tests/test_process.c: test_ensure_death
[vlock.git] / tests / test_process.c
blob3c826a12a38f5a2e39954cd35216cb05a495e1d7
1 #include <sys/types.h>
2 #include <sys/wait.h>
3 #include <unistd.h>
4 #include <signal.h>
5 #include <errno.h>
7 #include <CUnit/CUnit.h>
9 #include "process.h"
11 #include "test_process.h"
13 void test_wait_for_death(void)
15 pid_t pid = fork();
17 if (pid == 0) {
18 usleep(10000);
19 execl("/bin/true", "/bin/true", NULL);
20 _exit(1);
23 CU_ASSERT(!wait_for_death(pid, 0, 2000));
24 CU_ASSERT(wait_for_death(pid, 0, 20000));
27 void test_ensure_death(void)
29 pid_t pid = fork();
31 if (pid == 0) {
32 signal(SIGTERM, SIG_IGN);
33 signal(SIGHUP, SIG_IGN);
34 execl("/bin/true", "/bin/true", NULL);
35 _exit(0);
38 ensure_death(pid);
40 CU_ASSERT(waitpid(pid, NULL, WNOHANG) < 0);
41 CU_ASSERT(errno == ECHILD);
44 CU_TestInfo process_tests[] = {
45 { "test_wait_for_death", test_wait_for_death },
46 { "test_ensure_death", test_ensure_death },
47 CU_TEST_INFO_NULL,