33#include <unistd.h>
44#include <test_progs.h>
55#include "uprobe_multi.skel.h"
6+ #include "bpf/libbpf_internal.h"
67
78static char test_data [] = "test_data" ;
89
@@ -130,6 +131,72 @@ static void test_attach_api_syms(void)
130131 test_attach_api ("/proc/self/exe" , NULL , & opts );
131132}
132133
134+ static void test_link_api (void )
135+ {
136+ int prog_fd , link1_fd = -1 , link2_fd = -1 , link3_fd = -1 , link4_fd = -1 ;
137+ LIBBPF_OPTS (bpf_link_create_opts , opts );
138+ const char * path = "/proc/self/exe" ;
139+ struct uprobe_multi * skel = NULL ;
140+ unsigned long * offsets = NULL ;
141+ const char * syms [3 ] = {
142+ "uprobe_multi_func_1" ,
143+ "uprobe_multi_func_2" ,
144+ "uprobe_multi_func_3" ,
145+ };
146+ int err ;
147+
148+ err = elf_resolve_syms_offsets (path , 3 , syms , (unsigned long * * ) & offsets );
149+ if (!ASSERT_OK (err , "elf_resolve_syms_offsets" ))
150+ return ;
151+
152+ opts .uprobe_multi .path = path ;
153+ opts .uprobe_multi .offsets = offsets ;
154+ opts .uprobe_multi .cnt = ARRAY_SIZE (syms );
155+
156+ skel = uprobe_multi__open_and_load ();
157+ if (!ASSERT_OK_PTR (skel , "uprobe_multi__open_and_load" ))
158+ goto cleanup ;
159+
160+ opts .kprobe_multi .flags = 0 ;
161+ prog_fd = bpf_program__fd (skel -> progs .uprobe );
162+ link1_fd = bpf_link_create (prog_fd , 0 , BPF_TRACE_UPROBE_MULTI , & opts );
163+ if (!ASSERT_GE (link1_fd , 0 , "link1_fd" ))
164+ goto cleanup ;
165+
166+ opts .kprobe_multi .flags = BPF_F_UPROBE_MULTI_RETURN ;
167+ prog_fd = bpf_program__fd (skel -> progs .uretprobe );
168+ link2_fd = bpf_link_create (prog_fd , 0 , BPF_TRACE_UPROBE_MULTI , & opts );
169+ if (!ASSERT_GE (link2_fd , 0 , "link2_fd" ))
170+ goto cleanup ;
171+
172+ opts .kprobe_multi .flags = 0 ;
173+ prog_fd = bpf_program__fd (skel -> progs .uprobe_sleep );
174+ link3_fd = bpf_link_create (prog_fd , 0 , BPF_TRACE_UPROBE_MULTI , & opts );
175+ if (!ASSERT_GE (link3_fd , 0 , "link3_fd" ))
176+ goto cleanup ;
177+
178+ opts .kprobe_multi .flags = BPF_F_UPROBE_MULTI_RETURN ;
179+ prog_fd = bpf_program__fd (skel -> progs .uretprobe_sleep );
180+ link4_fd = bpf_link_create (prog_fd , 0 , BPF_TRACE_UPROBE_MULTI , & opts );
181+ if (!ASSERT_GE (link4_fd , 0 , "link4_fd" ))
182+ goto cleanup ;
183+
184+ uprobe_multi_test_run (skel );
185+
186+ cleanup :
187+ if (link1_fd >= 0 )
188+ close (link1_fd );
189+ if (link2_fd >= 0 )
190+ close (link2_fd );
191+ if (link3_fd >= 0 )
192+ close (link3_fd );
193+ if (link4_fd >= 0 )
194+ close (link4_fd );
195+
196+ uprobe_multi__destroy (skel );
197+ free (offsets );
198+ }
199+
133200void test_uprobe_multi_test (void )
134201{
135202 if (test__start_subtest ("skel_api" ))
@@ -138,4 +205,6 @@ void test_uprobe_multi_test(void)
138205 test_attach_api_pattern ();
139206 if (test__start_subtest ("attach_api_syms" ))
140207 test_attach_api_syms ();
208+ if (test__start_subtest ("link_api" ))
209+ test_link_api ();
141210}
0 commit comments