1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2001
4 * Copyright (c) 2024 SUSE LLC <[email protected]>
5 */
6
7 /*\
8 * [Description]
9 *
10 * Test to check the error conditions in waitpid() syscall.
11 */
12
13 #include <signal.h>
14 #include <sys/wait.h>
15 #include "tst_test.h"
16
17 static struct testcase {
18 pid_t pid;
19 int flags;
20 int err;
21 } testcase_list[] = {
22 {-1, 0, ECHILD}, /* Wait for any child when none exist */
23 {1, 0, ECHILD}, /* Wait for non-child process */
24 {-1, -1, EINVAL}, /* Invalid flags */
25 {INT_MIN, 0, ESRCH}, /* Wait for invalid process group */
26 };
27
run(unsigned int n)28 static void run(unsigned int n)
29 {
30 const struct testcase *tc = testcase_list + n;
31
32 TST_EXP_FAIL2(waitpid(tc->pid, NULL, tc->flags), tc->err,
33 "waipid(%d, NULL, 0x%x)", tc->pid, tc->flags);
34 }
35
36 static struct tst_test test = {
37 .test = run,
38 .tcnt = ARRAY_SIZE(testcase_list)
39 };
40