Skip to content

Commit 318c812

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
selftests/bpf: Add cookie test for bpf_program__attach_kprobe_multi_opts
Adding bpf_cookie test for programs attached by bpf_program__attach_kprobe_multi_opts API. Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9271a0c commit 318c812

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,72 @@ static void kprobe_multi_link_api_subtest(void)
170170
kprobe_multi__destroy(skel);
171171
}
172172

173+
static void kprobe_multi_attach_api_subtest(void)
174+
{
175+
struct bpf_link *link1 = NULL, *link2 = NULL;
176+
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
177+
LIBBPF_OPTS(bpf_test_run_opts, topts);
178+
struct kprobe_multi *skel = NULL;
179+
const char *syms[8] = {
180+
"bpf_fentry_test1",
181+
"bpf_fentry_test2",
182+
"bpf_fentry_test3",
183+
"bpf_fentry_test4",
184+
"bpf_fentry_test5",
185+
"bpf_fentry_test6",
186+
"bpf_fentry_test7",
187+
"bpf_fentry_test8",
188+
};
189+
__u64 cookies[8];
190+
191+
skel = kprobe_multi__open_and_load();
192+
if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load"))
193+
goto cleanup;
194+
195+
skel->bss->pid = getpid();
196+
skel->bss->test_cookie = true;
197+
198+
cookies[0] = 1;
199+
cookies[1] = 2;
200+
cookies[2] = 3;
201+
cookies[3] = 4;
202+
cookies[4] = 5;
203+
cookies[5] = 6;
204+
cookies[6] = 7;
205+
cookies[7] = 8;
206+
207+
opts.syms = syms;
208+
opts.cnt = ARRAY_SIZE(syms);
209+
opts.cookies = cookies;
210+
211+
link1 = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe,
212+
NULL, &opts);
213+
if (!ASSERT_OK_PTR(link1, "bpf_program__attach_kprobe_multi_opts"))
214+
goto cleanup;
215+
216+
cookies[0] = 8;
217+
cookies[1] = 7;
218+
cookies[2] = 6;
219+
cookies[3] = 5;
220+
cookies[4] = 4;
221+
cookies[5] = 3;
222+
cookies[6] = 2;
223+
cookies[7] = 1;
224+
225+
opts.retprobe = true;
226+
227+
link2 = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kretprobe,
228+
NULL, &opts);
229+
if (!ASSERT_OK_PTR(link2, "bpf_program__attach_kprobe_multi_opts"))
230+
goto cleanup;
231+
232+
kprobe_multi_test_run(skel);
233+
234+
cleanup:
235+
bpf_link__destroy(link2);
236+
bpf_link__destroy(link1);
237+
kprobe_multi__destroy(skel);
238+
}
173239
static void uprobe_subtest(struct test_bpf_cookie *skel)
174240
{
175241
DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, opts);
@@ -358,6 +424,8 @@ void test_bpf_cookie(void)
358424
kprobe_subtest(skel);
359425
if (test__start_subtest("multi_kprobe_link_api"))
360426
kprobe_multi_link_api_subtest();
427+
if (test__start_subtest("multi_kprobe_attach_api"))
428+
kprobe_multi_attach_api_subtest();
361429
if (test__start_subtest("uprobe"))
362430
uprobe_subtest(skel);
363431
if (test__start_subtest("tracepoint"))

0 commit comments

Comments
 (0)