Expand waitpid test.
This commit is contained in:
+1
-1
@@ -217,9 +217,9 @@ NAMES=\
|
||||
grp/getgrgid_r \
|
||||
grp/getgrnam_r \
|
||||
grp/gr_iter \
|
||||
sigqueue
|
||||
# resource/getrusage
|
||||
# time/times
|
||||
# sigqueue
|
||||
|
||||
# Tests run with `expect` (require a .c file and an .exp file
|
||||
# that takes the produced binary as the first argument)
|
||||
|
||||
+22
-7
@@ -1,21 +1,36 @@
|
||||
#include <assert.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(void) {
|
||||
void for_code(int code) {
|
||||
pid_t pid = fork();
|
||||
ERROR_IF(fork, pid, == -1);
|
||||
|
||||
// Testing successful exit
|
||||
if (pid == 0) {
|
||||
// child
|
||||
sleep(1);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else {
|
||||
// parent
|
||||
int stat_loc;
|
||||
pid_t wid = waitpid(pid, &stat_loc, 0);
|
||||
ERROR_IF(waitpid, wid, == -1);
|
||||
_Exit(code);
|
||||
}
|
||||
printf("Testing waitpid of child %d for code %d\n", pid, code);
|
||||
// parent
|
||||
int status;
|
||||
pid_t wid = waitpid(pid, &status, 0);
|
||||
ERROR_IF(waitpid, wid, == -1);
|
||||
|
||||
assert(WIFEXITED(status));
|
||||
assert(WEXITSTATUS(status) == code);
|
||||
|
||||
puts("Success");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
for_code(EXIT_SUCCESS);
|
||||
for_code(EXIT_FAILURE);
|
||||
for_code(42);
|
||||
for_code(255);
|
||||
// TODO: Also add coverage for e.g. WIFSTOPPED, WSTOPSIG, WTERMSIG, etc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user