summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorMenglong Dong <menglong8.dong@gmail.com>2026-02-24 12:22:08 +0300
committerAlexei Starovoitov <ast@kernel.org>2026-03-03 19:36:26 +0300
commitc1eee8d1e84fd199571b09a0b66d3da6a1d160a9 (patch)
treef5960a4a18c2ded0e5e94edefb8c077c13a6fcb2 /tools/testing
parent63d2b7d101267767f2a87921539b2cbbf9cc48b0 (diff)
downloadlinux-c1eee8d1e84fd199571b09a0b66d3da6a1d160a9.tar.xz
selftests/bpf: factor out get_func_* tests for fsession
The fsession is already supported by x86_64, arm64, riscv and s390, so we don't need to disable it in the compile time according to the architecture. Factor out the testings for it. Therefore, the testing can be disabled for the architecture that doesn't support it manually. Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> Link: https://lore.kernel.org/r/20260224092208.1395085-4-dongml2@chinatelecom.cn Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/get_func_args_test.c25
-rw-r--r--tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c28
-rw-r--r--tools/testing/selftests/bpf/progs/get_func_args_fsession_test.c37
-rw-r--r--tools/testing/selftests/bpf/progs/get_func_args_test.c38
-rw-r--r--tools/testing/selftests/bpf/progs/get_func_ip_fsession_test.c21
-rw-r--r--tools/testing/selftests/bpf/progs/get_func_ip_test.c23
6 files changed, 108 insertions, 64 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/get_func_args_test.c b/tools/testing/selftests/bpf/prog_tests/get_func_args_test.c
index 96b27de05524..7bf8adc41e99 100644
--- a/tools/testing/selftests/bpf/prog_tests/get_func_args_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/get_func_args_test.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "get_func_args_test.skel.h"
+#include "get_func_args_fsession_test.skel.h"
void test_get_func_args_test(void)
{
@@ -41,8 +42,30 @@ void test_get_func_args_test(void)
ASSERT_EQ(skel->bss->test4_result, 1, "test4_result");
ASSERT_EQ(skel->bss->test5_result, 1, "test5_result");
ASSERT_EQ(skel->bss->test6_result, 1, "test6_result");
- ASSERT_EQ(skel->bss->test7_result, 1, "test7_result");
cleanup:
get_func_args_test__destroy(skel);
}
+
+void test_get_func_args_fsession_test(void)
+{
+ struct get_func_args_fsession_test *skel = NULL;
+ int err;
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+
+ skel = get_func_args_fsession_test__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "get_func_args_fsession_test__open_and_load"))
+ return;
+
+ err = get_func_args_fsession_test__attach(skel);
+ if (!ASSERT_OK(err, "get_func_args_fsession_test__attach"))
+ goto cleanup;
+
+ err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.test1), &topts);
+ ASSERT_OK(err, "test_run");
+ ASSERT_EQ(topts.retval, 0, "test_run");
+
+ ASSERT_EQ(skel->bss->test1_result, 1, "test1_result");
+cleanup:
+ get_func_args_fsession_test__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c b/tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c
index 7772a0f288d3..357fdedfea93 100644
--- a/tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c
@@ -2,6 +2,7 @@
#include <test_progs.h>
#include "get_func_ip_test.skel.h"
#include "get_func_ip_uprobe_test.skel.h"
+#include "get_func_ip_fsession_test.skel.h"
static noinline void uprobe_trigger(void)
{
@@ -46,8 +47,6 @@ static void test_function_entry(void)
ASSERT_EQ(skel->bss->test5_result, 1, "test5_result");
ASSERT_EQ(skel->bss->test7_result, 1, "test7_result");
ASSERT_EQ(skel->bss->test8_result, 1, "test8_result");
- ASSERT_EQ(skel->bss->test9_entry_result, 1, "test9_entry_result");
- ASSERT_EQ(skel->bss->test9_exit_result, 1, "test9_exit_result");
cleanup:
get_func_ip_test__destroy(skel);
@@ -139,3 +138,28 @@ void test_get_func_ip_test(void)
test_function_entry();
test_function_body();
}
+
+void test_get_func_ip_fsession_test(void)
+{
+ struct get_func_ip_fsession_test *skel = NULL;
+ int err;
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+
+ skel = get_func_ip_fsession_test__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "get_func_ip_fsession_test__open_and_load"))
+ return;
+
+ err = get_func_ip_fsession_test__attach(skel);
+ if (!ASSERT_OK(err, "get_func_ip_fsession_test__attach"))
+ goto cleanup;
+
+ err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.test1), &topts);
+ ASSERT_OK(err, "test_run");
+ ASSERT_EQ(topts.retval, 0, "test_run");
+
+ ASSERT_EQ(skel->bss->test1_entry_result, 1, "test1_entry_result");
+ ASSERT_EQ(skel->bss->test1_exit_result, 1, "test1_exit_result");
+
+cleanup:
+ get_func_ip_fsession_test__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/get_func_args_fsession_test.c b/tools/testing/selftests/bpf/progs/get_func_args_fsession_test.c
new file mode 100644
index 000000000000..bb597f24b659
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/get_func_args_fsession_test.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include <errno.h>
+
+char _license[] SEC("license") = "GPL";
+
+__u64 test1_result = 0;
+
+SEC("fsession/bpf_fentry_test1")
+int BPF_PROG(test1)
+{
+ __u64 cnt = bpf_get_func_arg_cnt(ctx);
+ __u64 a = 0, z = 0, ret = 0;
+ __s64 err;
+
+ test1_result = cnt == 1;
+
+ /* valid arguments */
+ err = bpf_get_func_arg(ctx, 0, &a);
+ test1_result &= err == 0 && ((int) a == 1);
+
+ /* not valid argument */
+ err = bpf_get_func_arg(ctx, 1, &z);
+ test1_result &= err == -EINVAL;
+
+ if (bpf_session_is_return(ctx)) {
+ err = bpf_get_func_ret(ctx, &ret);
+ test1_result &= err == 0 && ret == 2;
+ } else {
+ err = bpf_get_func_ret(ctx, &ret);
+ test1_result &= err == 0 && ret == 0;
+ }
+
+ return 0;
+}
diff --git a/tools/testing/selftests/bpf/progs/get_func_args_test.c b/tools/testing/selftests/bpf/progs/get_func_args_test.c
index 075a1180ec26..1bf47f64d096 100644
--- a/tools/testing/selftests/bpf/progs/get_func_args_test.c
+++ b/tools/testing/selftests/bpf/progs/get_func_args_test.c
@@ -165,41 +165,3 @@ int BPF_PROG(tp_test2)
return 0;
}
-
-__u64 test7_result = 0;
-#if defined(bpf_target_x86) || defined(bpf_target_arm64) || defined(bpf_target_riscv)
-SEC("fsession/bpf_fentry_test1")
-int BPF_PROG(test7)
-{
- __u64 cnt = bpf_get_func_arg_cnt(ctx);
- __u64 a = 0, z = 0, ret = 0;
- __s64 err;
-
- test7_result = cnt == 1;
-
- /* valid arguments */
- err = bpf_get_func_arg(ctx, 0, &a);
- test7_result &= err == 0 && ((int) a == 1);
-
- /* not valid argument */
- err = bpf_get_func_arg(ctx, 1, &z);
- test7_result &= err == -EINVAL;
-
- if (bpf_session_is_return(ctx)) {
- err = bpf_get_func_ret(ctx, &ret);
- test7_result &= err == 0 && ret == 2;
- } else {
- err = bpf_get_func_ret(ctx, &ret);
- test7_result &= err == 0 && ret == 0;
- }
-
- return 0;
-}
-#else
-SEC("fentry/bpf_fentry_test1")
-int BPF_PROG(test7)
-{
- test7_result = 1;
- return 0;
-}
-#endif
diff --git a/tools/testing/selftests/bpf/progs/get_func_ip_fsession_test.c b/tools/testing/selftests/bpf/progs/get_func_ip_fsession_test.c
new file mode 100644
index 000000000000..bbeea0d512e3
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/get_func_ip_fsession_test.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+__u64 test1_entry_result = 0;
+__u64 test1_exit_result = 0;
+
+SEC("fsession/bpf_fentry_test1")
+int BPF_PROG(test1, int a)
+{
+ __u64 addr = bpf_get_func_ip(ctx);
+
+ if (bpf_session_is_return(ctx))
+ test1_exit_result = (const void *) addr == &bpf_fentry_test1;
+ else
+ test1_entry_result = (const void *) addr == &bpf_fentry_test1;
+ return 0;
+}
diff --git a/tools/testing/selftests/bpf/progs/get_func_ip_test.c b/tools/testing/selftests/bpf/progs/get_func_ip_test.c
index 45eaa54d1ac7..2011cacdeb18 100644
--- a/tools/testing/selftests/bpf/progs/get_func_ip_test.c
+++ b/tools/testing/selftests/bpf/progs/get_func_ip_test.c
@@ -103,26 +103,3 @@ int BPF_URETPROBE(test8, int ret)
test8_result = (const void *) addr == (const void *) uprobe_trigger;
return 0;
}
-
-__u64 test9_entry_result = 0;
-__u64 test9_exit_result = 0;
-#if defined(bpf_target_x86) || defined(bpf_target_arm64) || defined(bpf_target_riscv)
-SEC("fsession/bpf_fentry_test1")
-int BPF_PROG(test9, int a)
-{
- __u64 addr = bpf_get_func_ip(ctx);
-
- if (bpf_session_is_return(ctx))
- test9_exit_result = (const void *) addr == &bpf_fentry_test1;
- else
- test9_entry_result = (const void *) addr == &bpf_fentry_test1;
- return 0;
-}
-#else
-SEC("fentry/bpf_fentry_test1")
-int BPF_PROG(test9, int a)
-{
- test9_entry_result = test9_exit_result = 1;
- return 0;
-}
-#endif