@@ -114,7 +114,8 @@ static int call_clone3_set_tid(pid_t *set_tid,
114
114
return WEXITSTATUS (status );
115
115
}
116
116
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 ,
118
119
size_t set_tid_size ,
119
120
int flags ,
120
121
int expected ,
@@ -129,17 +130,13 @@ static void test_clone3_set_tid(pid_t *set_tid,
129
130
ret = call_clone3_set_tid (set_tid , set_tid_size , flags , expected_pid ,
130
131
wait_for_it );
131
132
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" ,
133
134
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 );
142
138
}
139
+
143
140
int main (int argc , char * argv [])
144
141
{
145
142
FILE * f ;
@@ -172,73 +169,91 @@ int main(int argc, char *argv[])
172
169
173
170
/* Try invalid settings */
174
171
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 );
176
174
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 );
178
177
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 );
181
181
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 );
183
184
184
185
/*
185
186
* This can actually work if this test running in a MAX_PID_NS_LEVEL - 1
186
187
* nested PID namespace.
187
188
*/
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 );
189
191
190
192
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 );
192
195
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 );
194
198
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 );
197
202
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 );
199
205
200
206
/*
201
207
* This can actually work if this test running in a MAX_PID_NS_LEVEL - 1
202
208
* nested PID namespace.
203
209
*/
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 );
205
212
206
213
memset (& set_tid , 0 , sizeof (set_tid ));
207
214
/* Try with an invalid PID */
208
215
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 );
210
218
211
219
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 );
213
222
214
223
/* 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 );
216
226
217
227
/* Try it in a new PID namespace */
218
228
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 );
220
231
else
221
232
ksft_test_result_skip ("Clone3() with set_tid requires root\n" );
222
233
223
234
/* Try with a valid PID (1) this should return -EEXIST. */
224
235
set_tid [0 ] = 1 ;
225
236
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 );
227
239
else
228
240
ksft_test_result_skip ("Clone3() with set_tid requires root\n" );
229
241
230
242
/* Try it in a new PID namespace */
231
243
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 );
233
246
else
234
247
ksft_test_result_skip ("Clone3() with set_tid requires root\n" );
235
248
236
249
/* pid_max should fail everywhere */
237
250
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 );
239
253
240
254
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 );
242
257
else
243
258
ksft_test_result_skip ("Clone3() with set_tid requires root\n" );
244
259
@@ -262,10 +277,12 @@ int main(int argc, char *argv[])
262
277
263
278
/* After the child has finished, its PID should be free. */
264
279
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 );
266
282
267
283
/* 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 );
269
286
270
287
/*
271
288
* Creating a process with PID 1 in the newly created most nested
@@ -274,7 +291,8 @@ int main(int argc, char *argv[])
274
291
*/
275
292
set_tid [0 ] = 1 ;
276
293
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 );
278
296
279
297
ksft_print_msg ("unshare PID namespace\n" );
280
298
if (unshare (CLONE_NEWPID ) == -1 )
@@ -284,7 +302,8 @@ int main(int argc, char *argv[])
284
302
set_tid [0 ] = pid ;
285
303
286
304
/* 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 );
288
307
289
308
/* Let's create a PID 1 */
290
309
ns_pid = fork ();
@@ -295,21 +314,25 @@ int main(int argc, char *argv[])
295
314
*/
296
315
set_tid [0 ] = 43 ;
297
316
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 );
299
319
300
320
set_tid [0 ] = 43 ;
301
321
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 );
303
324
304
325
ksft_print_msg ("Child in PID namespace has PID %d\n" , getpid ());
305
326
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 );
307
329
308
330
set_tid [0 ] = 1 ;
309
331
set_tid [1 ] = -1 ;
310
332
set_tid [2 ] = pid ;
311
333
/* 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 );
313
336
314
337
set_tid [0 ] = 1 ;
315
338
set_tid [1 ] = 42 ;
@@ -319,13 +342,15 @@ int main(int argc, char *argv[])
319
342
* namespaces. Again assuming this is running in the host's
320
343
* PID namespace. Not yet nested.
321
344
*/
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 );
323
347
324
348
/*
325
349
* This should work and from the parent we should see
326
350
* something like 'NSpid: pid 42 1'.
327
351
*/
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);
329
354
330
355
child_exit (ksft_cnt .ksft_fail );
331
356
}
@@ -380,16 +405,14 @@ int main(int argc, char *argv[])
380
405
ksft_cnt .ksft_pass += 6 - (ksft_cnt .ksft_fail - WEXITSTATUS (status ));
381
406
ksft_cnt .ksft_fail = WEXITSTATUS (status );
382
407
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" );
391
412
out :
392
413
ret = 0 ;
393
414
394
- return !ret ? ksft_exit_pass () : ksft_exit_fail ();
415
+ if (ret )
416
+ ksft_exit_fail ();
417
+ ksft_exit_pass ();
395
418
}
0 commit comments