77static void test_add (struct atomics_lskel * skel )
88{
99 int err , prog_fd ;
10- int link_fd ;
1110 LIBBPF_OPTS (bpf_test_run_opts , topts );
1211
13- link_fd = atomics_lskel__add__attach (skel );
14- if (!ASSERT_GT (link_fd , 0 , "attach(add)" ))
15- return ;
16-
12+ /* No need to attach it, just run it directly */
1713 prog_fd = skel -> progs .add .prog_fd ;
1814 err = bpf_prog_test_run_opts (prog_fd , & topts );
1915 if (!ASSERT_OK (err , "test_run_opts err" ))
20- goto cleanup ;
16+ return ;
2117 if (!ASSERT_OK (topts .retval , "test_run_opts retval" ))
22- goto cleanup ;
18+ return ;
2319
2420 ASSERT_EQ (skel -> data -> add64_value , 3 , "add64_value" );
2521 ASSERT_EQ (skel -> bss -> add64_result , 1 , "add64_result" );
@@ -31,27 +27,20 @@ static void test_add(struct atomics_lskel *skel)
3127 ASSERT_EQ (skel -> bss -> add_stack_result , 1 , "add_stack_result" );
3228
3329 ASSERT_EQ (skel -> data -> add_noreturn_value , 3 , "add_noreturn_value" );
34-
35- cleanup :
36- close (link_fd );
3730}
3831
3932static void test_sub (struct atomics_lskel * skel )
4033{
4134 int err , prog_fd ;
42- int link_fd ;
4335 LIBBPF_OPTS (bpf_test_run_opts , topts );
4436
45- link_fd = atomics_lskel__sub__attach (skel );
46- if (!ASSERT_GT (link_fd , 0 , "attach(sub)" ))
47- return ;
48-
37+ /* No need to attach it, just run it directly */
4938 prog_fd = skel -> progs .sub .prog_fd ;
5039 err = bpf_prog_test_run_opts (prog_fd , & topts );
5140 if (!ASSERT_OK (err , "test_run_opts err" ))
52- goto cleanup ;
41+ return ;
5342 if (!ASSERT_OK (topts .retval , "test_run_opts retval" ))
54- goto cleanup ;
43+ return ;
5544
5645 ASSERT_EQ (skel -> data -> sub64_value , -1 , "sub64_value" );
5746 ASSERT_EQ (skel -> bss -> sub64_result , 1 , "sub64_result" );
@@ -63,27 +52,20 @@ static void test_sub(struct atomics_lskel *skel)
6352 ASSERT_EQ (skel -> bss -> sub_stack_result , 1 , "sub_stack_result" );
6453
6554 ASSERT_EQ (skel -> data -> sub_noreturn_value , -1 , "sub_noreturn_value" );
66-
67- cleanup :
68- close (link_fd );
6955}
7056
7157static void test_and (struct atomics_lskel * skel )
7258{
7359 int err , prog_fd ;
74- int link_fd ;
7560 LIBBPF_OPTS (bpf_test_run_opts , topts );
7661
77- link_fd = atomics_lskel__and__attach (skel );
78- if (!ASSERT_GT (link_fd , 0 , "attach(and)" ))
79- return ;
80-
62+ /* No need to attach it, just run it directly */
8163 prog_fd = skel -> progs .and .prog_fd ;
8264 err = bpf_prog_test_run_opts (prog_fd , & topts );
8365 if (!ASSERT_OK (err , "test_run_opts err" ))
84- goto cleanup ;
66+ return ;
8567 if (!ASSERT_OK (topts .retval , "test_run_opts retval" ))
86- goto cleanup ;
68+ return ;
8769
8870 ASSERT_EQ (skel -> data -> and64_value , 0x010ull << 32 , "and64_value" );
8971 ASSERT_EQ (skel -> bss -> and64_result , 0x110ull << 32 , "and64_result" );
@@ -92,26 +74,20 @@ static void test_and(struct atomics_lskel *skel)
9274 ASSERT_EQ (skel -> bss -> and32_result , 0x110 , "and32_result" );
9375
9476 ASSERT_EQ (skel -> data -> and_noreturn_value , 0x010ull << 32 , "and_noreturn_value" );
95- cleanup :
96- close (link_fd );
9777}
9878
9979static void test_or (struct atomics_lskel * skel )
10080{
10181 int err , prog_fd ;
102- int link_fd ;
10382 LIBBPF_OPTS (bpf_test_run_opts , topts );
10483
105- link_fd = atomics_lskel__or__attach (skel );
106- if (!ASSERT_GT (link_fd , 0 , "attach(or)" ))
107- return ;
108-
84+ /* No need to attach it, just run it directly */
10985 prog_fd = skel -> progs .or .prog_fd ;
11086 err = bpf_prog_test_run_opts (prog_fd , & topts );
11187 if (!ASSERT_OK (err , "test_run_opts err" ))
112- goto cleanup ;
88+ return ;
11389 if (!ASSERT_OK (topts .retval , "test_run_opts retval" ))
114- goto cleanup ;
90+ return ;
11591
11692 ASSERT_EQ (skel -> data -> or64_value , 0x111ull << 32 , "or64_value" );
11793 ASSERT_EQ (skel -> bss -> or64_result , 0x110ull << 32 , "or64_result" );
@@ -120,26 +96,20 @@ static void test_or(struct atomics_lskel *skel)
12096 ASSERT_EQ (skel -> bss -> or32_result , 0x110 , "or32_result" );
12197
12298 ASSERT_EQ (skel -> data -> or_noreturn_value , 0x111ull << 32 , "or_noreturn_value" );
123- cleanup :
124- close (link_fd );
12599}
126100
127101static void test_xor (struct atomics_lskel * skel )
128102{
129103 int err , prog_fd ;
130- int link_fd ;
131104 LIBBPF_OPTS (bpf_test_run_opts , topts );
132105
133- link_fd = atomics_lskel__xor__attach (skel );
134- if (!ASSERT_GT (link_fd , 0 , "attach(xor)" ))
135- return ;
136-
106+ /* No need to attach it, just run it directly */
137107 prog_fd = skel -> progs .xor .prog_fd ;
138108 err = bpf_prog_test_run_opts (prog_fd , & topts );
139109 if (!ASSERT_OK (err , "test_run_opts err" ))
140- goto cleanup ;
110+ return ;
141111 if (!ASSERT_OK (topts .retval , "test_run_opts retval" ))
142- goto cleanup ;
112+ return ;
143113
144114 ASSERT_EQ (skel -> data -> xor64_value , 0x101ull << 32 , "xor64_value" );
145115 ASSERT_EQ (skel -> bss -> xor64_result , 0x110ull << 32 , "xor64_result" );
@@ -148,26 +118,20 @@ static void test_xor(struct atomics_lskel *skel)
148118 ASSERT_EQ (skel -> bss -> xor32_result , 0x110 , "xor32_result" );
149119
150120 ASSERT_EQ (skel -> data -> xor_noreturn_value , 0x101ull << 32 , "xor_nxoreturn_value" );
151- cleanup :
152- close (link_fd );
153121}
154122
155123static void test_cmpxchg (struct atomics_lskel * skel )
156124{
157125 int err , prog_fd ;
158- int link_fd ;
159126 LIBBPF_OPTS (bpf_test_run_opts , topts );
160127
161- link_fd = atomics_lskel__cmpxchg__attach (skel );
162- if (!ASSERT_GT (link_fd , 0 , "attach(cmpxchg)" ))
163- return ;
164-
128+ /* No need to attach it, just run it directly */
165129 prog_fd = skel -> progs .cmpxchg .prog_fd ;
166130 err = bpf_prog_test_run_opts (prog_fd , & topts );
167131 if (!ASSERT_OK (err , "test_run_opts err" ))
168- goto cleanup ;
132+ return ;
169133 if (!ASSERT_OK (topts .retval , "test_run_opts retval" ))
170- goto cleanup ;
134+ return ;
171135
172136 ASSERT_EQ (skel -> data -> cmpxchg64_value , 2 , "cmpxchg64_value" );
173137 ASSERT_EQ (skel -> bss -> cmpxchg64_result_fail , 1 , "cmpxchg_result_fail" );
@@ -176,45 +140,34 @@ static void test_cmpxchg(struct atomics_lskel *skel)
176140 ASSERT_EQ (skel -> data -> cmpxchg32_value , 2 , "lcmpxchg32_value" );
177141 ASSERT_EQ (skel -> bss -> cmpxchg32_result_fail , 1 , "cmpxchg_result_fail" );
178142 ASSERT_EQ (skel -> bss -> cmpxchg32_result_succeed , 1 , "cmpxchg_result_succeed" );
179-
180- cleanup :
181- close (link_fd );
182143}
183144
184145static void test_xchg (struct atomics_lskel * skel )
185146{
186147 int err , prog_fd ;
187- int link_fd ;
188148 LIBBPF_OPTS (bpf_test_run_opts , topts );
189149
190- link_fd = atomics_lskel__xchg__attach (skel );
191- if (!ASSERT_GT (link_fd , 0 , "attach(xchg)" ))
192- return ;
193-
150+ /* No need to attach it, just run it directly */
194151 prog_fd = skel -> progs .xchg .prog_fd ;
195152 err = bpf_prog_test_run_opts (prog_fd , & topts );
196153 if (!ASSERT_OK (err , "test_run_opts err" ))
197- goto cleanup ;
154+ return ;
198155 if (!ASSERT_OK (topts .retval , "test_run_opts retval" ))
199- goto cleanup ;
156+ return ;
200157
201158 ASSERT_EQ (skel -> data -> xchg64_value , 2 , "xchg64_value" );
202159 ASSERT_EQ (skel -> bss -> xchg64_result , 1 , "xchg64_result" );
203160
204161 ASSERT_EQ (skel -> data -> xchg32_value , 2 , "xchg32_value" );
205162 ASSERT_EQ (skel -> bss -> xchg32_result , 1 , "xchg32_result" );
206-
207- cleanup :
208- close (link_fd );
209163}
210164
211165void test_atomics (void )
212166{
213167 struct atomics_lskel * skel ;
214- __u32 duration = 0 ;
215168
216169 skel = atomics_lskel__open_and_load ();
217- if (CHECK (! skel , "skel_load" , " atomics skeleton failed\n " ))
170+ if (! ASSERT_OK_PTR ( skel , "atomics skeleton load " ))
218171 return ;
219172
220173 if (skel -> data -> skip_tests ) {
0 commit comments