|
1 | 1 | // SPDX-License-Identifier: GPL-2.0
|
2 | 2 | #include <test_progs.h>
|
3 | 3 | #include "test_attach_kprobe_sleepable.skel.h"
|
| 4 | +#include "test_attach_probe_manual.skel.h" |
4 | 5 | #include "test_attach_probe.skel.h"
|
5 | 6 |
|
6 | 7 | /* this is how USDT semaphore is actually defined, except volatile modifier */
|
@@ -33,33 +34,43 @@ static noinline void trigger_func4(void)
|
33 | 34 | static char test_data[] = "test_data";
|
34 | 35 |
|
35 | 36 | /* manual attach kprobe/kretprobe/uprobe/uretprobe testings */
|
36 |
| -static void test_attach_probe_manual(struct test_attach_probe *skel) |
| 37 | +static void test_attach_probe_manual(enum probe_attach_mode attach_mode) |
37 | 38 | {
|
38 | 39 | DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
|
| 40 | + DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, kprobe_opts); |
39 | 41 | struct bpf_link *kprobe_link, *kretprobe_link;
|
40 | 42 | struct bpf_link *uprobe_link, *uretprobe_link;
|
| 43 | + struct test_attach_probe_manual *skel; |
41 | 44 | ssize_t uprobe_offset;
|
42 | 45 |
|
| 46 | + skel = test_attach_probe_manual__open_and_load(); |
| 47 | + if (!ASSERT_OK_PTR(skel, "skel_kprobe_manual_open_and_load")) |
| 48 | + return; |
| 49 | + |
43 | 50 | uprobe_offset = get_uprobe_offset(&trigger_func);
|
44 | 51 | if (!ASSERT_GE(uprobe_offset, 0, "uprobe_offset"))
|
45 | 52 | goto cleanup;
|
46 | 53 |
|
47 | 54 | /* manual-attach kprobe/kretprobe */
|
48 |
| - kprobe_link = bpf_program__attach_kprobe(skel->progs.handle_kprobe, |
49 |
| - false /* retprobe */, |
50 |
| - SYS_NANOSLEEP_KPROBE_NAME); |
| 55 | + kprobe_opts.attach_mode = attach_mode; |
| 56 | + kprobe_opts.retprobe = false; |
| 57 | + kprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kprobe, |
| 58 | + SYS_NANOSLEEP_KPROBE_NAME, |
| 59 | + &kprobe_opts); |
51 | 60 | if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe"))
|
52 | 61 | goto cleanup;
|
53 | 62 | skel->links.handle_kprobe = kprobe_link;
|
54 | 63 |
|
55 |
| - kretprobe_link = bpf_program__attach_kprobe(skel->progs.handle_kretprobe, |
56 |
| - true /* retprobe */, |
57 |
| - SYS_NANOSLEEP_KPROBE_NAME); |
| 64 | + kprobe_opts.retprobe = true; |
| 65 | + kretprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kretprobe, |
| 66 | + SYS_NANOSLEEP_KPROBE_NAME, |
| 67 | + &kprobe_opts); |
58 | 68 | if (!ASSERT_OK_PTR(kretprobe_link, "attach_kretprobe"))
|
59 | 69 | goto cleanup;
|
60 | 70 | skel->links.handle_kretprobe = kretprobe_link;
|
61 | 71 |
|
62 | 72 | /* manual-attach uprobe/uretprobe */
|
| 73 | + uprobe_opts.attach_mode = attach_mode; |
63 | 74 | uprobe_opts.ref_ctr_offset = 0;
|
64 | 75 | uprobe_opts.retprobe = false;
|
65 | 76 | uprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uprobe,
|
@@ -108,6 +119,7 @@ static void test_attach_probe_manual(struct test_attach_probe *skel)
|
108 | 119 | ASSERT_EQ(skel->bss->uprobe_byname_res, 5, "check_uprobe_byname_res");
|
109 | 120 |
|
110 | 121 | cleanup:
|
| 122 | + test_attach_probe_manual__destroy(skel); |
111 | 123 | }
|
112 | 124 |
|
113 | 125 | static void test_attach_probe_auto(struct test_attach_probe *skel)
|
@@ -289,8 +301,15 @@ void test_attach_probe(void)
|
289 | 301 | if (!ASSERT_OK_PTR(skel->bss, "check_bss"))
|
290 | 302 | goto cleanup;
|
291 | 303 |
|
292 |
| - if (test__start_subtest("manual")) |
293 |
| - test_attach_probe_manual(skel); |
| 304 | + if (test__start_subtest("manual-default")) |
| 305 | + test_attach_probe_manual(PROBE_ATTACH_MODE_DEFAULT); |
| 306 | + if (test__start_subtest("manual-legacy")) |
| 307 | + test_attach_probe_manual(PROBE_ATTACH_MODE_LEGACY); |
| 308 | + if (test__start_subtest("manual-perf")) |
| 309 | + test_attach_probe_manual(PROBE_ATTACH_MODE_PERF); |
| 310 | + if (test__start_subtest("manual-link")) |
| 311 | + test_attach_probe_manual(PROBE_ATTACH_MODE_LINK); |
| 312 | + |
294 | 313 | if (test__start_subtest("auto"))
|
295 | 314 | test_attach_probe_auto(skel);
|
296 | 315 | if (test__start_subtest("kprobe-sleepable"))
|
|
0 commit comments