[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2243183.irdbgypaU6@7950hx>
Date: Mon, 20 Oct 2025 16:40:17 +0800
From: Menglong Dong <menglong.dong@...ux.dev>
To: Menglong Dong <menglong8.dong@...il.com>, Jiri Olsa <olsajiri@...il.com>
Cc: ast@...nel.org, daniel@...earbox.net, john.fastabend@...il.com,
andrii@...nel.org, martin.lau@...ux.dev, eddyz87@...il.com, song@...nel.org,
yonghong.song@...ux.dev, kpsingh@...nel.org, sdf@...ichev.me,
haoluo@...gle.com, mattbobrowski@...gle.com, rostedt@...dmis.org,
mhiramat@...nel.org, mathieu.desnoyers@...icios.com, leon.hwang@...ux.dev,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org
Subject:
Re: [PATCH RFC bpf-next 5/5] selftests/bpf: add testcases for tracing session
On 2025/10/20 16:19, Jiri Olsa wrote:
> On Sat, Oct 18, 2025 at 10:21:24PM +0800, Menglong Dong wrote:
>
> SNIP
>
> > +static void test_fsession_reattach(void)
> > +{
> > + struct fsession_test *skel = NULL;
> > + int err, prog_fd;
> > + LIBBPF_OPTS(bpf_test_run_opts, topts);
> > +
> > + skel = fsession_test__open_and_load();
> > + if (!ASSERT_OK_PTR(skel, "fsession_test__open_and_load"))
> > + goto cleanup;
> > +
> > + /* First attach */
> > + err = fsession_test__attach(skel);
> > + if (!ASSERT_OK(err, "fsession_first_attach"))
> > + goto cleanup;
> > +
> > + /* Trigger test function calls */
> > + prog_fd = bpf_program__fd(skel->progs.test1);
> > + err = bpf_prog_test_run_opts(prog_fd, &topts);
> > + if (!ASSERT_OK(err, "test_run_opts err"))
> > + return;
>
> goto cleanup
ACK.
>
> > + if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
> > + return;
>
> goto cleanup
ACK.
>
> > +
> > + /* Verify first call */
> > + ASSERT_EQ(skel->bss->test1_entry_called, 1, "test1_entry_first");
> > + ASSERT_EQ(skel->bss->test1_exit_called, 1, "test1_exit_first");
> > +
> > + /* Detach */
> > + fsession_test__detach(skel);
> > +
> > + /* Reset counters */
> > + memset(skel->bss, 0, sizeof(*skel->bss));
> > +
> > + /* Second attach */
> > + err = fsession_test__attach(skel);
> > + if (!ASSERT_OK(err, "fsession_second_attach"))
> > + goto cleanup;
> > +
> > + err = bpf_prog_test_run_opts(prog_fd, &topts);
> > + if (!ASSERT_OK(err, "test_run_opts err"))
> > + return;
>
> goto cleanup
ACK.
>
> > + if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
> > + return;
>
> goto cleanup
ACK.
>
> > +
> > + /* Verify second call */
> > + ASSERT_EQ(skel->bss->test1_entry_called, 1, "test1_entry_second");
> > + ASSERT_EQ(skel->bss->test1_exit_called, 1, "test1_exit_second");
> > +
> > +cleanup:
> > + fsession_test__destroy(skel);
> > +}
> > +
> > +void test_fsession_test(void)
> > +{
> > +#if !defined(__x86_64__)
> > + test__skip();
> > + return;
> > +#endif
> > + if (test__start_subtest("fsession_basic"))
> > + test_fsession_basic();
> > + if (test__start_subtest("fsession_reattach"))
> > + test_fsession_reattach();
> > +}
> > diff --git a/tools/testing/selftests/bpf/progs/fsession_test.c b/tools/testing/selftests/bpf/progs/fsession_test.c
> > new file mode 100644
> > index 000000000000..cce2b32f7c2c
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/progs/fsession_test.c
> > @@ -0,0 +1,178 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/* Copyright (c) 2025 ChinaTelecom */
> > +#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;
> > +__u64 test1_entry_called = 0;
> > +__u64 test1_exit_called = 0;
> > +
> > +SEC("fsession/bpf_fentry_test1")
> > +int BPF_PROG(test1, int a)
> > +{
>
> I guess we can access return argument directly but it makes sense only
> for exit session program, or we could use bpf_get_func_ret
Yeah, we can access the return value directly here or use
bpf_get_func_ret(). For fentry, it is also allow to access the return value.
It makes no sense to obtain the return value in the fentry, and
what it gets is just the previous fsession-fentry returned.
And it needs more effort in the verifier to forbid such operation.
The testcases is not complete, and I'll add more testcases in the
next version to cover more cases.
Thanks!
Menglong Dong
>
> jirka
>
>
> > + bool is_exit = bpf_tracing_is_exit(ctx);
> > +
> > + if (!is_exit) {
> > + /* This is entry */
> > + test1_entry_called = 1;
> > + test1_entry_result = a == 1;
> > + return 0; /* Return 0 to allow exit to be called */
> > + }
> > +
> > + /* This is exit */
> > + test1_exit_called = 1;
> > + test1_exit_result = a == 1;
> > + return 0;
> > +}
> > +
> > +__u64 test2_entry_result = 0;
> > +__u64 test2_exit_result = 0;
> > +__u64 test2_entry_called = 0;
> > +__u64 test2_exit_called = 0;
> > +
>
> SNIP
>
>
Powered by blists - more mailing lists