]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: test bpf_get_func_arg() for tp_btf
authorMenglong Dong <menglong8.dong@gmail.com>
Wed, 21 Jan 2026 04:43:48 +0000 (12:43 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 21 Jan 2026 17:31:35 +0000 (09:31 -0800)
Test bpf_get_func_arg() and bpf_get_func_arg_cnt() for tp_btf. The code
is most copied from test1 and test2.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20260121044348.113201-3-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/progs/get_func_args_test.c
tools/testing/selftests/bpf/test_kmods/bpf_testmod-events.h
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c

index 64a9c95d4acf6223b49ddc6f1a5d184060ecbbb5..fadee95d3ae8494a823ab95f8c6935137457457f 100644 (file)
@@ -33,11 +33,14 @@ void test_get_func_args_test(void)
 
        ASSERT_EQ(topts.retval >> 16, 1, "test_run");
        ASSERT_EQ(topts.retval & 0xffff, 1234 + 29, "test_run");
+       ASSERT_OK(trigger_module_test_read(1), "trigger_read");
 
        ASSERT_EQ(skel->bss->test1_result, 1, "test1_result");
        ASSERT_EQ(skel->bss->test2_result, 1, "test2_result");
        ASSERT_EQ(skel->bss->test3_result, 1, "test3_result");
        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");
 
 cleanup:
        get_func_args_test__destroy(skel);
index e0f34a55e697f9134d8bc2c2c36826d57492a071..5b7233afef0536ba21788531ff02acea64f32b4a 100644 (file)
@@ -121,3 +121,47 @@ int BPF_PROG(fexit_test, int _a, int *_b, int _ret)
        test4_result &= err == 0 && ret == 1234;
        return 0;
 }
+
+__u64 test5_result = 0;
+SEC("tp_btf/bpf_testmod_fentry_test1_tp")
+int BPF_PROG(tp_test1)
+{
+       __u64 cnt = bpf_get_func_arg_cnt(ctx);
+       __u64 a = 0, z = 0;
+       __s64 err;
+
+       test5_result = cnt == 1;
+
+       err = bpf_get_func_arg(ctx, 0, &a);
+       test5_result &= err == 0 && ((int) a == 1);
+
+       /* not valid argument */
+       err = bpf_get_func_arg(ctx, 1, &z);
+       test5_result &= err == -EINVAL;
+
+       return 0;
+}
+
+__u64 test6_result = 0;
+SEC("tp_btf/bpf_testmod_fentry_test2_tp")
+int BPF_PROG(tp_test2)
+{
+       __u64 cnt = bpf_get_func_arg_cnt(ctx);
+       __u64 a = 0, b = 0, z = 0;
+       __s64 err;
+
+       test6_result = cnt == 2;
+
+       /* valid arguments */
+       err = bpf_get_func_arg(ctx, 0, &a);
+       test6_result &= err == 0 && (int) a == 2;
+
+       err = bpf_get_func_arg(ctx, 1, &b);
+       test6_result &= err == 0 && b == 3;
+
+       /* not valid argument */
+       err = bpf_get_func_arg(ctx, 2, &z);
+       test6_result &= err == -EINVAL;
+
+       return 0;
+}
index aeef86b3da747a5011d76ee52589ea5231f23239..45a5e41f3a920c244bcd97be16325d5916e99ffb 100644 (file)
@@ -63,6 +63,16 @@ BPF_TESTMOD_DECLARE_TRACE(bpf_testmod_test_writable_bare,
        sizeof(struct bpf_testmod_test_writable_ctx)
 );
 
+DECLARE_TRACE(bpf_testmod_fentry_test1,
+       TP_PROTO(int a),
+       TP_ARGS(a)
+);
+
+DECLARE_TRACE(bpf_testmod_fentry_test2,
+       TP_PROTO(int a, u64 b),
+       TP_ARGS(a, b)
+);
+
 #endif /* _BPF_TESTMOD_EVENTS_H */
 
 #undef TRACE_INCLUDE_PATH
index d425034b72d397fc80f0d56ada20afa66df192b7..77a81fa8ec6a3165cfec927de8ed062fa3118ea6 100644 (file)
@@ -412,11 +412,15 @@ __weak noinline struct file *bpf_testmod_return_ptr(int arg)
 
 noinline int bpf_testmod_fentry_test1(int a)
 {
+       trace_bpf_testmod_fentry_test1_tp(a);
+
        return a + 1;
 }
 
 noinline int bpf_testmod_fentry_test2(int a, u64 b)
 {
+       trace_bpf_testmod_fentry_test2_tp(a, b);
+
        return a + b;
 }