|
3 | 3 | #include "kprobe_multi.skel.h"
|
4 | 4 | #include "trace_helpers.h"
|
5 | 5 | #include "kprobe_multi_empty.skel.h"
|
| 6 | +#include "kprobe_multi_override.skel.h" |
6 | 7 | #include "bpf/libbpf_internal.h"
|
7 | 8 | #include "bpf/hashmap.h"
|
8 | 9 |
|
@@ -453,6 +454,40 @@ static void test_kprobe_multi_bench_attach(bool kernel)
|
453 | 454 | }
|
454 | 455 | }
|
455 | 456 |
|
| 457 | +void test_attach_override(void) |
| 458 | +{ |
| 459 | + struct kprobe_multi_override *skel = NULL; |
| 460 | + struct bpf_link *link = NULL; |
| 461 | + |
| 462 | + skel = kprobe_multi_override__open_and_load(); |
| 463 | + if (!ASSERT_OK_PTR(skel, "kprobe_multi_empty__open_and_load")) |
| 464 | + goto cleanup; |
| 465 | + |
| 466 | + /* The test_override calls bpf_override_return so it should fail |
| 467 | + * to attach to bpf_fentry_test1 function, which is not on error |
| 468 | + * injection list. |
| 469 | + */ |
| 470 | + link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_override, |
| 471 | + "bpf_fentry_test1", NULL); |
| 472 | + if (!ASSERT_ERR_PTR(link, "override_attached_bpf_fentry_test1")) { |
| 473 | + bpf_link__destroy(link); |
| 474 | + goto cleanup; |
| 475 | + } |
| 476 | + |
| 477 | + /* The should_fail_bio function is on error injection list, |
| 478 | + * attach should succeed. |
| 479 | + */ |
| 480 | + link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_override, |
| 481 | + "should_fail_bio", NULL); |
| 482 | + if (!ASSERT_OK_PTR(link, "override_attached_should_fail_bio")) |
| 483 | + goto cleanup; |
| 484 | + |
| 485 | + bpf_link__destroy(link); |
| 486 | + |
| 487 | +cleanup: |
| 488 | + kprobe_multi_override__destroy(skel); |
| 489 | +} |
| 490 | + |
456 | 491 | void serial_test_kprobe_multi_bench_attach(void)
|
457 | 492 | {
|
458 | 493 | if (test__start_subtest("kernel"))
|
@@ -480,4 +515,6 @@ void test_kprobe_multi_test(void)
|
480 | 515 | test_attach_api_syms();
|
481 | 516 | if (test__start_subtest("attach_api_fails"))
|
482 | 517 | test_attach_api_fails();
|
| 518 | + if (test__start_subtest("attach_override")) |
| 519 | + test_attach_override(); |
483 | 520 | }
|
0 commit comments