test: add tap output
Given UV_TAP_OUTPUT being set, test result output should use TAP formatting
This commit is contained in:
parent
c98083ef26
commit
bfe269b8a0
@ -60,5 +60,5 @@ static int maybe_run_test(int argc, char **argv) {
|
|||||||
return 42;
|
return 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
return run_test(argv[1], BENCHMARK_TIMEOUT, 1);
|
return run_test(argv[1], BENCHMARK_TIMEOUT, 1, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -155,5 +155,5 @@ static int maybe_run_test(int argc, char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return run_test(argv[1], TEST_TIMEOUT, 0);
|
return run_test(argv[1], TEST_TIMEOUT, 0, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
/* Do platform-specific initialization. */
|
/* Do platform-specific initialization. */
|
||||||
void platform_init(int argc, char **argv) {
|
void platform_init(int argc, char **argv) {
|
||||||
const char* var = getenv("UV_RUN_AS_ROOT");
|
const char* var = getenv("UV_RUN_AS_ROOT");
|
||||||
|
const char* tap = getenv("UV_TAP_OUTPUT");
|
||||||
|
|
||||||
/* Running the tests as root is not smart - don't do it. */
|
/* Running the tests as root is not smart - don't do it. */
|
||||||
if (getuid() == 0 && (var == NULL || atoi(var) <= 0)) {
|
if (getuid() == 0 && (var == NULL || atoi(var) <= 0)) {
|
||||||
@ -49,6 +50,8 @@ void platform_init(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tap_output = (tap != NULL && atoi(tap) > 0);
|
||||||
|
|
||||||
/* Disable stdio output buffering. */
|
/* Disable stdio output buffering. */
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
setvbuf(stderr, NULL, _IONBF, 0);
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
@ -261,19 +264,26 @@ int process_copy_output(process_info_t *p, int fd) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t nread, nwritten;
|
ssize_t nwritten;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
while ((nread = read(fileno(p->stdout_file), buf, 1024)) > 0) {
|
/* TODO: what if the line is longer than buf */
|
||||||
nwritten = write(fd, buf, nread);
|
while (fgets(buf, sizeof(buf), p->stdout_file) != NULL) {
|
||||||
/* TODO: what if write doesn't write the whole buffer... */
|
/* TODO: what if write doesn't write the whole buffer... */
|
||||||
|
nwritten = 0;
|
||||||
|
|
||||||
|
if (tap_output)
|
||||||
|
nwritten += write(fd, "#", 1);
|
||||||
|
|
||||||
|
nwritten += write(fd, buf, strlen(buf));
|
||||||
|
|
||||||
if (nwritten < 0) {
|
if (nwritten < 0) {
|
||||||
perror("write");
|
perror("write");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nread < 0) {
|
if (ferror(p->stdout_file)) {
|
||||||
perror("read");
|
perror("read");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
char executable_path[PATHMAX] = { '\0' };
|
char executable_path[PATHMAX] = { '\0' };
|
||||||
|
|
||||||
|
int tap_output = 0;
|
||||||
|
|
||||||
|
|
||||||
static void log_progress(int total, int passed, int failed, const char* name) {
|
static void log_progress(int total, int passed, int failed, const char* name) {
|
||||||
if (total == 0)
|
if (total == 0)
|
||||||
@ -76,7 +78,7 @@ const char* fmt(double d) {
|
|||||||
|
|
||||||
|
|
||||||
int run_tests(int timeout, int benchmark_output) {
|
int run_tests(int timeout, int benchmark_output) {
|
||||||
int total, passed, failed;
|
int total, passed, failed, current;
|
||||||
task_entry_t* task;
|
task_entry_t* task;
|
||||||
|
|
||||||
/* Count the number of tests. */
|
/* Count the number of tests. */
|
||||||
@ -87,29 +89,35 @@ int run_tests(int timeout, int benchmark_output) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tap_output) {
|
||||||
|
LOGF("1..%d\n", total);
|
||||||
|
}
|
||||||
|
|
||||||
/* Run all tests. */
|
/* Run all tests. */
|
||||||
passed = 0;
|
passed = 0;
|
||||||
failed = 0;
|
failed = 0;
|
||||||
|
current = 1;
|
||||||
for (task = TASKS; task->main; task++) {
|
for (task = TASKS; task->main; task++) {
|
||||||
if (task->is_helper) {
|
if (task->is_helper) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rewind_cursor();
|
rewind_cursor();
|
||||||
if (!benchmark_output) {
|
if (!benchmark_output && !tap_output) {
|
||||||
log_progress(total, passed, failed, task->task_name);
|
log_progress(total, passed, failed, task->task_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (run_test(task->task_name, timeout, benchmark_output) == 0) {
|
if (run_test(task->task_name, timeout, benchmark_output, current) == 0) {
|
||||||
passed++;
|
passed++;
|
||||||
} else {
|
} else {
|
||||||
failed++;
|
failed++;
|
||||||
}
|
}
|
||||||
|
current++;
|
||||||
}
|
}
|
||||||
|
|
||||||
rewind_cursor();
|
rewind_cursor();
|
||||||
|
|
||||||
if (!benchmark_output) {
|
if (!benchmark_output && !tap_output) {
|
||||||
log_progress(total, passed, failed, "Done.\n");
|
log_progress(total, passed, failed, "Done.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +125,10 @@ int run_tests(int timeout, int benchmark_output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int run_test(const char* test, int timeout, int benchmark_output) {
|
int run_test(const char* test,
|
||||||
|
int timeout,
|
||||||
|
int benchmark_output,
|
||||||
|
int test_count) {
|
||||||
char errmsg[1024] = "no error";
|
char errmsg[1024] = "no error";
|
||||||
process_info_t processes[1024];
|
process_info_t processes[1024];
|
||||||
process_info_t *main_proc;
|
process_info_t *main_proc;
|
||||||
@ -243,7 +254,9 @@ out:
|
|||||||
|
|
||||||
/* Show error and output from processes if the test failed. */
|
/* Show error and output from processes if the test failed. */
|
||||||
if (status != 0 || task->show_output) {
|
if (status != 0 || task->show_output) {
|
||||||
if (status != 0) {
|
if (tap_output) {
|
||||||
|
LOGF("not ok %d - %s\n#", test_count, test);
|
||||||
|
} else if (status != 0) {
|
||||||
LOGF("\n`%s` failed: %s\n", test, errmsg);
|
LOGF("\n`%s` failed: %s\n", test, errmsg);
|
||||||
} else {
|
} else {
|
||||||
LOGF("\n");
|
LOGF("\n");
|
||||||
@ -267,7 +280,10 @@ out:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG("=============================================================\n");
|
|
||||||
|
if (!tap_output) {
|
||||||
|
LOG("=============================================================\n");
|
||||||
|
}
|
||||||
|
|
||||||
/* In benchmark mode show concise output from the main process. */
|
/* In benchmark mode show concise output from the main process. */
|
||||||
} else if (benchmark_output) {
|
} else if (benchmark_output) {
|
||||||
@ -286,6 +302,8 @@ out:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (tap_output) {
|
||||||
|
LOGF("ok %d - %s\n", test_count, test);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up all process handles. */
|
/* Clean up all process handles. */
|
||||||
|
|||||||
@ -102,7 +102,10 @@ int run_tests(int timeout, int benchmark_output);
|
|||||||
/*
|
/*
|
||||||
* Run a single test. Starts up any helpers.
|
* Run a single test. Starts up any helpers.
|
||||||
*/
|
*/
|
||||||
int run_test(const char* test, int timeout, int benchmark_output);
|
int run_test(const char* test,
|
||||||
|
int timeout,
|
||||||
|
int benchmark_output,
|
||||||
|
int test_count);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run a test part, i.e. the test or one of its helpers.
|
* Run a test part, i.e. the test or one of its helpers.
|
||||||
@ -156,4 +159,7 @@ void process_cleanup(process_info_t *p);
|
|||||||
/* Move the console cursor one line up and back to the first column. */
|
/* Move the console cursor one line up and back to the first column. */
|
||||||
void rewind_cursor(void);
|
void rewind_cursor(void);
|
||||||
|
|
||||||
|
/* trigger output as tap */
|
||||||
|
extern int tap_output;
|
||||||
|
|
||||||
#endif /* RUNNER_H_ */
|
#endif /* RUNNER_H_ */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user