xref: /xnu-10063.141.1/tests/sigcont_return.c (revision d8b80295118ef25ac3a784134bcf95cd8e88109f)
1*d8b80295SApple OSS Distributions #include <signal.h>
2*d8b80295SApple OSS Distributions #include <stdio.h>
3*d8b80295SApple OSS Distributions #include <stdlib.h>
4*d8b80295SApple OSS Distributions #include <unistd.h>
5*d8b80295SApple OSS Distributions #include <errno.h>
6*d8b80295SApple OSS Distributions 
7*d8b80295SApple OSS Distributions #include <darwintest.h>
8*d8b80295SApple OSS Distributions 
9*d8b80295SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
10*d8b80295SApple OSS Distributions 
11*d8b80295SApple OSS Distributions T_DECL(sigcontreturn, "checks that a call to waitid() for a child that is stopped and then continued returns correctly")
12*d8b80295SApple OSS Distributions {
13*d8b80295SApple OSS Distributions 	pid_t           pid;
14*d8b80295SApple OSS Distributions 	siginfo_t       siginfo;
15*d8b80295SApple OSS Distributions 	pid = fork();
16*d8b80295SApple OSS Distributions 	T_QUIET; T_ASSERT_NE_INT(pid, -1, "fork() failed!");
17*d8b80295SApple OSS Distributions 
18*d8b80295SApple OSS Distributions 	if (pid == 0) {
19*d8b80295SApple OSS Distributions 		while (1) {
20*d8b80295SApple OSS Distributions 		}
21*d8b80295SApple OSS Distributions 	}
22*d8b80295SApple OSS Distributions 
23*d8b80295SApple OSS Distributions 	kill(pid, SIGSTOP);
24*d8b80295SApple OSS Distributions 	kill(pid, SIGCONT);
25*d8b80295SApple OSS Distributions 	sleep(1);
26*d8b80295SApple OSS Distributions 
27*d8b80295SApple OSS Distributions 	T_QUIET; T_ASSERT_POSIX_SUCCESS(waitid(P_PID, pid, &siginfo, WCONTINUED), "Calling waitid() failed for pid %d", pid);
28*d8b80295SApple OSS Distributions 
29*d8b80295SApple OSS Distributions 	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 );
30*d8b80295SApple OSS Distributions 	kill(pid, SIGKILL);
31*d8b80295SApple OSS Distributions }
32