selftests: cgroup: Make test_pids backwards compatible
The predicates in test expect event counting from73e75e6fc3("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:9f34c56602("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>
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user