aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/cgroup_mprog.c
diff options
context:
space:
mode:
authorYonghong Song <yonghong.song@linux.dev>2025-06-06 09:31:56 -0700
committerAndrii Nakryiko <andrii@kernel.org>2025-06-09 16:28:31 -0700
commite422d5f118e4da5d15b57c5721ee68ae39b512ec (patch)
treeee4f3bbbef0f5e95caa73394b6e6217b261234df /tools/testing/selftests/bpf/progs/cgroup_mprog.c
parentselftests/bpf: Move some tc_helpers.h functions to test_progs.h (diff)
downloadlinux-e422d5f118e4da5d15b57c5721ee68ae39b512ec.tar.gz
linux-e422d5f118e4da5d15b57c5721ee68ae39b512ec.zip
selftests/bpf: Add two selftests for mprog API based cgroup progs
Two tests are added: - cgroup_mprog_opts, which mimics tc_opts.c ([1]). Both prog and link attach are tested. Some negative tests are also included. - cgroup_mprog_ordering, which actually runs the program with some mprog API flags. [1] https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/prog_tests/tc_opts.c Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20250606163156.2429955-1-yonghong.song@linux.dev
Diffstat (limited to 'tools/testing/selftests/bpf/progs/cgroup_mprog.c')
-rw-r--r--tools/testing/selftests/bpf/progs/cgroup_mprog.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/cgroup_mprog.c b/tools/testing/selftests/bpf/progs/cgroup_mprog.c
new file mode 100644
index 000000000000..6a0ea02c4de2
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/cgroup_mprog.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+
+char _license[] SEC("license") = "GPL";
+
+SEC("cgroup/getsockopt")
+int getsockopt_1(struct bpf_sockopt *ctx)
+{
+ return 1;
+}
+
+SEC("cgroup/getsockopt")
+int getsockopt_2(struct bpf_sockopt *ctx)
+{
+ return 1;
+}
+
+SEC("cgroup/getsockopt")
+int getsockopt_3(struct bpf_sockopt *ctx)
+{
+ return 1;
+}
+
+SEC("cgroup/getsockopt")
+int getsockopt_4(struct bpf_sockopt *ctx)
+{
+ return 1;
+}