Use Linux 6.6 in build-many-glibcs.py
[glibc.git] / support / tst-support-process_state.c
blobbece316276e999b763de3760c472f5e73e087257
1 /* Wait for process state tests.
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <stdio.h>
20 #include <sys/wait.h>
21 #include <unistd.h>
22 #include <errno.h>
24 #include <support/test-driver.h>
25 #include <support/process_state.h>
26 #include <support/check.h>
27 #include <support/xsignal.h>
28 #include <support/xunistd.h>
30 #ifndef WEXITED
31 # define WEXITED 0
32 #endif
34 static void
35 sigusr1_handler (int signo)
39 static void
40 test_child (void)
42 xsignal (SIGUSR1, sigusr1_handler);
44 raise (SIGSTOP);
46 TEST_COMPARE (pause (), -1);
47 TEST_COMPARE (errno, EINTR);
49 while (1)
50 asm ("");
53 static int
54 do_test (void)
56 pid_t pid = xfork ();
57 if (pid == 0)
59 test_child ();
60 _exit (127);
63 /* Adding process_state_tracing_stop ('t') allows the test to work under
64 trace programs such as ptrace. */
65 enum support_process_state stop_state = support_process_state_stopped
66 | support_process_state_tracing_stop;
68 if (test_verbose)
69 printf ("info: waiting pid %d, state_stopped/state_tracing_stop\n",
70 (int) pid);
71 support_process_state_wait (pid, stop_state);
73 if (kill (pid, SIGCONT) != 0)
74 FAIL_RET ("kill (%d, SIGCONT): %m\n", pid);
76 if (test_verbose)
77 printf ("info: waiting pid %d, state_sleeping\n", (int) pid);
78 support_process_state_wait (pid, support_process_state_sleeping);
80 if (kill (pid, SIGUSR1) != 0)
81 FAIL_RET ("kill (%d, SIGUSR1): %m\n", pid);
83 if (test_verbose)
84 printf ("info: waiting pid %d, state_running\n", (int) pid);
85 support_process_state_wait (pid, support_process_state_running);
87 if (kill (pid, SIGKILL) != 0)
88 FAIL_RET ("kill (%d, SIGKILL): %m\n", pid);
90 if (test_verbose)
91 printf ("info: waiting pid %d, state_zombie\n", (int) pid);
92 support_process_state_wait (pid, support_process_state_zombie);
94 siginfo_t info;
95 int r = waitid (P_PID, pid, &info, WEXITED);
96 TEST_COMPARE (r, 0);
97 TEST_COMPARE (info.si_signo, SIGCHLD);
98 TEST_COMPARE (info.si_code, CLD_KILLED);
99 TEST_COMPARE (info.si_status, SIGKILL);
100 TEST_COMPARE (info.si_pid, pid);
102 return 0;
105 #include <support/test-driver.c>