]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests: cgroup: Make test_pids backwards compatible
authorMichal Koutný <mkoutny@suse.com>
Wed, 27 Aug 2025 15:53:00 +0000 (17:53 +0200)
committerTejun Heo <tj@kernel.org>
Wed, 27 Aug 2025 15:59:52 +0000 (05:59 -1000)
The predicates in test expect event counting from 73e75e6fc352b
("cgroup/pids: Separate semantics of pids.events related to pids.max")
and the test would fail on older kernels. We want to have one version of
tests for all, so detect the feature and skip the test on old kernels.
(The test could even switch to check v1 semantics based on the flag but
keep it simple for now.)

Fixes: 9f34c566027b6 ("selftests: cgroup: Add basic tests for pids controller")
Signed-off-by: Michal Koutný <mkoutny@suse.com>
Tested-by: Sebastian Chlad <sebastian.chlad@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/testing/selftests/cgroup/lib/cgroup_util.c
tools/testing/selftests/cgroup/lib/include/cgroup_util.h
tools/testing/selftests/cgroup/test_pids.c

index 0e89fcff4d05d3550eef716aa735ca5b31cd7d79..44c52f620fda17b50762a245ff198946d09bdb24 100644 (file)
@@ -522,6 +522,18 @@ int proc_mount_contains(const char *option)
        return strstr(buf, option) != NULL;
 }
 
+int cgroup_feature(const char *feature)
+{
+       char buf[PAGE_SIZE];
+       ssize_t read;
+
+       read = read_text("/sys/kernel/cgroup/features", buf, sizeof(buf));
+       if (read < 0)
+               return read;
+
+       return strstr(buf, feature) != NULL;
+}
+
 ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size)
 {
        char path[PATH_MAX];
index c69cab66254b419e2dc88dbfc51296519d7076a9..9dc90a1b386d7771cb43035630195bd9ffd56ef8 100644 (file)
@@ -60,6 +60,7 @@ extern int cg_run_nowait(const char *cgroup,
 extern int cg_wait_for_proc_count(const char *cgroup, int count);
 extern int cg_killall(const char *cgroup);
 int proc_mount_contains(const char *option);
+int cgroup_feature(const char *feature);
 extern ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size);
 extern int proc_read_strstr(int pid, bool thread, const char *item, const char *needle);
 extern pid_t clone_into_cgroup(int cgroup_fd);
index 9ecb83c6cc5cbf4d2b26d02fa921700d5c1ada23..d8a1d1cd500727421e0d907614a6e996e961d23f 100644 (file)
@@ -77,6 +77,9 @@ static int test_pids_events(const char *root)
        char *cg_parent = NULL, *cg_child = NULL;
        int pid;
 
+       if (cgroup_feature("pids_localevents") <= 0)
+               return KSFT_SKIP;
+
        cg_parent = cg_name(root, "pids_parent");
        cg_child = cg_name(cg_parent, "pids_child");
        if (!cg_parent || !cg_child)