@@ -114,7 +114,8 @@ static int call_clone3_set_tid(pid_t *set_tid,
114114 return WEXITSTATUS (status );
115115}
116116
117- static void test_clone3_set_tid (pid_t * set_tid ,
117+ static void test_clone3_set_tid (const char * desc ,
118+ pid_t * set_tid ,
118119 size_t set_tid_size ,
119120 int flags ,
120121 int expected ,
@@ -129,17 +130,13 @@ static void test_clone3_set_tid(pid_t *set_tid,
129130 ret = call_clone3_set_tid (set_tid , set_tid_size , flags , expected_pid ,
130131 wait_for_it );
131132 ksft_print_msg (
132- "[%d] clone3() with CLONE_SET_TID %d says : %d - expected %d\n" ,
133+ "[%d] clone3() with CLONE_SET_TID %d says: %d - expected %d\n" ,
133134 getpid (), set_tid [0 ], ret , expected );
134- if (ret != expected )
135- ksft_test_result_fail (
136- "[%d] Result (%d) is different than expected (%d)\n" ,
137- getpid (), ret , expected );
138- else
139- ksft_test_result_pass (
140- "[%d] Result (%d) matches expectation (%d)\n" ,
141- getpid (), ret , expected );
135+
136+ ksft_test_result (ret == expected , "%s with %zu TIDs and flags 0x%x\n" ,
137+ desc , set_tid_size , flags );
142138}
139+
143140int main (int argc , char * argv [])
144141{
145142 FILE * f ;
@@ -172,73 +169,91 @@ int main(int argc, char *argv[])
172169
173170 /* Try invalid settings */
174171 memset (& set_tid , 0 , sizeof (set_tid ));
175- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL + 1 , 0 , - EINVAL , 0 , 0 );
172+ test_clone3_set_tid ("invalid size, 0 TID" ,
173+ set_tid , MAX_PID_NS_LEVEL + 1 , 0 , - EINVAL , 0 , 0 );
176174
177- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL * 2 , 0 , - EINVAL , 0 , 0 );
175+ test_clone3_set_tid ("invalid size, 0 TID" ,
176+ set_tid , MAX_PID_NS_LEVEL * 2 , 0 , - EINVAL , 0 , 0 );
178177
179- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL * 2 + 1 , 0 ,
180- - EINVAL , 0 , 0 );
178+ test_clone3_set_tid ("invalid size, 0 TID" ,
179+ set_tid , MAX_PID_NS_LEVEL * 2 + 1 , 0 ,
180+ - EINVAL , 0 , 0 );
181181
182- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL * 42 , 0 , - EINVAL , 0 , 0 );
182+ test_clone3_set_tid ("invalid size, 0 TID" ,
183+ set_tid , MAX_PID_NS_LEVEL * 42 , 0 , - EINVAL , 0 , 0 );
183184
184185 /*
185186 * This can actually work if this test running in a MAX_PID_NS_LEVEL - 1
186187 * nested PID namespace.
187188 */
188- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL - 1 , 0 , - EINVAL , 0 , 0 );
189+ test_clone3_set_tid ("invalid size, 0 TID" ,
190+ set_tid , MAX_PID_NS_LEVEL - 1 , 0 , - EINVAL , 0 , 0 );
189191
190192 memset (& set_tid , 0xff , sizeof (set_tid ));
191- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL + 1 , 0 , - EINVAL , 0 , 0 );
193+ test_clone3_set_tid ("invalid size, TID all 1s" ,
194+ set_tid , MAX_PID_NS_LEVEL + 1 , 0 , - EINVAL , 0 , 0 );
192195
193- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL * 2 , 0 , - EINVAL , 0 , 0 );
196+ test_clone3_set_tid ("invalid size, TID all 1s" ,
197+ set_tid , MAX_PID_NS_LEVEL * 2 , 0 , - EINVAL , 0 , 0 );
194198
195- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL * 2 + 1 , 0 ,
196- - EINVAL , 0 , 0 );
199+ test_clone3_set_tid ("invalid size, TID all 1s" ,
200+ set_tid , MAX_PID_NS_LEVEL * 2 + 1 , 0 ,
201+ - EINVAL , 0 , 0 );
197202
198- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL * 42 , 0 , - EINVAL , 0 , 0 );
203+ test_clone3_set_tid ("invalid size, TID all 1s" ,
204+ set_tid , MAX_PID_NS_LEVEL * 42 , 0 , - EINVAL , 0 , 0 );
199205
200206 /*
201207 * This can actually work if this test running in a MAX_PID_NS_LEVEL - 1
202208 * nested PID namespace.
203209 */
204- test_clone3_set_tid (set_tid , MAX_PID_NS_LEVEL - 1 , 0 , - EINVAL , 0 , 0 );
210+ test_clone3_set_tid ("invalid size, TID all 1s" ,
211+ set_tid , MAX_PID_NS_LEVEL - 1 , 0 , - EINVAL , 0 , 0 );
205212
206213 memset (& set_tid , 0 , sizeof (set_tid ));
207214 /* Try with an invalid PID */
208215 set_tid [0 ] = 0 ;
209- test_clone3_set_tid (set_tid , 1 , 0 , - EINVAL , 0 , 0 );
216+ test_clone3_set_tid ("valid size, 0 TID" ,
217+ set_tid , 1 , 0 , - EINVAL , 0 , 0 );
210218
211219 set_tid [0 ] = -1 ;
212- test_clone3_set_tid (set_tid , 1 , 0 , - EINVAL , 0 , 0 );
220+ test_clone3_set_tid ("valid size, -1 TID" ,
221+ set_tid , 1 , 0 , - EINVAL , 0 , 0 );
213222
214223 /* Claim that the set_tid array actually contains 2 elements. */
215- test_clone3_set_tid (set_tid , 2 , 0 , - EINVAL , 0 , 0 );
224+ test_clone3_set_tid ("2 TIDs, -1 and 0" ,
225+ set_tid , 2 , 0 , - EINVAL , 0 , 0 );
216226
217227 /* Try it in a new PID namespace */
218228 if (uid == 0 )
219- test_clone3_set_tid (set_tid , 1 , CLONE_NEWPID , - EINVAL , 0 , 0 );
229+ test_clone3_set_tid ("valid size, -1 TID" ,
230+ set_tid , 1 , CLONE_NEWPID , - EINVAL , 0 , 0 );
220231 else
221232 ksft_test_result_skip ("Clone3() with set_tid requires root\n" );
222233
223234 /* Try with a valid PID (1) this should return -EEXIST. */
224235 set_tid [0 ] = 1 ;
225236 if (uid == 0 )
226- test_clone3_set_tid (set_tid , 1 , 0 , - EEXIST , 0 , 0 );
237+ test_clone3_set_tid ("duplicate PID 1" ,
238+ set_tid , 1 , 0 , - EEXIST , 0 , 0 );
227239 else
228240 ksft_test_result_skip ("Clone3() with set_tid requires root\n" );
229241
230242 /* Try it in a new PID namespace */
231243 if (uid == 0 )
232- test_clone3_set_tid (set_tid , 1 , CLONE_NEWPID , 0 , 0 , 0 );
244+ test_clone3_set_tid ("duplicate PID 1" ,
245+ set_tid , 1 , CLONE_NEWPID , 0 , 0 , 0 );
233246 else
234247 ksft_test_result_skip ("Clone3() with set_tid requires root\n" );
235248
236249 /* pid_max should fail everywhere */
237250 set_tid [0 ] = pid_max ;
238- test_clone3_set_tid (set_tid , 1 , 0 , - EINVAL , 0 , 0 );
251+ test_clone3_set_tid ("set TID to maximum" ,
252+ set_tid , 1 , 0 , - EINVAL , 0 , 0 );
239253
240254 if (uid == 0 )
241- test_clone3_set_tid (set_tid , 1 , CLONE_NEWPID , - EINVAL , 0 , 0 );
255+ test_clone3_set_tid ("set TID to maximum" ,
256+ set_tid , 1 , CLONE_NEWPID , - EINVAL , 0 , 0 );
242257 else
243258 ksft_test_result_skip ("Clone3() with set_tid requires root\n" );
244259
@@ -262,10 +277,12 @@ int main(int argc, char *argv[])
262277
263278 /* After the child has finished, its PID should be free. */
264279 set_tid [0 ] = pid ;
265- test_clone3_set_tid (set_tid , 1 , 0 , 0 , 0 , 0 );
280+ test_clone3_set_tid ("reallocate child TID" ,
281+ set_tid , 1 , 0 , 0 , 0 , 0 );
266282
267283 /* This should fail as there is no PID 1 in that namespace */
268- test_clone3_set_tid (set_tid , 1 , CLONE_NEWPID , - EINVAL , 0 , 0 );
284+ test_clone3_set_tid ("duplicate child TID" ,
285+ set_tid , 1 , CLONE_NEWPID , - EINVAL , 0 , 0 );
269286
270287 /*
271288 * Creating a process with PID 1 in the newly created most nested
@@ -274,7 +291,8 @@ int main(int argc, char *argv[])
274291 */
275292 set_tid [0 ] = 1 ;
276293 set_tid [1 ] = pid ;
277- test_clone3_set_tid (set_tid , 2 , CLONE_NEWPID , 0 , pid , 0 );
294+ test_clone3_set_tid ("create PID 1 in new NS" ,
295+ set_tid , 2 , CLONE_NEWPID , 0 , pid , 0 );
278296
279297 ksft_print_msg ("unshare PID namespace\n" );
280298 if (unshare (CLONE_NEWPID ) == -1 )
@@ -284,7 +302,8 @@ int main(int argc, char *argv[])
284302 set_tid [0 ] = pid ;
285303
286304 /* This should fail as there is no PID 1 in that namespace */
287- test_clone3_set_tid (set_tid , 1 , 0 , - EINVAL , 0 , 0 );
305+ test_clone3_set_tid ("duplicate PID 1" ,
306+ set_tid , 1 , 0 , - EINVAL , 0 , 0 );
288307
289308 /* Let's create a PID 1 */
290309 ns_pid = fork ();
@@ -295,21 +314,25 @@ int main(int argc, char *argv[])
295314 */
296315 set_tid [0 ] = 43 ;
297316 set_tid [1 ] = -1 ;
298- test_clone3_set_tid (set_tid , 2 , 0 , - EINVAL , 0 , 0 );
317+ test_clone3_set_tid ("check leak on invalid TID -1" ,
318+ set_tid , 2 , 0 , - EINVAL , 0 , 0 );
299319
300320 set_tid [0 ] = 43 ;
301321 set_tid [1 ] = pid ;
302- test_clone3_set_tid (set_tid , 2 , 0 , 0 , 43 , 0 );
322+ test_clone3_set_tid ("check leak on invalid specific TID" ,
323+ set_tid , 2 , 0 , 0 , 43 , 0 );
303324
304325 ksft_print_msg ("Child in PID namespace has PID %d\n" , getpid ());
305326 set_tid [0 ] = 2 ;
306- test_clone3_set_tid (set_tid , 1 , 0 , 0 , 2 , 0 );
327+ test_clone3_set_tid ("create PID 2 in child NS" ,
328+ set_tid , 1 , 0 , 0 , 2 , 0 );
307329
308330 set_tid [0 ] = 1 ;
309331 set_tid [1 ] = -1 ;
310332 set_tid [2 ] = pid ;
311333 /* This should fail as there is invalid PID at level '1'. */
312- test_clone3_set_tid (set_tid , 3 , CLONE_NEWPID , - EINVAL , 0 , 0 );
334+ test_clone3_set_tid ("fail due to invalid TID at level 1" ,
335+ set_tid , 3 , CLONE_NEWPID , - EINVAL , 0 , 0 );
313336
314337 set_tid [0 ] = 1 ;
315338 set_tid [1 ] = 42 ;
@@ -319,13 +342,15 @@ int main(int argc, char *argv[])
319342 * namespaces. Again assuming this is running in the host's
320343 * PID namespace. Not yet nested.
321344 */
322- test_clone3_set_tid (set_tid , 4 , CLONE_NEWPID , - EINVAL , 0 , 0 );
345+ test_clone3_set_tid ("fail due to too few active PID NSs" ,
346+ set_tid , 4 , CLONE_NEWPID , - EINVAL , 0 , 0 );
323347
324348 /*
325349 * This should work and from the parent we should see
326350 * something like 'NSpid: pid 42 1'.
327351 */
328- test_clone3_set_tid (set_tid , 3 , CLONE_NEWPID , 0 , 42 , true);
352+ test_clone3_set_tid ("verify that we have 3 PID NSs" ,
353+ set_tid , 3 , CLONE_NEWPID , 0 , 42 , true);
329354
330355 child_exit (ksft_cnt .ksft_fail );
331356 }
@@ -380,16 +405,14 @@ int main(int argc, char *argv[])
380405 ksft_cnt .ksft_pass += 6 - (ksft_cnt .ksft_fail - WEXITSTATUS (status ));
381406 ksft_cnt .ksft_fail = WEXITSTATUS (status );
382407
383- if (ns3 == pid && ns2 == 42 && ns1 == 1 )
384- ksft_test_result_pass (
385- "PIDs in all namespaces as expected (%d,%d,%d)\n" ,
386- ns3 , ns2 , ns1 );
387- else
388- ksft_test_result_fail (
389- "PIDs in all namespaces not as expected (%d,%d,%d)\n" ,
390- ns3 , ns2 , ns1 );
408+ ksft_print_msg ("Expecting PIDs %d, 42, 1\n" , pid );
409+ ksft_print_msg ("Have PIDs in namespaces: %d, %d, %d\n" , ns3 , ns2 , ns1 );
410+ ksft_test_result (ns3 == pid && ns2 == 42 && ns1 == 1 ,
411+ "PIDs in all namespaces as expected\n" );
391412out :
392413 ret = 0 ;
393414
394- return !ret ? ksft_exit_pass () : ksft_exit_fail ();
415+ if (ret )
416+ ksft_exit_fail ();
417+ ksft_exit_pass ();
395418}
0 commit comments