From: Jiri Olsa <olsajiri@gmail.com>
To: Menglong Dong <menglong8.dong@gmail.com>
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org,
sdf@fomichev.me, haoluo@google.com, mattbobrowski@google.com,
rostedt@goodmis.org, mhiramat@kernel.org,
mathieu.desnoyers@efficios.com, leon.hwang@linux.dev,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next 5/5] selftests/bpf: add testcases for tracing session
Date: Mon, 20 Oct 2025 10:19:47 +0200 [thread overview]
Message-ID: <aPXwo0puQI3t0CXC@krava> (raw)
In-Reply-To: <20251018142124.783206-6-dongml2@chinatelecom.cn>
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
> + if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
> + return;
goto cleanup
> +
> + /* 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
> + if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
> + return;
goto cleanup
> +
> + /* 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
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
next prev parent reply other threads:[~2025-10-20 8:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-18 14:21 [PATCH RFC bpf-next 0/5] bpf: tracing session supporting Menglong Dong
2025-10-18 14:21 ` [PATCH RFC bpf-next 1/5] bpf: add tracing session support Menglong Dong
2025-10-18 14:21 ` [PATCH RFC bpf-next 2/5] bpf: add kfunc bpf_tracing_is_exit for TRACE_SESSION Menglong Dong
2025-10-20 8:19 ` Jiri Olsa
2025-10-20 8:30 ` Menglong Dong
2025-10-18 14:21 ` [PATCH RFC bpf-next 3/5] bpf,x86: add tracing session supporting for x86_64 Menglong Dong
2025-10-19 2:03 ` Menglong Dong
2025-10-20 8:19 ` Jiri Olsa
2025-10-20 8:31 ` Menglong Dong
2025-10-21 18:16 ` Alexei Starovoitov
2025-10-22 1:05 ` Menglong Dong
2025-10-18 14:21 ` [PATCH RFC bpf-next 4/5] libbpf: add support for tracing session Menglong Dong
2025-10-18 14:21 ` [PATCH RFC bpf-next 5/5] selftests/bpf: add testcases " Menglong Dong
2025-10-20 8:19 ` Jiri Olsa [this message]
2025-10-20 8:40 ` Menglong Dong
2025-10-20 8:18 ` [PATCH RFC bpf-next 0/5] bpf: tracing session supporting Jiri Olsa
2025-10-20 8:55 ` Menglong Dong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aPXwo0puQI3t0CXC@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kpsingh@kernel.org \
--cc=leon.hwang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mattbobrowski@google.com \
--cc=menglong8.dong@gmail.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox