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