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