Re: [PATCH perf/core 14/22] selftests/bpf: Add uprobe/usdt syscall tests

Andrii Nakryiko
2025-04-23T17:41:11Z

On Mon, Apr 21, 2025 at 2:47 PM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Adding tests for optimized uprobe/usdt probes.
>
> Checking that we get expected trampoline and attached bpf programs
> get executed properly.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> .../selftests/bpf/prog_tests/uprobe_syscall.c | 278 +++++++++++++++++-
> .../bpf/progs/uprobe_syscall_executed.c | 37 +++
> 2 files changed, 314 insertions(+), 1 deletion(-)
>

[...]

> static void __test_uprobe_syscall(void)
> diff --git a/tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c b/tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c
> index 2e1b689ed4fb..7bb4338c3ee2 100644
> --- a/tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c
> +++ b/tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c
> @@ -1,6 +1,8 @@
> // SPDX-License-Identifier: GPL-2.0
> #include "vmlinux.h"
> #include <bpf/bpf_helpers.h>
> +#include <bpf/bpf_tracing.h>
> +#include <bpf/usdt.bpf.h>
> #include <string.h>
>
> struct pt_regs regs;
> @@ -9,9 +11,44 @@ char _license[] SEC("license") = "GPL";
>
> int executed = 0;
>
> +SEC("uprobe")
> +int BPF_UPROBE(test_uprobe)
> +{

I'd add a PID filter to all of these to guard against potential
unrelated triggerings if in the future there is some parallel test
that attaches to all uprobes or something like that. Better safe than
sorry.

> + executed++;
> + return 0;
> +}
> +
> +SEC("uretprobe")
> +int BPF_URETPROBE(test_uretprobe)
> +{
> + executed++;
> + return 0;
> +}
> +
> +SEC("uprobe.multi")
> +int test_uprobe_multi(struct pt_regs *ctx)
> +{
> + executed++;
> + return 0;
> +}
> +
> SEC("uretprobe.multi")
> int test_uretprobe_multi(struct pt_regs *ctx)
> {
> executed++;
> return 0;
> }
> +
> +SEC("uprobe.session")
> +int test_uprobe_session(struct pt_regs *ctx)
> +{
> + executed++;
> + return 0;
> +}
> +
> +SEC("usdt")
> +int test_usdt(struct pt_regs *ctx)
> +{
> + executed++;
> + return 0;
> +}
> --
> 2.49.0
>