Skip to content

Commit 8909a93

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
selftests/bpf: Add extra link to uprobe_multi tests
Attaching extra program to same functions system wide for api and link tests. This way we can test the pid filter works properly when there's extra system wide consumer on the same uprobe that will trigger the original uprobe handler. We expect to have the same counts as before. Signed-off-by: Jiri Olsa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent d571efa commit 8909a93

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ __test_attach_api(const char *binary, const char *pattern, struct bpf_uprobe_mul
184184
if (!ASSERT_OK_PTR(skel->links.uretprobe_sleep, "bpf_program__attach_uprobe_multi"))
185185
goto cleanup;
186186

187+
opts->retprobe = false;
188+
skel->links.uprobe_extra = bpf_program__attach_uprobe_multi(skel->progs.uprobe_extra, -1,
189+
binary, pattern, opts);
190+
if (!ASSERT_OK_PTR(skel->links.uprobe_extra, "bpf_program__attach_uprobe_multi"))
191+
goto cleanup;
192+
187193
uprobe_multi_test_run(skel, child);
188194

189195
cleanup:
@@ -240,6 +246,7 @@ static void __test_link_api(struct child *child)
240246
"uprobe_multi_func_2",
241247
"uprobe_multi_func_3",
242248
};
249+
int link_extra_fd = -1;
243250
int err;
244251

245252
err = elf_resolve_syms_offsets(path, 3, syms, (unsigned long **) &offsets);
@@ -279,6 +286,13 @@ static void __test_link_api(struct child *child)
279286
if (!ASSERT_GE(link4_fd, 0, "link4_fd"))
280287
goto cleanup;
281288

289+
opts.kprobe_multi.flags = 0;
290+
opts.uprobe_multi.pid = 0;
291+
prog_fd = bpf_program__fd(skel->progs.uprobe_extra);
292+
link_extra_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts);
293+
if (!ASSERT_GE(link_extra_fd, 0, "link_extra_fd"))
294+
goto cleanup;
295+
282296
uprobe_multi_test_run(skel, child);
283297

284298
cleanup:
@@ -290,6 +304,8 @@ static void __test_link_api(struct child *child)
290304
close(link3_fd);
291305
if (link4_fd >= 0)
292306
close(link4_fd);
307+
if (link_extra_fd >= 0)
308+
close(link_extra_fd);
293309

294310
uprobe_multi__destroy(skel);
295311
free(offsets);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,9 @@ int uretprobe_sleep(struct pt_regs *ctx)
9393
uprobe_multi_check(ctx, true, true);
9494
return 0;
9595
}
96+
97+
SEC("uprobe.multi//proc/self/exe:uprobe_multi_func_*")
98+
int uprobe_extra(struct pt_regs *ctx)
99+
{
100+
return 0;
101+
}

0 commit comments

Comments
 (0)