mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Down <chris@chrisdown.name>
To: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com,
	shakeel.butt@linux.dev
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 2/2] selftests/cgroup: Test parsing of long fractions in cpu.uclamp.min
Date: Wed, 25 Nov 2026 21:41:18 -0800	[thread overview]
Message-ID: <dbdeffef59486589a893e2724546724b58443757.1795671629.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1795671629.git.chris@chrisdown.name>

Add a test to test_cpu that writes values to cpu.uclamp.min and reads
them back, checking that they are rounded to two decimal places and
that malformed or out of range values are rejected.

Signed-off-by: Chris Down <chris@chrisdown.name>
---
 tools/testing/selftests/cgroup/config     |  4 ++
 tools/testing/selftests/cgroup/test_cpu.c | 71 +++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/tools/testing/selftests/cgroup/config b/tools/testing/selftests/cgroup/config
index 39f979690dd3..c8b2c95a186e 100644
--- a/tools/testing/selftests/cgroup/config
+++ b/tools/testing/selftests/cgroup/config
@@ -2,5 +2,9 @@ CONFIG_CGROUPS=y
 CONFIG_CGROUP_CPUACCT=y
 CONFIG_CGROUP_FREEZER=y
 CONFIG_CGROUP_SCHED=y
+CONFIG_CPU_FREQ=y
+CONFIG_CPU_FREQ_GOV_SCHEDUTIL=y
 CONFIG_MEMCG=y
 CONFIG_PAGE_COUNTER=y
+CONFIG_UCLAMP_TASK=y
+CONFIG_UCLAMP_TASK_GROUP=y
diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
index 3456e3e988c6..369d4930c1f4 100644
--- a/tools/testing/selftests/cgroup/test_cpu.c
+++ b/tools/testing/selftests/cgroup/test_cpu.c
@@ -809,6 +809,76 @@ cleanup:
 	return ret;
 }
 
+static int test_cpucg_uclamp_parse(const char *root)
+{
+	static const struct {
+		char *input;
+		char *expected;	/* NULL if the write must fail */
+	} cases[] = {
+		{ "12.34", "12.34\n" },
+		{ "50", "50.00\n" },
+		{ "0.125", "0.13\n" },
+		{ "0.999", "1.00\n" },
+		{ "100.01", NULL },
+		{ "abc", NULL },
+		{ "0.5000000000000", "0.50\n" },
+		{ "0.123456789012", "0.12\n" },
+		{ "0.99999999999999999999", "1.00\n" },
+		{ "0.0000000000000000000000000000000000", "0.00\n" },
+	};
+	int ret = KSFT_FAIL;
+	char buf[64];
+	char *cpucg;
+	int i, err;
+
+	cpucg = cg_name(root, "cpucg_test");
+	if (!cpucg)
+		goto cleanup;
+
+	if (cg_create(cpucg))
+		goto cleanup;
+
+	if (cg_read(cpucg, "cpu.uclamp.min", buf, sizeof(buf))) {
+		ret = KSFT_SKIP;
+		goto cleanup;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(cases); i++) {
+		err = cg_write(cpucg, "cpu.uclamp.min", cases[i].input);
+
+		if (!cases[i].expected) {
+			if (!err) {
+				ksft_print_msg("%s was accepted\n", cases[i].input);
+				goto cleanup;
+			}
+			continue;
+		}
+
+		if (err) {
+			ksft_print_msg("%s was rejected: %s\n", cases[i].input,
+				       strerror(-err));
+			goto cleanup;
+		}
+
+		if (cg_read(cpucg, "cpu.uclamp.min", buf, sizeof(buf)))
+			goto cleanup;
+
+		if (strcmp(buf, cases[i].expected)) {
+			ksft_print_msg("%s reads back as %s", cases[i].input,
+				       buf);
+			goto cleanup;
+		}
+	}
+
+	ret = KSFT_PASS;
+
+cleanup:
+	cg_destroy(cpucg);
+	free(cpucg);
+
+	return ret;
+}
+
 #define T(x) { x, #x }
 struct cpucg_test {
 	int (*fn)(const char *root);
@@ -823,6 +893,7 @@ struct cpucg_test {
 	T(test_cpucg_nested_weight_underprovisioned),
 	T(test_cpucg_max),
 	T(test_cpucg_max_nested),
+	T(test_cpucg_uclamp_parse),
 };
 #undef T
 
-- 
2.56.1


  parent reply	other threads:[~2026-11-26  5:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  5:41 [PATCH v3 0/2] cgroup: Fix cgroup_mutex deadlock through cgroup_parse_float() oops Chris Down
2026-11-26  5:41 ` [PATCH v3 1/2] cgroup: Fix divide error on long fractions in cgroup_parse_float() Chris Down
2026-11-26  5:41 ` Chris Down [this message]
2026-11-26 11:32 ` [PATCH v3 0/2] cgroup: Fix cgroup_mutex deadlock through cgroup_parse_float() oops Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dbdeffef59486589a893e2724546724b58443757.1795671629.git.chris@chrisdown.name \
    --to=chris@chrisdown.name \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®