-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_engine.c
207 lines (150 loc) · 4.47 KB
/
check_engine.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <check.h>
#include <math.h>
#include <pthread.h>
#include <string.h>
#include <time.h>
#include "engine.h"
#include "def.h"
START_TEST(test_format_step_too_few_specifiers) {
step tmp_stp;
tmp_stp.stdout_cmd_fmt = "";
tmp_stp.tmpfile_cmd_fmt = "";
tmp_stp.tmpfile = "/tmp/foo";
tmp_stp.stdin_prerequisite = NULL;
tmp_stp.tmpfile_prerequisites = NULL;
tmp_stp.next = NULL;
step stp;
stp.stdout_cmd_fmt = "";
stp.tmpfile_cmd_fmt = "";
stp.tmpfile = NULL;
stp.stdin_prerequisite = NULL;
stp.tmpfile_prerequisites = &tmp_stp;
stp.next = NULL;
char buf[2000];
int retval = format_step(buf, "foo", &stp);
fail_unless(retval == FAILURE,
"did not return FAILURE when more tmpfiles than %%i");
}
END_TEST
START_TEST(test_format_step_too_many_specifiers) {
step stp;
stp.stdout_cmd_fmt = "";
stp.tmpfile_cmd_fmt = "";
stp.tmpfile = "/tmp/foo";
stp.stdin_prerequisite = NULL;
stp.tmpfile_prerequisites = NULL;
stp.next = NULL;
char buf[2000];
int retval = format_step(buf, "foo %i %i", &stp);
fail_unless(retval == FAILURE,
"did not return FAILURE when fewer tmpfiles than %%i");
}
END_TEST
START_TEST(test_format_step) {
step tmp_stp;
tmp_stp.stdout_cmd_fmt = "";
tmp_stp.tmpfile_cmd_fmt = "";
tmp_stp.tmpfile = "/tmp/foo";
tmp_stp.stdin_prerequisite = NULL;
tmp_stp.tmpfile_prerequisites = NULL;
tmp_stp.next = NULL;
step stp;
stp.stdout_cmd_fmt = "";
stp.tmpfile_cmd_fmt = "";
stp.tmpfile = NULL;
stp.stdin_prerequisite = NULL;
stp.tmpfile_prerequisites = &tmp_stp;
stp.next = NULL;
char buf[2000];
int retval = format_step(buf, "foo %i bar", &stp);
fail_unless(retval == 0, "did not return 0");
fail_unless(strcmp(buf, "foo /tmp/foo bar") == 0,
"did not set buf to 'foo /tmp/foo bar'");
}
END_TEST
START_TEST(test_execute_stdout_step) {
step stp;
stp.stdout_cmd_fmt = "ls";
stp.tmpfile_cmd_fmt = "";
stp.tmpfile = NULL;
stp.stdin_prerequisite = NULL;
stp.tmpfile_prerequisites = NULL;
stp.next = NULL;
char buf[2000];
int retval = execute_stdout_step(&stp);
fail_unless(retval == SUCCESS, "did not return SUCCESS");
}
END_TEST
START_TEST(test_execute_stdout_step_pipe) {
step pre_stp;
pre_stp.stdout_cmd_fmt = "ls";
pre_stp.tmpfile_cmd_fmt = "";
pre_stp.tmpfile = NULL;
pre_stp.stdin_prerequisite = NULL;
pre_stp.tmpfile_prerequisites = NULL;
pre_stp.next = NULL;
step stp;
stp.stdout_cmd_fmt = "sort";
stp.tmpfile_cmd_fmt = "";
stp.tmpfile = NULL;
stp.stdin_prerequisite = &pre_stp;
stp.tmpfile_prerequisites = NULL;
stp.next = NULL;
char buf[2000];
int retval = execute_stdout_step(&stp);
fail_unless(retval == SUCCESS, "did not return SUCCESS");
}
END_TEST
START_TEST(test_execute_stdout_step_tmpfile) {
step pre_stp;
pre_stp.stdout_cmd_fmt = "";
pre_stp.tmpfile_cmd_fmt = "ls > %o";
pre_stp.tmpfile = NULL;
pre_stp.stdin_prerequisite = NULL;
pre_stp.tmpfile_prerequisites = NULL;
pre_stp.next = NULL;
step stp;
stp.stdout_cmd_fmt = "head -1 %i";
stp.tmpfile_cmd_fmt = "";
stp.tmpfile = NULL;
stp.stdin_prerequisite = NULL;
stp.tmpfile_prerequisites = &pre_stp;
stp.next = NULL;
char buf[2000];
int retval = execute_stdout_step(&stp);
fail_unless(retval == SUCCESS, "did not return SUCCESS");
}
END_TEST
Suite *
suite_engine(void) {
Suite *ste = suite_create("suite: engine");
TCase *tc1 = tcase_create("case: format_step_too_few_specifiers");
TCase *tc2 = tcase_create("case: format_step_too_many_specifiers");
TCase *tc3 = tcase_create("case: format_step");
TCase *tc4 = tcase_create("case: execute_stdout_step");
TCase *tc5 = tcase_create("case: execute_stdout_step_pipe");
TCase *tc6 = tcase_create("case: execute_stdout_step_tmpfile");
tcase_add_test(tc1, test_format_step_too_few_specifiers);
suite_add_tcase(ste, tc1);
tcase_add_test(tc2, test_format_step_too_many_specifiers);
suite_add_tcase(ste, tc2);
tcase_add_test(tc3, test_format_step);
suite_add_tcase(ste, tc3);
tcase_add_test(tc4, test_execute_stdout_step);
suite_add_tcase(ste, tc4);
tcase_add_test(tc5, test_execute_stdout_step_pipe);
suite_add_tcase(ste, tc5);
tcase_add_test(tc6, test_execute_stdout_step_tmpfile);
suite_add_tcase(ste, tc6);
return ste;
}
int
main(void) {
int number_failed;
Suite *ste = suite_engine();
SRunner *sr = srunner_create(ste);
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed);
}