|
2 | 2 |
|
3 | 3 | #include <unistd.h> |
4 | 4 | #include <pthread.h> |
| 5 | +#include <fcntl.h> |
5 | 6 | #include <test_progs.h> |
6 | 7 | #include "uprobe_multi.skel.h" |
7 | 8 | #include "uprobe_multi_bench.skel.h" |
@@ -757,6 +758,65 @@ static void test_link_api(void) |
757 | 758 | __test_link_api(&child); |
758 | 759 | } |
759 | 760 |
|
| 761 | +static void test_link_api_path_fd(void) |
| 762 | +{ |
| 763 | + const char *resolve_path = "/proc/self/exe"; |
| 764 | + LIBBPF_OPTS(bpf_link_create_opts, opts); |
| 765 | + int prog_fd, link_fd = -1, path_fd = -1; |
| 766 | + struct uprobe_multi *skel = NULL; |
| 767 | + unsigned long *offsets = NULL; |
| 768 | + const char *syms[3] = { |
| 769 | + "uprobe_multi_func_1", |
| 770 | + "uprobe_multi_func_2", |
| 771 | + "uprobe_multi_func_3", |
| 772 | + }; |
| 773 | + int err; |
| 774 | + |
| 775 | + err = elf_resolve_syms_offsets(resolve_path, ARRAY_SIZE(syms), syms, |
| 776 | + &offsets, STT_FUNC); |
| 777 | + if (!ASSERT_OK(err, "elf_resolve_syms_offsets")) |
| 778 | + return; |
| 779 | + |
| 780 | + path_fd = open(resolve_path, O_RDONLY); |
| 781 | + if (!ASSERT_GE(path_fd, 0, "path_fd")) |
| 782 | + goto cleanup; |
| 783 | + |
| 784 | + opts.uprobe_multi.path_fd = path_fd; |
| 785 | + opts.uprobe_multi.offsets = offsets; |
| 786 | + opts.uprobe_multi.cnt = ARRAY_SIZE(syms); |
| 787 | + opts.uprobe_multi.flags = BPF_F_UPROBE_MULTI_PATH_FD; |
| 788 | + |
| 789 | + skel = uprobe_multi__open_and_load(); |
| 790 | + if (!ASSERT_OK_PTR(skel, "uprobe_multi__open_and_load")) |
| 791 | + goto cleanup; |
| 792 | + |
| 793 | + prog_fd = bpf_program__fd(skel->progs.uprobe); |
| 794 | + link_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts); |
| 795 | + if (!ASSERT_GE(link_fd, 0, "bpf_link_create")) |
| 796 | + goto cleanup; |
| 797 | + |
| 798 | + skel->bss->uprobe_multi_func_1_addr = (__u64)uprobe_multi_func_1; |
| 799 | + skel->bss->uprobe_multi_func_2_addr = (__u64)uprobe_multi_func_2; |
| 800 | + skel->bss->uprobe_multi_func_3_addr = (__u64)uprobe_multi_func_3; |
| 801 | + skel->bss->pid = getpid(); |
| 802 | + |
| 803 | + uprobe_multi_func_1(); |
| 804 | + uprobe_multi_func_2(); |
| 805 | + uprobe_multi_func_3(); |
| 806 | + |
| 807 | + ASSERT_EQ(skel->bss->uprobe_multi_func_1_result, 1, "uprobe_multi_func_1_result"); |
| 808 | + ASSERT_EQ(skel->bss->uprobe_multi_func_2_result, 1, "uprobe_multi_func_2_result"); |
| 809 | + ASSERT_EQ(skel->bss->uprobe_multi_func_3_result, 1, "uprobe_multi_func_3_result"); |
| 810 | + |
| 811 | +cleanup: |
| 812 | + if (link_fd >= 0) |
| 813 | + close(link_fd); |
| 814 | + if (path_fd >= 0) |
| 815 | + close(path_fd); |
| 816 | + uprobe_multi__destroy(skel); |
| 817 | + free(offsets); |
| 818 | +} |
| 819 | + |
760 | 820 | static struct bpf_program * |
761 | 821 | get_program(struct uprobe_multi_consumers *skel, int prog) |
762 | 822 | { |
@@ -1354,6 +1414,8 @@ void test_uprobe_multi_test(void) |
1354 | 1414 | test_attach_api_syms(); |
1355 | 1415 | if (test__start_subtest("link_api")) |
1356 | 1416 | test_link_api(); |
| 1417 | + if (test__start_subtest("link_api_path_fd")) |
| 1418 | + test_link_api_path_fd(); |
1357 | 1419 | if (test__start_subtest("bench_uprobe")) |
1358 | 1420 | test_bench_attach_uprobe(); |
1359 | 1421 | if (test__start_subtest("bench_usdt")) |
|
0 commit comments