-
Notifications
You must be signed in to change notification settings - Fork 2
/
self_tests.c
64 lines (58 loc) · 1.05 KB
/
self_tests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* See LICENSE file for copyright and license details.
*
* A test suite for dh_cuts, implemented with dh_cuts.
* Weirdness ensues.
*/
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#define DH_IMPLEMENT_HERE
#include "dh_cuts.h"
static void
test_crash_recovery(void)
{
dh_push("crash recovery");
pid_t pid = fork();
if (pid == 0) {
dh_init(fopen("/dev/null", "w"));
dh_branch( raise(SIGBUS); )
exit(0);
}
if (pid > 0) {
int ret = 0;
waitpid(pid, &ret, 0);
dh_assert(ret == 0);
}
dh_pop();
}
static void
test_forfeit_on_failure(void)
{
dh_push("forfeit on failure");
pid_t pid = fork();
if (pid == 0) {
dh_init(fopen("/dev/null", "w"));
dh_throw("always throw");
exit(0);
}
if (pid > 0) {
int ret = 0;
waitpid(pid, &ret, 0);
dh_assert(ret != 0);
}
dh_pop();
}
int
main()
{
dh_init(stdout);
dh_push("dh_cuts self-tests");
dh_branch( test_crash_recovery(); )
dh_branch( test_forfeit_on_failure(); )
dh_pop();
dh_summarize();
return EXIT_SUCCESS;
}