22
23
#include <string.h>
24
25
#include "runner.h"
27
29
char executable_path[PATHMAX] = { '\0' };
30
static void log_progress(int total, int passed, int failed, const char* name) {
31
LOGF("[%% %3d|+ %3d|- %3d]: %s", (passed + failed) / total * 100,
32
passed, failed, name);
34
static void log_progress(int total,
45
progress = 100 * (passed + failed + skipped + todos) / total;
46
LOGF("[%% %3d|+ %3d|- %3d|T %3d|S %3d]: %s",
56
const char* fmt(double d) {
57
static char buf[1024];
66
if (p >= buf + sizeof(buf))
67
return "<buffer too small>";
71
#if 0 /* works but we don't care about fractional precision */
73
*--p = '0' + (uint64_t) (d * 100) % 10;
74
*--p = '0' + (uint64_t) (d * 10) % 10;
83
if (v) *--p = '0' + (v % 10), v /= 10;
84
if (v) *--p = '0' + (v % 10), v /= 10;
85
if (v) *--p = '0' + (v % 10), v /= 10;
36
93
int run_tests(int timeout, int benchmark_output) {
37
int total, passed, failed;
38
101
task_entry_t* task;
40
103
/* Count the number of tests. */
112
LOGF("1..%d\n", total);
48
115
/* Run all tests. */
51
121
for (task = TASKS; task->main; task++) {
52
122
if (task->is_helper) {
129
if (!benchmark_output && !tap_output) {
130
log_progress(total, passed, failed, todos, skipped, task->task_name);
133
test_result = run_test(task->task_name, timeout, benchmark_output, current);
134
switch (test_result) {
135
case TEST_OK: passed++; break;
136
case TEST_TODO: todos++; break;
137
case TEST_SKIP: skipped++; break;
57
if (!benchmark_output) {
58
log_progress(total, passed, failed, task->task_name);
61
if (run_test(task->task_name, timeout, benchmark_output) == 0) {
70
if (!benchmark_output) {
71
log_progress(total, passed, failed, "Done.\n");
146
if (!benchmark_output && !tap_output) {
147
log_progress(total, passed, failed, todos, skipped, "Done.\n");
78
int run_test(const char* test, int timeout, int benchmark_output) {
154
void log_tap_result(int test_count,
157
process_info_t* process) {
159
const char* directive;
169
directive = " # TODO ";
173
directive = " # SKIP ";
180
if ((status == TEST_SKIP || status == TEST_TODO) &&
181
process_output_size(process) > 0) {
182
process_read_last_line(process, reason, sizeof reason);
187
LOGF("%s %d - %s%s%s\n", result, test_count, test, directive, reason);
191
int run_test(const char* test,
193
int benchmark_output,
79
195
char errmsg[1024] = "no error";
80
196
process_info_t processes[1024];
81
197
process_info_t *main_proc;
90
206
process_count = 0;
209
/* Clean up stale socket from previous run. */
210
remove(TEST_PIPENAME);
92
213
/* If it's a helper the user asks for, start it directly. */
93
214
for (task = TASKS; task->main; task++) {
94
215
if (task->is_helper && strcmp(test, task->process_name) == 0) {
110
231
if (process_start(task->task_name,
111
232
task->process_name,
112
&processes[process_count]) == -1) {
233
&processes[process_count],
234
1 /* is_helper */) == -1) {
115
237
"Process `%s` failed to start.",
126
248
/* Now start the test itself. */
127
for (main_proc = NULL, task = TASKS; task->main; task++) {
249
for (task = TASKS; task->main; task++) {
128
250
if (strcmp(test, task->task_name) != 0) {
136
258
if (process_start(task->task_name,
137
259
task->process_name,
138
&processes[process_count]) == -1) {
260
&processes[process_count],
261
0 /* !is_helper */) == -1) {
141
264
"Process `%s` failed to start.",
192
315
FATAL("process_wait failed");
319
log_tap_result(test_count, test, status, &processes[i]);
195
321
/* Show error and output from processes if the test failed. */
197
LOGF("\n`%s` failed: %s\n", test, errmsg);
322
if (status != 0 || task->show_output) {
325
} else if (status == TEST_TODO) {
326
LOGF("\n`%s` todo\n", test);
327
} else if (status == TEST_SKIP) {
328
LOGF("\n`%s` skipped\n", test);
329
} else if (status != 0) {
330
LOGF("\n`%s` failed: %s\n", test, errmsg);
199
335
for (i = 0; i < process_count; i++) {
200
336
switch (process_output_size(&processes[i])) {
217
LOG("=============================================================\n");
355
LOG("=============================================================\n");
219
358
/* In benchmark mode show concise output from the main process. */
220
359
} else if (benchmark_output) {
250
389
int run_test_part(const char* test, const char* part) {
251
390
task_entry_t* task;
253
393
for (task = TASKS; task->main; task++) {
254
if (strcmp(test, task->task_name) == 0
255
&& strcmp(part, task->process_name) == 0) {
394
if (strcmp(test, task->task_name) == 0 &&
395
strcmp(part, task->process_name) == 0) {