xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/waitid/waitid08.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Crackerjack Project., 2007
4*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Manas Kumar Nayak [email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
6*49cdfc7eSAndroid Build Coastguard Worker  */
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker /*\
9*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
10*49cdfc7eSAndroid Build Coastguard Worker  *
11*49cdfc7eSAndroid Build Coastguard Worker  * Test if waitid() filters children killed with SIGCONT.
12*49cdfc7eSAndroid Build Coastguard Worker  */
13*49cdfc7eSAndroid Build Coastguard Worker 
14*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
16*49cdfc7eSAndroid Build Coastguard Worker 
17*49cdfc7eSAndroid Build Coastguard Worker static siginfo_t *infop;
18*49cdfc7eSAndroid Build Coastguard Worker 
run(void)19*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
20*49cdfc7eSAndroid Build Coastguard Worker {
21*49cdfc7eSAndroid Build Coastguard Worker 	pid_t pid_child;
22*49cdfc7eSAndroid Build Coastguard Worker 
23*49cdfc7eSAndroid Build Coastguard Worker 	pid_child = SAFE_FORK();
24*49cdfc7eSAndroid Build Coastguard Worker 	if (!pid_child) {
25*49cdfc7eSAndroid Build Coastguard Worker 		SAFE_KILL(getpid(), SIGSTOP);
26*49cdfc7eSAndroid Build Coastguard Worker 		TST_CHECKPOINT_WAIT(0);
27*49cdfc7eSAndroid Build Coastguard Worker 		return;
28*49cdfc7eSAndroid Build Coastguard Worker 	}
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TINFO, "send SIGCONT to child");
31*49cdfc7eSAndroid Build Coastguard Worker 
32*49cdfc7eSAndroid Build Coastguard Worker 	memset(infop, 0, sizeof(*infop));
33*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS(waitid(P_PID, pid_child, infop, WSTOPPED));
34*49cdfc7eSAndroid Build Coastguard Worker 
35*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LI(infop->si_pid, pid_child);
36*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LI(infop->si_status, SIGSTOP);
37*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
38*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LI(infop->si_code, CLD_STOPPED);
39*49cdfc7eSAndroid Build Coastguard Worker 
40*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_KILL(pid_child, SIGCONT);
41*49cdfc7eSAndroid Build Coastguard Worker 
42*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TINFO, "filter child by WCONTINUED");
43*49cdfc7eSAndroid Build Coastguard Worker 
44*49cdfc7eSAndroid Build Coastguard Worker 	memset(infop, 0, sizeof(*infop));
45*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS(waitid(P_PID, pid_child, infop, WCONTINUED));
46*49cdfc7eSAndroid Build Coastguard Worker 
47*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LI(infop->si_pid, pid_child);
48*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LI(infop->si_status, SIGCONT);
49*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
50*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LI(infop->si_code, CLD_CONTINUED);
51*49cdfc7eSAndroid Build Coastguard Worker 
52*49cdfc7eSAndroid Build Coastguard Worker 	TST_CHECKPOINT_WAKE(0);
53*49cdfc7eSAndroid Build Coastguard Worker }
54*49cdfc7eSAndroid Build Coastguard Worker 
55*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
56*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = run,
57*49cdfc7eSAndroid Build Coastguard Worker 	.forks_child = 1,
58*49cdfc7eSAndroid Build Coastguard Worker 	.needs_checkpoints = 1,
59*49cdfc7eSAndroid Build Coastguard Worker 	.bufs = (struct tst_buffers[]) {
60*49cdfc7eSAndroid Build Coastguard Worker 		{&infop, .size = sizeof(*infop)},
61*49cdfc7eSAndroid Build Coastguard Worker 		{}
62*49cdfc7eSAndroid Build Coastguard Worker 	}
63*49cdfc7eSAndroid Build Coastguard Worker };
64