• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  *    AUTHOR		: William Roske
5  *    CO-PILOT		: Dave Fenner
6  */
7 /*\
8  * [Description]
9  *
10  * For a terminated child, test whether wait(2) can get its pid
11  * and exit status correctly.
12  */
13 
14 #include <errno.h>
15 #include <sys/types.h>
16 #include <sys/wait.h>
17 #include <stdlib.h>
18 #include "tst_test.h"
19 
verify_wait(void)20 static void verify_wait(void)
21 {
22 	int status, exit_child = 1;
23 	pid_t fpid;
24 
25 	fpid = SAFE_FORK();
26 	if (fpid == 0)
27 		exit(exit_child);
28 
29 	TST_EXP_PID_SILENT(wait(&status));
30 
31 	if (!TST_PASS)
32 		return;
33 
34 	if (fpid != TST_RET) {
35 		tst_res(TFAIL, "wait() returned pid %ld, expected %d",
36 			TST_RET, fpid);
37 		return;
38 	}
39 
40 	if (WIFEXITED(status) && WEXITSTATUS(status) == exit_child) {
41 		tst_res(TPASS, "wait() succeeded");
42 		return;
43 	}
44 
45 	tst_res(TFAIL, "wait() reported child %s", tst_strstatus(status));
46 }
47 
48 static struct tst_test test = {
49 	.test_all = verify_wait,
50 	.forks_child = 1,
51 };
52