xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/waitid/waitid01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Crackerjack Project., 2007
4  * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
5  */
6 
7 /*\
8  * [Description]
9  *
10  * This test is checking if waitid() syscall does wait for WEXITED and check for
11  * the return value.
12  */
13 
14 #include <stdlib.h>
15 #include <sys/wait.h>
16 #include "tst_test.h"
17 
18 static siginfo_t *infop;
19 
run(void)20 static void run(void)
21 {
22 	pid_t pidchild;
23 
24 	pidchild = SAFE_FORK();
25 	if (!pidchild)
26 		exit(123);
27 
28 	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
29 	TST_EXP_EQ_LI(infop->si_pid, pidchild);
30 	TST_EXP_EQ_LI(infop->si_status, 123);
31 	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
32 	TST_EXP_EQ_LI(infop->si_code, CLD_EXITED);
33 }
34 
35 static struct tst_test test = {
36 	.test_all = run,
37 	.forks_child = 1,
38 	.bufs = (struct tst_buffers[]) {
39 		{&infop, .size = sizeof(*infop)},
40 		{},
41 	},
42 };
43