xref: /xnu-12377.41.6/tests/signals/sigcont_return.c (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1 #include <signal.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <errno.h>
6 
7 #include <darwintest.h>
8 
9 T_GLOBAL_META(
10 	T_META_RUN_CONCURRENTLY(true),
11 	T_META_CHECK_LEAKS(false),
12 	T_META_TAG_VM_PREFERRED,
13 	T_META_RADAR_COMPONENT_NAME("xnu"),
14 	T_META_RADAR_COMPONENT_VERSION("signals"));
15 
16 T_DECL(sigcontreturn, "checks that a call to waitid() for a child that is stopped and then continued returns correctly", T_META_TAG_VM_PREFERRED)
17 {
18 	pid_t           pid;
19 	siginfo_t       siginfo;
20 	pid = fork();
21 	T_QUIET; T_ASSERT_NE_INT(pid, -1, "fork() failed!");
22 
23 	if (pid == 0) {
24 		while (1) {
25 		}
26 	}
27 
28 	kill(pid, SIGSTOP);
29 	kill(pid, SIGCONT);
30 	sleep(1);
31 
32 	T_QUIET; T_ASSERT_POSIX_SUCCESS(waitid(P_PID, pid, &siginfo, WCONTINUED), "Calling waitid() failed for pid %d", pid);
33 
34 	T_ASSERT_EQ_INT(siginfo.si_status, SIGCONT, "A call to waitid() for stopped and continued child returns 0x%x, expected SIGCONT (0x%x)", siginfo.si_status, SIGCONT );
35 	kill(pid, SIGKILL);
36 }
37