-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.c
More file actions
95 lines (83 loc) · 1.68 KB
/
Copy pathtests.c
File metadata and controls
95 lines (83 loc) · 1.68 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "tests.h"
#include "util.h"
int
skip_test(const char *name, int argc, char *argv[])
{
int i;
if(argc == 1) {
return 0;
}
for(i = 1; i < argc; i++) {
if(!strcmp(argv[i], name)) {
return 0;
}
}
return 1;
}
static size_t run_tests_count = LEN(TESTS);
static size_t
next_from_all(int argc, char *argv[]) {
(void)argc; (void)argv;
static size_t i = 0;
return i++;
}
static size_t
next_from_args(int argc, char *argv[])
{
static int i = 1;
static size_t run = 0;
size_t j;
for(; i < argc; i++) {
for(j = 0; j < LEN(TESTS); j++) {
if(!strcmp(argv[i], TESTS[j].name)) {
i++;
run++;
return j;
}
}
}
run_tests_count = run;
return LEN(TESTS);
}
int __wrap_main(int argc, char *argv[])
{
size_t i;
size_t success = 0;
pid_t pid;
int status;
size_t (*next)(int, char*[]);
next = (argc > 1) ? next_from_args : next_from_all;
while((i = next(argc, argv)) < LEN(TESTS)) {
printf("Running: %s\n", TESTS[i].name);
pid = fork();
if(pid < 0) {
perror("test suite failure, fork");
return -1;
}
if(pid == 0) {
return TESTS[i].func();
} else {
if(waitpid(pid, &status, 0) == -1) {
perror("test suite failure, waitpid");
return -1;
}
if(status) {
printf("failure: exit code %d signal %d\n\n",
WIFEXITED(status) ? WEXITSTATUS(status) : 0,
WIFSIGNALED(status) ? WTERMSIG(status) : -1);
} else {
puts("success");
success++;
}
}
}
printf("%s, tests ok: %zu / %zu\n",
success == run_tests_count ? "success" : "failure",
success, run_tests_count);
return success == run_tests_count ? 0 : 1;
}