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