On Sun, Mar 17, 2024 at 8:10 PM Ratheesh Kannoth rkannoth@marvell.com wrote:
On 2024-03-16 at 21:52:41, Jose Fernandez (josef@netflix.com) wrote:
This patch adds a selftest for the `bpf_task_get_cgroup` kfunc. The test focuses on the use case of obtaining the cgroup ID of the previous task in a `sched_switch` tracepoint.
The selftest involves creating a test cgroup, attaching a BPF program that utilizes the `bpf_task_get_cgroup` during a `sched_switch` tracepoint, and validating that the obtained cgroup ID for the previous task matches the expected cgroup ID.
Signed-off-by: Jose Fernandez josef@netflix.com Reviewed-by: Tycho Andersen tycho@tycho.pizza
V1 -> V2: Refactor test to work with a cgroup pointer instead of the ID
.../bpf/prog_tests/task_get_cgroup.c | 58 +++++++++++++++++++ .../bpf/progs/test_task_get_cgroup.c | 37 ++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/task_get_cgroup.c create mode 100644 tools/testing/selftests/bpf/progs/test_task_get_cgroup.c
diff --git a/tools/testing/selftests/bpf/prog_tests/task_get_cgroup.c b/tools/testing/selftests/bpf/prog_tests/task_get_cgroup.c new file mode 100644 index 000000000000..67ed65d0c461 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/task_get_cgroup.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright 2024 Netflix, Inc.
+#include <test_progs.h> +#include <cgroup_helpers.h> +#include "test_task_get_cgroup.skel.h" +#include <unistd.h>
+#define TEST_CGROUP "/test-task-get-cgroup/"
+void test_task_get_cgroup(void) +{
struct test_task_get_cgroup *skel;
int err, fd;
pid_t pid;
__u64 cgroup_id, expected_cgroup_id;
const struct timespec req = {
.tv_sec = 1,
.tv_nsec = 0,
};
Reverse Xmas tree.
NO. We don't do it in bpf trees.