diff options
author | David Vernet <void@manifault.com> | 2022-11-21 23:54:58 -0600 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-11-22 14:45:41 -0800 |
commit | 227a89cf504188759fd3d8933a3a06fc60cca7f2 (patch) | |
tree | 7fec770a835ec1159b9e39d4097b62a5826330b9 /tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c | |
parent | 5ca7867078296cfa9c100f9a3b2d24be1e139825 (diff) | |
download | linux-stable-227a89cf504188759fd3d8933a3a06fc60cca7f2.tar.gz linux-stable-227a89cf504188759fd3d8933a3a06fc60cca7f2.tar.bz2 linux-stable-227a89cf504188759fd3d8933a3a06fc60cca7f2.zip |
selftests/bpf: Add selftests for bpf_cgroup_ancestor() kfunc
bpf_cgroup_ancestor() allows BPF programs to access the ancestor of a
struct cgroup *. This patch adds selftests that validate its expected
behavior.
Signed-off-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/r/20221122055458.173143-5-void@manifault.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c b/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c index 9f4569f7598b..0c23ea32df9f 100644 --- a/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c +++ b/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c @@ -123,3 +123,48 @@ int BPF_PROG(test_cgrp_get_release, struct cgroup *cgrp, const char *path) return 0; } + +SEC("tp_btf/cgroup_mkdir") +int BPF_PROG(test_cgrp_get_ancestors, struct cgroup *cgrp, const char *path) +{ + struct cgroup *self, *ancestor1, *invalid; + + if (!is_test_kfunc_task()) + return 0; + + self = bpf_cgroup_ancestor(cgrp, cgrp->level); + if (!self) { + err = 1; + return 0; + } + + if (self->self.id != cgrp->self.id) { + bpf_cgroup_release(self); + err = 2; + return 0; + } + bpf_cgroup_release(self); + + ancestor1 = bpf_cgroup_ancestor(cgrp, cgrp->level - 1); + if (!ancestor1) { + err = 3; + return 0; + } + bpf_cgroup_release(ancestor1); + + invalid = bpf_cgroup_ancestor(cgrp, 10000); + if (invalid) { + bpf_cgroup_release(invalid); + err = 4; + return 0; + } + + invalid = bpf_cgroup_ancestor(cgrp, -1); + if (invalid) { + bpf_cgroup_release(invalid); + err = 5; + return 0; + } + + return 0; +} |