Skip to content

Commit 6a2d2f8

Browse files
olsajiriKernel Patches Daemon
authored andcommitted
selftests/bpf: Add stacktrace ips test for raw_tp
Adding test that verifies we get expected initial 2 entries from stacktrace for rawtp probe via ORC unwind. Signed-off-by: Jiri Olsa <[email protected]>
1 parent ada7496 commit 6a2d2f8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,58 @@ static void test_stacktrace_ips_kprobe_multi(bool retprobe)
8484
stacktrace_ips__destroy(skel);
8585
}
8686

87+
static void test_stacktrace_ips_raw_tp(void)
88+
{
89+
__u32 info_len = sizeof(struct bpf_prog_info);
90+
LIBBPF_OPTS(bpf_test_run_opts, topts);
91+
struct bpf_prog_info info = {};
92+
struct stacktrace_ips *skel;
93+
__u64 bpf_prog_ksym = 0;
94+
int err;
95+
96+
skel = stacktrace_ips__open_and_load();
97+
if (!ASSERT_OK_PTR(skel, "stacktrace_ips__open_and_load"))
98+
return;
99+
100+
if (!skel->kconfig->CONFIG_UNWINDER_ORC) {
101+
test__skip();
102+
goto cleanup;
103+
}
104+
105+
skel->links.rawtp_test = bpf_program__attach_raw_tracepoint(
106+
skel->progs.rawtp_test,
107+
"bpf_testmod_test_read");
108+
if (!ASSERT_OK_PTR(skel->links.rawtp_test, "bpf_program__attach_raw_tracepoint"))
109+
goto cleanup;
110+
111+
/* get bpf program address */
112+
info.jited_ksyms = ptr_to_u64(&bpf_prog_ksym);
113+
info.nr_jited_ksyms = 1;
114+
err = bpf_prog_get_info_by_fd(bpf_program__fd(skel->progs.rawtp_test),
115+
&info, &info_len);
116+
if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
117+
goto cleanup;
118+
119+
trigger_module_test_read(1);
120+
121+
load_kallsyms();
122+
123+
check_stacktrace_ips(bpf_map__fd(skel->maps.stackmap), skel->bss->stack_key, 2,
124+
bpf_prog_ksym,
125+
ksym_get_addr("bpf_trace_run2"));
126+
127+
cleanup:
128+
stacktrace_ips__destroy(skel);
129+
}
130+
87131
static void __test_stacktrace_ips(void)
88132
{
89133
if (test__start_subtest("kprobe_multi"))
90134
test_stacktrace_ips_kprobe_multi(false);
91135
if (test__start_subtest("kretprobe_multi"))
92136
test_stacktrace_ips_kprobe_multi(true);
137+
if (test__start_subtest("raw_tp"))
138+
test_stacktrace_ips_raw_tp();
93139
}
94140
#else
95141
static void __test_stacktrace_ips(void)

tools/testing/selftests/bpf/progs/stacktrace_ips.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ int kprobe_multi_test(struct pt_regs *ctx)
3838
return 0;
3939
}
4040

41+
SEC("raw_tp/bpf_testmod_test_read")
42+
int rawtp_test(void *ctx)
43+
{
44+
/* Skip ebpf program entry in the stack. */
45+
stack_key = bpf_get_stackid(ctx, &stackmap, 0);
46+
return 0;
47+
}
48+
4149
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)