Re: [PATCH v2] selftests/cgroup: add user_usec sanity check in test_cpucg_nice
Tao Cui <[email protected]> Thu, 30 Jul 2026 22:55:41 +0800
| Newsgroups | org.kernel.vger.cgroups,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest |
|---|---|
| Message-ID | <[email protected]> |
在 2026/7/30 21:07, Shaojie Sun 写道: > In test_cpucg_nice, after the child process exits, user_usec is > read from cpu.stat but the value is not checked. Add a sanity check > to ensure user_usec > 0, analogous to test_cpucg_stats(), so that > the test fails early if CPU usage wasn't properly accounted. > > Signed-off-by: Shaojie Sun <[email protected]> > --- > v2: Instead of simply removing the unused user_usec read, add a sanity > check (if user_usec <= 0, goto cleanup) analogous to test_cpucg_stats(), > as suggested by Michal. > > tools/testing/selftests/cgroup/test_cpu.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c > index 7a40d76b9548..5a44705ed3fd 100644 > --- a/tools/testing/selftests/cgroup/test_cpu.c > +++ b/tools/testing/selftests/cgroup/test_cpu.c > @@ -291,6 +291,8 @@ static int test_cpucg_nice(const char *root) > > user_usec = cg_read_key_long(cpucg, "cpu.stat", "user_usec"); > nice_usec = cg_read_key_long(cpucg, "cpu.stat", "nice_usec"); > + if (user_usec <= 0) > + goto cleanup; > if (!values_close_report(nice_usec, expected_nice_usec, 1)) > goto cleanup; > Acked-by: Tao Cui <[email protected]>