1 /* Wait for process state tests.
2 Copyright (C) 2020-2022 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/>. */
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>
35 sigusr1_handler (int signo
)
42 xsignal (SIGUSR1
, sigusr1_handler
);
46 TEST_COMPARE (pause (), -1);
47 TEST_COMPARE (errno
, EINTR
);
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
;
69 printf ("info: waiting pid %d, state_stopped/state_tracing_stop\n",
71 support_process_state_wait (pid
, stop_state
);
73 if (kill (pid
, SIGCONT
) != 0)
74 FAIL_RET ("kill (%d, SIGCONT): %m\n", pid
);
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
);
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
);
91 printf ("info: waiting pid %d, state_zombie\n", (int) pid
);
92 support_process_state_wait (pid
, support_process_state_zombie
);
95 int r
= waitid (P_PID
, pid
, &info
, WEXITED
);
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
);
105 #include <support/test-driver.c>