|
11 | 11 | #include <bpf/btf.h>
|
12 | 12 | #include "test_bpf_cookie.skel.h"
|
13 | 13 | #include "kprobe_multi.skel.h"
|
| 14 | +#include "uprobe_multi.skel.h" |
14 | 15 |
|
15 | 16 | /* uprobe attach point */
|
16 | 17 | static noinline void trigger_func(void)
|
@@ -239,6 +240,81 @@ static void kprobe_multi_attach_api_subtest(void)
|
239 | 240 | bpf_link__destroy(link1);
|
240 | 241 | kprobe_multi__destroy(skel);
|
241 | 242 | }
|
| 243 | + |
| 244 | +/* defined in prog_tests/uprobe_multi_test.c */ |
| 245 | +void uprobe_multi_func_1(void); |
| 246 | +void uprobe_multi_func_2(void); |
| 247 | +void uprobe_multi_func_3(void); |
| 248 | + |
| 249 | +static void uprobe_multi_test_run(struct uprobe_multi *skel) |
| 250 | +{ |
| 251 | + skel->bss->uprobe_multi_func_1_addr = (__u64) uprobe_multi_func_1; |
| 252 | + skel->bss->uprobe_multi_func_2_addr = (__u64) uprobe_multi_func_2; |
| 253 | + skel->bss->uprobe_multi_func_3_addr = (__u64) uprobe_multi_func_3; |
| 254 | + |
| 255 | + skel->bss->pid = getpid(); |
| 256 | + skel->bss->test_cookie = true; |
| 257 | + |
| 258 | + uprobe_multi_func_1(); |
| 259 | + uprobe_multi_func_2(); |
| 260 | + uprobe_multi_func_3(); |
| 261 | + |
| 262 | + ASSERT_EQ(skel->bss->uprobe_multi_func_1_result, 1, "uprobe_multi_func_1_result"); |
| 263 | + ASSERT_EQ(skel->bss->uprobe_multi_func_2_result, 1, "uprobe_multi_func_2_result"); |
| 264 | + ASSERT_EQ(skel->bss->uprobe_multi_func_3_result, 1, "uprobe_multi_func_3_result"); |
| 265 | + |
| 266 | + ASSERT_EQ(skel->bss->uretprobe_multi_func_1_result, 1, "uretprobe_multi_func_1_result"); |
| 267 | + ASSERT_EQ(skel->bss->uretprobe_multi_func_2_result, 1, "uretprobe_multi_func_2_result"); |
| 268 | + ASSERT_EQ(skel->bss->uretprobe_multi_func_3_result, 1, "uretprobe_multi_func_3_result"); |
| 269 | +} |
| 270 | + |
| 271 | +static void uprobe_multi_attach_api_subtest(void) |
| 272 | +{ |
| 273 | + struct bpf_link *link1 = NULL, *link2 = NULL; |
| 274 | + struct uprobe_multi *skel = NULL; |
| 275 | + LIBBPF_OPTS(bpf_uprobe_multi_opts, opts); |
| 276 | + const char *syms[3] = { |
| 277 | + "uprobe_multi_func_1", |
| 278 | + "uprobe_multi_func_2", |
| 279 | + "uprobe_multi_func_3", |
| 280 | + }; |
| 281 | + __u64 cookies[3]; |
| 282 | + |
| 283 | + cookies[0] = 3; /* uprobe_multi_func_1 */ |
| 284 | + cookies[1] = 1; /* uprobe_multi_func_2 */ |
| 285 | + cookies[2] = 2; /* uprobe_multi_func_3 */ |
| 286 | + |
| 287 | + opts.syms = syms; |
| 288 | + opts.cnt = ARRAY_SIZE(syms); |
| 289 | + opts.cookies = &cookies[0]; |
| 290 | + |
| 291 | + skel = uprobe_multi__open_and_load(); |
| 292 | + if (!ASSERT_OK_PTR(skel, "uprobe_multi")) |
| 293 | + goto cleanup; |
| 294 | + |
| 295 | + link1 = bpf_program__attach_uprobe_multi(skel->progs.uprobe, -1, |
| 296 | + "/proc/self/exe", NULL, &opts); |
| 297 | + if (!ASSERT_OK_PTR(link1, "bpf_program__attach_uprobe_multi")) |
| 298 | + goto cleanup; |
| 299 | + |
| 300 | + cookies[0] = 2; /* uprobe_multi_func_1 */ |
| 301 | + cookies[1] = 3; /* uprobe_multi_func_2 */ |
| 302 | + cookies[2] = 1; /* uprobe_multi_func_3 */ |
| 303 | + |
| 304 | + opts.retprobe = true; |
| 305 | + link2 = bpf_program__attach_uprobe_multi(skel->progs.uretprobe, -1, |
| 306 | + "/proc/self/exe", NULL, &opts); |
| 307 | + if (!ASSERT_OK_PTR(link2, "bpf_program__attach_uprobe_multi_retprobe")) |
| 308 | + goto cleanup; |
| 309 | + |
| 310 | + uprobe_multi_test_run(skel); |
| 311 | + |
| 312 | +cleanup: |
| 313 | + bpf_link__destroy(link2); |
| 314 | + bpf_link__destroy(link1); |
| 315 | + uprobe_multi__destroy(skel); |
| 316 | +} |
| 317 | + |
242 | 318 | static void uprobe_subtest(struct test_bpf_cookie *skel)
|
243 | 319 | {
|
244 | 320 | DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, opts);
|
@@ -515,6 +591,8 @@ void test_bpf_cookie(void)
|
515 | 591 | kprobe_multi_attach_api_subtest();
|
516 | 592 | if (test__start_subtest("uprobe"))
|
517 | 593 | uprobe_subtest(skel);
|
| 594 | + if (test__start_subtest("multi_uprobe_attach_api")) |
| 595 | + uprobe_multi_attach_api_subtest(); |
518 | 596 | if (test__start_subtest("tracepoint"))
|
519 | 597 | tp_subtest(skel);
|
520 | 598 | if (test__start_subtest("perf_event"))
|
|
0 commit comments