]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: factor out get_func_* tests for fsession
authorMenglong Dong <menglong8.dong@gmail.com>
Tue, 24 Feb 2026 09:22:08 +0000 (17:22 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 3 Mar 2026 16:36:26 +0000 (08:36 -0800)
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>
tools/testing/selftests/bpf/prog_tests/get_func_args_test.c
tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c
tools/testing/selftests/bpf/progs/get_func_args_fsession_test.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/get_func_args_test.c
tools/testing/selftests/bpf/progs/get_func_ip_fsession_test.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/get_func_ip_test.c

index 96b27de055246b025f4a68e841b1a94054ddd93b..7bf8adc41e994ac0ef79dd10b03afa05b881c487 100644 (file)
@@ -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);
+}
index 7772a0f288d305222fa785a693a4e94f88e9c846..357fdedfea932741485686bcc3f30d8ef1d326cd 100644 (file)
@@ -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 (file)
index 0000000..bb597f2
--- /dev/null
@@ -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;
+}
index 075a1180ec268a24feceaf513972728e8975d8e6..1bf47f64d0967a3543739841201b58b14b4036a7 100644 (file)
@@ -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 (file)
index 0000000..bbeea0d
--- /dev/null
@@ -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;
+}
index 45eaa54d1ac78a0e3f5b1a9f2e1b7d2dbc519e1d..2011cacdeb183c2cdde678970779a44502f40a67 100644 (file)
@@ -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