On 2/12/26 12:23 AM, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> When cgroup.memory=nokmem is set in kernel command line, kmem
> accounting is disabled and the test_kmem subtest will fail.
>
> Add a check to skip this test when the parameter is present.
>
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---
> .../bpf/prog_tests/cgroup_iter_memcg.c | 28 +++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> index 13b299512429..203e6b091a21 100644
> --- a/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
> @@ -134,11 +134,39 @@ static void test_shmem(struct bpf_link *link, struct memcg_query *memcg_query)
> shm_unlink("/tmp_shmem");
> }
>
> +static bool cmdline_has(const char *arg)
> +{
> + char cmdline[4096];
> + int fd;
> + ssize_t len;
> + bool ret = false;
> +
> + fd = open("/proc/cmdline", O_RDONLY);
> + if (fd < 0)
> + return false;
> +
> + len = read(fd, cmdline, sizeof(cmdline) - 1);
> + close(fd);
> + if (len < 0)
> + return false;
> +
> + cmdline[len] = '\0';
> + if (strstr(cmdline, arg))
> + ret = true;
> +
> + return ret;
> +}
> +
> #define NR_PIPES 64
> static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query)
> {
> int fds[NR_PIPES][2], i;
>
> + if (cmdline_has("cgroup.memory=nokmem")) {
> + test__skip();
> + return;
> + }
Instead of just skipping what if we proceed and then confirm we get a
zero value after the allocations?