11e8611bbSAndrii Nakryiko // SPDX-License-Identifier: GPL-2.0
21e8611bbSAndrii Nakryiko #include <test_progs.h>
37391ec63SMenglong Dong #include "test_attach_kprobe_sleepable.skel.h"
4*c7aec81bSMenglong Dong #include "test_attach_probe_manual.skel.h"
5f3c926a4SAndrii Nakryiko #include "test_attach_probe.skel.h"
61e8611bbSAndrii Nakryiko 
74bd11e08SAndrii Nakryiko /* this is how USDT semaphore is actually defined, except volatile modifier */
84bd11e08SAndrii Nakryiko volatile unsigned short uprobe_ref_ctr __attribute__((unused)) __attribute((section(".probes")));
94bd11e08SAndrii Nakryiko 
10ff943683SAndrii Nakryiko /* uprobe attach point */
trigger_func(void)11df78da27SAndrii Nakryiko static noinline void trigger_func(void)
12ff943683SAndrii Nakryiko {
13ff943683SAndrii Nakryiko 	asm volatile ("");
149e7240fbSYucong Sun }
159e7240fbSYucong Sun 
16ba7499bcSAlan Maguire /* attach point for byname uprobe */
trigger_func2(void)17df78da27SAndrii Nakryiko static noinline void trigger_func2(void)
18ba7499bcSAlan Maguire {
19ba7499bcSAlan Maguire 	asm volatile ("");
20ba7499bcSAlan Maguire }
21ba7499bcSAlan Maguire 
22cb3f4a4aSDelyan Kratunov /* attach point for byname sleepable uprobe */
trigger_func3(void)23df78da27SAndrii Nakryiko static noinline void trigger_func3(void)
24cb3f4a4aSDelyan Kratunov {
25cb3f4a4aSDelyan Kratunov 	asm volatile ("");
26cb3f4a4aSDelyan Kratunov }
27cb3f4a4aSDelyan Kratunov 
287391ec63SMenglong Dong /* attach point for ref_ctr */
trigger_func4(void)297391ec63SMenglong Dong static noinline void trigger_func4(void)
307391ec63SMenglong Dong {
317391ec63SMenglong Dong 	asm volatile ("");
327391ec63SMenglong Dong }
337391ec63SMenglong Dong 
34cb3f4a4aSDelyan Kratunov static char test_data[] = "test_data";
35cb3f4a4aSDelyan Kratunov 
367391ec63SMenglong Dong /* manual attach kprobe/kretprobe/uprobe/uretprobe testings */
test_attach_probe_manual(enum probe_attach_mode attach_mode)37*c7aec81bSMenglong Dong static void test_attach_probe_manual(enum probe_attach_mode attach_mode)
381e8611bbSAndrii Nakryiko {
394bd11e08SAndrii Nakryiko 	DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
40*c7aec81bSMenglong Dong 	DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, kprobe_opts);
41f3c926a4SAndrii Nakryiko 	struct bpf_link *kprobe_link, *kretprobe_link;
42f3c926a4SAndrii Nakryiko 	struct bpf_link *uprobe_link, *uretprobe_link;
43*c7aec81bSMenglong Dong 	struct test_attach_probe_manual *skel;
447391ec63SMenglong Dong 	ssize_t uprobe_offset;
451e8611bbSAndrii Nakryiko 
46*c7aec81bSMenglong Dong 	skel = test_attach_probe_manual__open_and_load();
47*c7aec81bSMenglong Dong 	if (!ASSERT_OK_PTR(skel, "skel_kprobe_manual_open_and_load"))
48*c7aec81bSMenglong Dong 		return;
49*c7aec81bSMenglong Dong 
50ff943683SAndrii Nakryiko 	uprobe_offset = get_uprobe_offset(&trigger_func);
51ff943683SAndrii Nakryiko 	if (!ASSERT_GE(uprobe_offset, 0, "uprobe_offset"))
52928ca75eSAndrii Nakryiko 		goto cleanup;
53928ca75eSAndrii Nakryiko 
5432c03c49SAndrii Nakryiko 	/* manual-attach kprobe/kretprobe */
55*c7aec81bSMenglong Dong 	kprobe_opts.attach_mode = attach_mode;
56*c7aec81bSMenglong Dong 	kprobe_opts.retprobe = false;
57*c7aec81bSMenglong Dong 	kprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kprobe,
58*c7aec81bSMenglong Dong 						      SYS_NANOSLEEP_KPROBE_NAME,
59*c7aec81bSMenglong Dong 						      &kprobe_opts);
60bad2e478SAndrii Nakryiko 	if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe"))
611e8611bbSAndrii Nakryiko 		goto cleanup;
62f3c926a4SAndrii Nakryiko 	skel->links.handle_kprobe = kprobe_link;
63f3c926a4SAndrii Nakryiko 
64*c7aec81bSMenglong Dong 	kprobe_opts.retprobe = true;
65*c7aec81bSMenglong Dong 	kretprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kretprobe,
66*c7aec81bSMenglong Dong 							 SYS_NANOSLEEP_KPROBE_NAME,
67*c7aec81bSMenglong Dong 							 &kprobe_opts);
68bad2e478SAndrii Nakryiko 	if (!ASSERT_OK_PTR(kretprobe_link, "attach_kretprobe"))
691e8611bbSAndrii Nakryiko 		goto cleanup;
70f3c926a4SAndrii Nakryiko 	skel->links.handle_kretprobe = kretprobe_link;
71f3c926a4SAndrii Nakryiko 
727391ec63SMenglong Dong 	/* manual-attach uprobe/uretprobe */
73*c7aec81bSMenglong Dong 	uprobe_opts.attach_mode = attach_mode;
747391ec63SMenglong Dong 	uprobe_opts.ref_ctr_offset = 0;
754bd11e08SAndrii Nakryiko 	uprobe_opts.retprobe = false;
764bd11e08SAndrii Nakryiko 	uprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uprobe,
771e8611bbSAndrii Nakryiko 						      0 /* self pid */,
781e8611bbSAndrii Nakryiko 						      "/proc/self/exe",
794bd11e08SAndrii Nakryiko 						      uprobe_offset,
804bd11e08SAndrii Nakryiko 						      &uprobe_opts);
81bad2e478SAndrii Nakryiko 	if (!ASSERT_OK_PTR(uprobe_link, "attach_uprobe"))
821e8611bbSAndrii Nakryiko 		goto cleanup;
83f3c926a4SAndrii Nakryiko 	skel->links.handle_uprobe = uprobe_link;
84f3c926a4SAndrii Nakryiko 
854bd11e08SAndrii Nakryiko 	uprobe_opts.retprobe = true;
864bd11e08SAndrii Nakryiko 	uretprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uretprobe,
871e8611bbSAndrii Nakryiko 							 -1 /* any pid */,
881e8611bbSAndrii Nakryiko 							 "/proc/self/exe",
894bd11e08SAndrii Nakryiko 							 uprobe_offset, &uprobe_opts);
90bad2e478SAndrii Nakryiko 	if (!ASSERT_OK_PTR(uretprobe_link, "attach_uretprobe"))
911e8611bbSAndrii Nakryiko 		goto cleanup;
92f3c926a4SAndrii Nakryiko 	skel->links.handle_uretprobe = uretprobe_link;
931e8611bbSAndrii Nakryiko 
947391ec63SMenglong Dong 	/* attach uprobe by function name manually */
95ba7499bcSAlan Maguire 	uprobe_opts.func_name = "trigger_func2";
96ba7499bcSAlan Maguire 	uprobe_opts.retprobe = false;
97ba7499bcSAlan Maguire 	uprobe_opts.ref_ctr_offset = 0;
98ba7499bcSAlan Maguire 	skel->links.handle_uprobe_byname =
99ba7499bcSAlan Maguire 			bpf_program__attach_uprobe_opts(skel->progs.handle_uprobe_byname,
100ba7499bcSAlan Maguire 							0 /* this pid */,
101ba7499bcSAlan Maguire 							"/proc/self/exe",
102ba7499bcSAlan Maguire 							0, &uprobe_opts);
103ba7499bcSAlan Maguire 	if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname, "attach_uprobe_byname"))
104ba7499bcSAlan Maguire 		goto cleanup;
105ba7499bcSAlan Maguire 
1067391ec63SMenglong Dong 	/* trigger & validate kprobe && kretprobe */
1077391ec63SMenglong Dong 	usleep(1);
1087391ec63SMenglong Dong 
1097391ec63SMenglong Dong 	/* trigger & validate uprobe & uretprobe */
1107391ec63SMenglong Dong 	trigger_func();
1117391ec63SMenglong Dong 
1127391ec63SMenglong Dong 	/* trigger & validate uprobe attached by name */
1137391ec63SMenglong Dong 	trigger_func2();
1147391ec63SMenglong Dong 
1157391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->kprobe_res, 1, "check_kprobe_res");
1167391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->kretprobe_res, 2, "check_kretprobe_res");
1177391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->uprobe_res, 3, "check_uprobe_res");
1187391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->uretprobe_res, 4, "check_uretprobe_res");
1197391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->uprobe_byname_res, 5, "check_uprobe_byname_res");
1207391ec63SMenglong Dong 
1217391ec63SMenglong Dong cleanup:
122*c7aec81bSMenglong Dong 	test_attach_probe_manual__destroy(skel);
1237391ec63SMenglong Dong }
1247391ec63SMenglong Dong 
test_attach_probe_auto(struct test_attach_probe * skel)1257391ec63SMenglong Dong static void test_attach_probe_auto(struct test_attach_probe *skel)
1267391ec63SMenglong Dong {
1277391ec63SMenglong Dong 	struct bpf_link *uprobe_err_link;
1287391ec63SMenglong Dong 
1297391ec63SMenglong Dong 	/* auto-attachable kprobe and kretprobe */
1307391ec63SMenglong Dong 	skel->links.handle_kprobe_auto = bpf_program__attach(skel->progs.handle_kprobe_auto);
1317391ec63SMenglong Dong 	ASSERT_OK_PTR(skel->links.handle_kprobe_auto, "attach_kprobe_auto");
1327391ec63SMenglong Dong 
1337391ec63SMenglong Dong 	skel->links.handle_kretprobe_auto = bpf_program__attach(skel->progs.handle_kretprobe_auto);
1347391ec63SMenglong Dong 	ASSERT_OK_PTR(skel->links.handle_kretprobe_auto, "attach_kretprobe_auto");
1357391ec63SMenglong Dong 
1367391ec63SMenglong Dong 	/* verify auto-attach fails for old-style uprobe definition */
1377391ec63SMenglong Dong 	uprobe_err_link = bpf_program__attach(skel->progs.handle_uprobe_byname);
1387391ec63SMenglong Dong 	if (!ASSERT_EQ(libbpf_get_error(uprobe_err_link), -EOPNOTSUPP,
1397391ec63SMenglong Dong 		       "auto-attach should fail for old-style name"))
1407391ec63SMenglong Dong 		return;
1417391ec63SMenglong Dong 
142ba7499bcSAlan Maguire 	/* verify auto-attach works */
143ba7499bcSAlan Maguire 	skel->links.handle_uretprobe_byname =
144ba7499bcSAlan Maguire 			bpf_program__attach(skel->progs.handle_uretprobe_byname);
145ba7499bcSAlan Maguire 	if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname, "attach_uretprobe_byname"))
1467391ec63SMenglong Dong 		return;
1477391ec63SMenglong Dong 
1487391ec63SMenglong Dong 	/* trigger & validate kprobe && kretprobe */
1497391ec63SMenglong Dong 	usleep(1);
1507391ec63SMenglong Dong 
1517391ec63SMenglong Dong 	/* trigger & validate uprobe attached by name */
1527391ec63SMenglong Dong 	trigger_func2();
1537391ec63SMenglong Dong 
1547391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->kprobe2_res, 11, "check_kprobe_auto_res");
1557391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->kretprobe2_res, 22, "check_kretprobe_auto_res");
1567391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->uretprobe_byname_res, 6, "check_uretprobe_byname_res");
1577391ec63SMenglong Dong }
1587391ec63SMenglong Dong 
test_uprobe_lib(struct test_attach_probe * skel)1597391ec63SMenglong Dong static void test_uprobe_lib(struct test_attach_probe *skel)
1607391ec63SMenglong Dong {
1617391ec63SMenglong Dong 	DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
1627391ec63SMenglong Dong 	FILE *devnull;
163ba7499bcSAlan Maguire 
164ba7499bcSAlan Maguire 	/* test attach by name for a library function, using the library
165ba7499bcSAlan Maguire 	 * as the binary argument. libc.so.6 will be resolved via dlopen()/dlinfo().
166ba7499bcSAlan Maguire 	 */
167202702e8SIlya Leoshkevich 	uprobe_opts.func_name = "fopen";
168ba7499bcSAlan Maguire 	uprobe_opts.retprobe = false;
169ba7499bcSAlan Maguire 	skel->links.handle_uprobe_byname2 =
170ba7499bcSAlan Maguire 			bpf_program__attach_uprobe_opts(skel->progs.handle_uprobe_byname2,
171ba7499bcSAlan Maguire 							0 /* this pid */,
172ba7499bcSAlan Maguire 							"libc.so.6",
173ba7499bcSAlan Maguire 							0, &uprobe_opts);
174ba7499bcSAlan Maguire 	if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname2, "attach_uprobe_byname2"))
1757391ec63SMenglong Dong 		return;
176ba7499bcSAlan Maguire 
177202702e8SIlya Leoshkevich 	uprobe_opts.func_name = "fclose";
178ba7499bcSAlan Maguire 	uprobe_opts.retprobe = true;
179ba7499bcSAlan Maguire 	skel->links.handle_uretprobe_byname2 =
180ba7499bcSAlan Maguire 			bpf_program__attach_uprobe_opts(skel->progs.handle_uretprobe_byname2,
181ba7499bcSAlan Maguire 							-1 /* any pid */,
182ba7499bcSAlan Maguire 							"libc.so.6",
183ba7499bcSAlan Maguire 							0, &uprobe_opts);
184ba7499bcSAlan Maguire 	if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname2, "attach_uretprobe_byname2"))
1857391ec63SMenglong Dong 		return;
1861e8611bbSAndrii Nakryiko 
187ba7499bcSAlan Maguire 	/* trigger & validate shared library u[ret]probes attached by name */
188202702e8SIlya Leoshkevich 	devnull = fopen("/dev/null", "r");
189202702e8SIlya Leoshkevich 	fclose(devnull);
1901e8611bbSAndrii Nakryiko 
1917391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->uprobe_byname2_res, 7, "check_uprobe_byname2_res");
1927391ec63SMenglong Dong 	ASSERT_EQ(skel->bss->uretprobe_byname2_res, 8, "check_uretprobe_byname2_res");
1937391ec63SMenglong Dong }
1941e8611bbSAndrii Nakryiko 
test_uprobe_ref_ctr(struct test_attach_probe * skel)1957391ec63SMenglong Dong static void test_uprobe_ref_ctr(struct test_attach_probe *skel)
1967391ec63SMenglong Dong {
1977391ec63SMenglong Dong 	DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
1987391ec63SMenglong Dong 	struct bpf_link *uprobe_link, *uretprobe_link;
1997391ec63SMenglong Dong 	ssize_t uprobe_offset, ref_ctr_offset;
2007391ec63SMenglong Dong 
2017391ec63SMenglong Dong 	uprobe_offset = get_uprobe_offset(&trigger_func4);
2027391ec63SMenglong Dong 	if (!ASSERT_GE(uprobe_offset, 0, "uprobe_offset_ref_ctr"))
2037391ec63SMenglong Dong 		return;
2047391ec63SMenglong Dong 
2057391ec63SMenglong Dong 	ref_ctr_offset = get_rel_offset((uintptr_t)&uprobe_ref_ctr);
2067391ec63SMenglong Dong 	if (!ASSERT_GE(ref_ctr_offset, 0, "ref_ctr_offset"))
2077391ec63SMenglong Dong 		return;
2087391ec63SMenglong Dong 
2097391ec63SMenglong Dong 	ASSERT_EQ(uprobe_ref_ctr, 0, "uprobe_ref_ctr_before");
2107391ec63SMenglong Dong 
2117391ec63SMenglong Dong 	uprobe_opts.retprobe = false;
2127391ec63SMenglong Dong 	uprobe_opts.ref_ctr_offset = ref_ctr_offset;
2137391ec63SMenglong Dong 	uprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uprobe_ref_ctr,
2147391ec63SMenglong Dong 						      0 /* self pid */,
2157391ec63SMenglong Dong 						      "/proc/self/exe",
2167391ec63SMenglong Dong 						      uprobe_offset,
2177391ec63SMenglong Dong 						      &uprobe_opts);
2187391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(uprobe_link, "attach_uprobe_ref_ctr"))
2197391ec63SMenglong Dong 		return;
2207391ec63SMenglong Dong 	skel->links.handle_uprobe_ref_ctr = uprobe_link;
2217391ec63SMenglong Dong 
2227391ec63SMenglong Dong 	ASSERT_GT(uprobe_ref_ctr, 0, "uprobe_ref_ctr_after");
2237391ec63SMenglong Dong 
2247391ec63SMenglong Dong 	/* if uprobe uses ref_ctr, uretprobe has to use ref_ctr as well */
2257391ec63SMenglong Dong 	uprobe_opts.retprobe = true;
2267391ec63SMenglong Dong 	uprobe_opts.ref_ctr_offset = ref_ctr_offset;
2277391ec63SMenglong Dong 	uretprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uretprobe_ref_ctr,
2287391ec63SMenglong Dong 							 -1 /* any pid */,
2297391ec63SMenglong Dong 							 "/proc/self/exe",
2307391ec63SMenglong Dong 							 uprobe_offset, &uprobe_opts);
2317391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(uretprobe_link, "attach_uretprobe_ref_ctr"))
2327391ec63SMenglong Dong 		return;
2337391ec63SMenglong Dong 	skel->links.handle_uretprobe_ref_ctr = uretprobe_link;
2347391ec63SMenglong Dong }
2357391ec63SMenglong Dong 
test_kprobe_sleepable(void)2367391ec63SMenglong Dong static void test_kprobe_sleepable(void)
2377391ec63SMenglong Dong {
2387391ec63SMenglong Dong 	struct test_attach_kprobe_sleepable *skel;
2397391ec63SMenglong Dong 
2407391ec63SMenglong Dong 	skel = test_attach_kprobe_sleepable__open();
2417391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(skel, "skel_kprobe_sleepable_open"))
2427391ec63SMenglong Dong 		return;
2437391ec63SMenglong Dong 
2447391ec63SMenglong Dong 	/* sleepable kprobe test case needs flags set before loading */
2457391ec63SMenglong Dong 	if (!ASSERT_OK(bpf_program__set_flags(skel->progs.handle_kprobe_sleepable,
2467391ec63SMenglong Dong 		BPF_F_SLEEPABLE), "kprobe_sleepable_flags"))
2477391ec63SMenglong Dong 		goto cleanup;
2487391ec63SMenglong Dong 
2497391ec63SMenglong Dong 	if (!ASSERT_OK(test_attach_kprobe_sleepable__load(skel),
2507391ec63SMenglong Dong 		       "skel_kprobe_sleepable_load"))
2517391ec63SMenglong Dong 		goto cleanup;
2527391ec63SMenglong Dong 
2537391ec63SMenglong Dong 	/* sleepable kprobes should not attach successfully */
2547391ec63SMenglong Dong 	skel->links.handle_kprobe_sleepable = bpf_program__attach(skel->progs.handle_kprobe_sleepable);
2557391ec63SMenglong Dong 	ASSERT_ERR_PTR(skel->links.handle_kprobe_sleepable, "attach_kprobe_sleepable");
2567391ec63SMenglong Dong 
2577391ec63SMenglong Dong cleanup:
2587391ec63SMenglong Dong 	test_attach_kprobe_sleepable__destroy(skel);
2597391ec63SMenglong Dong }
2607391ec63SMenglong Dong 
test_uprobe_sleepable(struct test_attach_probe * skel)2617391ec63SMenglong Dong static void test_uprobe_sleepable(struct test_attach_probe *skel)
2627391ec63SMenglong Dong {
2637391ec63SMenglong Dong 	/* test sleepable uprobe and uretprobe variants */
2647391ec63SMenglong Dong 	skel->links.handle_uprobe_byname3_sleepable = bpf_program__attach(skel->progs.handle_uprobe_byname3_sleepable);
2657391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname3_sleepable, "attach_uprobe_byname3_sleepable"))
2667391ec63SMenglong Dong 		return;
2677391ec63SMenglong Dong 
2687391ec63SMenglong Dong 	skel->links.handle_uprobe_byname3 = bpf_program__attach(skel->progs.handle_uprobe_byname3);
2697391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname3, "attach_uprobe_byname3"))
2707391ec63SMenglong Dong 		return;
2717391ec63SMenglong Dong 
2727391ec63SMenglong Dong 	skel->links.handle_uretprobe_byname3_sleepable = bpf_program__attach(skel->progs.handle_uretprobe_byname3_sleepable);
2737391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname3_sleepable, "attach_uretprobe_byname3_sleepable"))
2747391ec63SMenglong Dong 		return;
2757391ec63SMenglong Dong 
2767391ec63SMenglong Dong 	skel->links.handle_uretprobe_byname3 = bpf_program__attach(skel->progs.handle_uretprobe_byname3);
2777391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname3, "attach_uretprobe_byname3"))
2787391ec63SMenglong Dong 		return;
2797391ec63SMenglong Dong 
2807391ec63SMenglong Dong 	skel->bss->user_ptr = test_data;
281ba7499bcSAlan Maguire 
282cb3f4a4aSDelyan Kratunov 	/* trigger & validate sleepable uprobe attached by name */
283cb3f4a4aSDelyan Kratunov 	trigger_func3();
284cb3f4a4aSDelyan Kratunov 
285cb3f4a4aSDelyan Kratunov 	ASSERT_EQ(skel->bss->uprobe_byname3_sleepable_res, 9, "check_uprobe_byname3_sleepable_res");
286cb3f4a4aSDelyan Kratunov 	ASSERT_EQ(skel->bss->uprobe_byname3_res, 10, "check_uprobe_byname3_res");
287cb3f4a4aSDelyan Kratunov 	ASSERT_EQ(skel->bss->uretprobe_byname3_sleepable_res, 11, "check_uretprobe_byname3_sleepable_res");
288cb3f4a4aSDelyan Kratunov 	ASSERT_EQ(skel->bss->uretprobe_byname3_res, 12, "check_uretprobe_byname3_res");
2897391ec63SMenglong Dong }
2907391ec63SMenglong Dong 
test_attach_probe(void)2917391ec63SMenglong Dong void test_attach_probe(void)
2927391ec63SMenglong Dong {
2937391ec63SMenglong Dong 	struct test_attach_probe *skel;
2947391ec63SMenglong Dong 
2957391ec63SMenglong Dong 	skel = test_attach_probe__open();
2967391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(skel, "skel_open"))
2977391ec63SMenglong Dong 		return;
2987391ec63SMenglong Dong 
2997391ec63SMenglong Dong 	if (!ASSERT_OK(test_attach_probe__load(skel), "skel_load"))
3007391ec63SMenglong Dong 		goto cleanup;
3017391ec63SMenglong Dong 	if (!ASSERT_OK_PTR(skel->bss, "check_bss"))
3027391ec63SMenglong Dong 		goto cleanup;
3037391ec63SMenglong Dong 
304*c7aec81bSMenglong Dong 	if (test__start_subtest("manual-default"))
305*c7aec81bSMenglong Dong 		test_attach_probe_manual(PROBE_ATTACH_MODE_DEFAULT);
306*c7aec81bSMenglong Dong 	if (test__start_subtest("manual-legacy"))
307*c7aec81bSMenglong Dong 		test_attach_probe_manual(PROBE_ATTACH_MODE_LEGACY);
308*c7aec81bSMenglong Dong 	if (test__start_subtest("manual-perf"))
309*c7aec81bSMenglong Dong 		test_attach_probe_manual(PROBE_ATTACH_MODE_PERF);
310*c7aec81bSMenglong Dong 	if (test__start_subtest("manual-link"))
311*c7aec81bSMenglong Dong 		test_attach_probe_manual(PROBE_ATTACH_MODE_LINK);
312*c7aec81bSMenglong Dong 
3137391ec63SMenglong Dong 	if (test__start_subtest("auto"))
3147391ec63SMenglong Dong 		test_attach_probe_auto(skel);
3157391ec63SMenglong Dong 	if (test__start_subtest("kprobe-sleepable"))
3167391ec63SMenglong Dong 		test_kprobe_sleepable();
3177391ec63SMenglong Dong 	if (test__start_subtest("uprobe-lib"))
3187391ec63SMenglong Dong 		test_uprobe_lib(skel);
3197391ec63SMenglong Dong 	if (test__start_subtest("uprobe-sleepable"))
3207391ec63SMenglong Dong 		test_uprobe_sleepable(skel);
3217391ec63SMenglong Dong 	if (test__start_subtest("uprobe-ref_ctr"))
3227391ec63SMenglong Dong 		test_uprobe_ref_ctr(skel);
3231e8611bbSAndrii Nakryiko 
3241e8611bbSAndrii Nakryiko cleanup:
325f3c926a4SAndrii Nakryiko 	test_attach_probe__destroy(skel);
3264bd11e08SAndrii Nakryiko 	ASSERT_EQ(uprobe_ref_ctr, 0, "uprobe_ref_ctr_cleanup");
3271e8611bbSAndrii Nakryiko }
328