cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: cgroup: Make test_pids backwards compatible
@ 2025-08-27 15:53 Michal Koutný
  2025-08-27 16:09 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Michal Koutný @ 2025-08-27 15:53 UTC (permalink / raw)
  To: Michal Koutný, Tejun Heo, cgroups, linux-kselftest,
	linux-kernel
  Cc: Sebastian Chlad, Johannes Weiner, Shuah Khan

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>
---
 tools/testing/selftests/cgroup/lib/cgroup_util.c     | 12 ++++++++++++
 .../selftests/cgroup/lib/include/cgroup_util.h       |  1 +
 tools/testing/selftests/cgroup/test_pids.c           |  3 +++
 3 files changed, 16 insertions(+)

diff --git a/tools/testing/selftests/cgroup/lib/cgroup_util.c b/tools/testing/selftests/cgroup/lib/cgroup_util.c
index 0e89fcff4d05d..44c52f620fda1 100644
--- a/tools/testing/selftests/cgroup/lib/cgroup_util.c
+++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c
@@ -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];
diff --git a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
index c69cab66254b4..9dc90a1b386d7 100644
--- a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
+++ b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
@@ -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);
diff --git a/tools/testing/selftests/cgroup/test_pids.c b/tools/testing/selftests/cgroup/test_pids.c
index 9ecb83c6cc5cb..d8a1d1cd50072 100644
--- a/tools/testing/selftests/cgroup/test_pids.c
+++ b/tools/testing/selftests/cgroup/test_pids.c
@@ -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)

base-commit: 04a4d6c24eef8a1fc89d8b6129ac00ca2f638aff
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests: cgroup: Make test_pids backwards compatible
  2025-08-27 15:53 [PATCH] selftests: cgroup: Make test_pids backwards compatible Michal Koutný
@ 2025-08-27 16:09 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2025-08-27 16:09 UTC (permalink / raw)
  To: Michal Koutný
  Cc: cgroups, linux-kselftest, linux-kernel, Sebastian Chlad,
	Johannes Weiner, Shuah Khan

On Wed, Aug 27, 2025 at 05:53:00PM +0200, Michal Koutný wrote:
> 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>

Applied to cgroup/for-6.18.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-27 16:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 15:53 [PATCH] selftests: cgroup: Make test_pids backwards compatible Michal Koutný
2025-08-27 16:09 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).