Test runner minor fixes
This commit is contained in:
parent
ad94c9297e
commit
56608452af
@ -55,7 +55,7 @@ int process_start(char *name, process_info_t *p) {
|
|||||||
if (_snwprintf_s((wchar_t*)&args,
|
if (_snwprintf_s((wchar_t*)&args,
|
||||||
sizeof(args) / sizeof(wchar_t),
|
sizeof(args) / sizeof(wchar_t),
|
||||||
_TRUNCATE,
|
_TRUNCATE,
|
||||||
L"\"%s\" %S meh",
|
L"\"%s\" %S",
|
||||||
image,
|
image,
|
||||||
name) < 0)
|
name) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -95,7 +95,7 @@ error:
|
|||||||
|
|
||||||
|
|
||||||
/* Timeout is is msecs. Set timeout < 0 to never time out. */
|
/* Timeout is is msecs. Set timeout < 0 to never time out. */
|
||||||
/* Returns 0 when all processes are terminated, -1 on timeout. */
|
/* Returns 0 when all processes are terminated, -2 on timeout. */
|
||||||
int process_wait(process_info_t *vec, int n, int timeout) {
|
int process_wait(process_info_t *vec, int n, int timeout) {
|
||||||
int i;
|
int i;
|
||||||
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
|
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
|
||||||
@ -138,7 +138,6 @@ long int process_output_size(process_info_t *p) {
|
|||||||
|
|
||||||
|
|
||||||
int process_copy_output(process_info_t *p, int fd) {
|
int process_copy_output(process_info_t *p, int fd) {
|
||||||
/* Any errors in this function are ignored */
|
|
||||||
DWORD read;
|
DWORD read;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
@ -162,7 +161,6 @@ char* process_get_name(process_info_t *p) {
|
|||||||
|
|
||||||
|
|
||||||
int process_terminate(process_info_t *p) {
|
int process_terminate(process_info_t *p) {
|
||||||
/* If it fails the process is probably already closed. */
|
|
||||||
if (!TerminateProcess(p->process, 1))
|
if (!TerminateProcess(p->process, 1))
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -1,5 +1,17 @@
|
|||||||
|
|
||||||
|
/* Don't complain about _snprintf being unsecure. */
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
|
/* Dont complain about write(), fileno() etc. being deprecated. */
|
||||||
|
#pragma warning(disable : 4996)
|
||||||
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Windows has no snprintf, only _snprintf. */
|
||||||
|
#define snprintf _snprintf
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -39,12 +39,12 @@ int run_test(test_entry_t *test) {
|
|||||||
|
|
||||||
process_count = 0;
|
process_count = 0;
|
||||||
|
|
||||||
/* Start all helpers for this test first */
|
/* Start all helpers for this test first. */
|
||||||
for (helper = (test_entry_t*)&TESTS; helper->main; helper++) {
|
for (helper = (test_entry_t*)&TESTS; helper->main; helper++) {
|
||||||
if (helper->is_helper &&
|
if (helper->is_helper &&
|
||||||
strcmp(test->test_name, helper->test_name) == 0) {
|
strcmp(test->test_name, helper->test_name) == 0) {
|
||||||
if (process_start(helper->process_name, &processes[process_count]) == -1) {
|
if (process_start(helper->process_name, &processes[process_count]) == -1) {
|
||||||
sprintf_s((char*)&errmsg, sizeof(errmsg), "process `%s` failed to start.", helper->process_name);
|
snprintf((char*)&errmsg, sizeof(errmsg), "process `%s` failed to start.", helper->process_name);
|
||||||
goto finalize;
|
goto finalize;
|
||||||
}
|
}
|
||||||
process_count++;
|
process_count++;
|
||||||
@ -53,7 +53,7 @@ int run_test(test_entry_t *test) {
|
|||||||
|
|
||||||
/* Start the main test process. */
|
/* Start the main test process. */
|
||||||
if (process_start(test->process_name, &processes[process_count]) == -1) {
|
if (process_start(test->process_name, &processes[process_count]) == -1) {
|
||||||
sprintf_s((char*)&errmsg, sizeof(errmsg), "process `%s` failed to start.", test->process_name);
|
snprintf((char*)&errmsg, sizeof(errmsg), "process `%s` failed to start.", test->process_name);
|
||||||
goto finalize;
|
goto finalize;
|
||||||
}
|
}
|
||||||
main_process = &processes[process_count];
|
main_process = &processes[process_count];
|
||||||
@ -64,14 +64,14 @@ int run_test(test_entry_t *test) {
|
|||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
FATAL("process_wait failed\n");
|
FATAL("process_wait failed\n");
|
||||||
} else if (result == -2) {
|
} else if (result == -2) {
|
||||||
sprintf_s((char*)&errmsg, sizeof(errmsg), "timeout.");
|
snprintf((char*)&errmsg, sizeof(errmsg), "timeout.");
|
||||||
goto finalize;
|
goto finalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reap main process */
|
/* Reap the main process. */
|
||||||
result = process_reap(main_process);
|
result = process_reap(main_process);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
sprintf_s((char*)&errmsg, sizeof(errmsg), "exit code %d.", result);
|
snprintf((char*)&errmsg, sizeof(errmsg), "exit code %d.", result);
|
||||||
goto finalize;
|
goto finalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +81,7 @@ int run_test(test_entry_t *test) {
|
|||||||
finalize:
|
finalize:
|
||||||
/* Kill all (helper) processes that are still running. */
|
/* Kill all (helper) processes that are still running. */
|
||||||
for (i = 0; i < process_count; i++)
|
for (i = 0; i < process_count; i++)
|
||||||
|
/* If terminate fails the process is probably already closed. */
|
||||||
process_terminate(&processes[i]);
|
process_terminate(&processes[i]);
|
||||||
|
|
||||||
/* Wait until all processes have really terminated. */
|
/* Wait until all processes have really terminated. */
|
||||||
@ -128,11 +129,11 @@ int main(int argc, char **argv) {
|
|||||||
test_entry_t *test;
|
test_entry_t *test;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* On windows disable the "application crashed" popup */
|
/* On windows disable the "application crashed" popup. */
|
||||||
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
|
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Disable 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);
|
||||||
|
|
||||||
@ -146,7 +147,7 @@ int main(int argc, char **argv) {
|
|||||||
return 255;
|
return 255;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Count the number of tests */
|
/* Count the number of tests. */
|
||||||
total = 0;
|
total = 0;
|
||||||
test = (test_entry_t*)&TESTS;
|
test = (test_entry_t*)&TESTS;
|
||||||
for (test = (test_entry_t*)&TESTS; test->main; test++) {
|
for (test = (test_entry_t*)&TESTS; test->main; test++) {
|
||||||
@ -154,7 +155,7 @@ int main(int argc, char **argv) {
|
|||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run all tests */
|
/* Run all tests. */
|
||||||
passed = 0;
|
passed = 0;
|
||||||
failed = 0;
|
failed = 0;
|
||||||
test = (test_entry_t*)&TESTS;
|
test = (test_entry_t*)&TESTS;
|
||||||
|
|||||||
@ -70,11 +70,11 @@ char* process_get_name(process_info_t *p);
|
|||||||
/* Terminate process `p`. */
|
/* Terminate process `p`. */
|
||||||
int process_terminate(process_info_t *p);
|
int process_terminate(process_info_t *p);
|
||||||
|
|
||||||
/* Return the return value of process p. */
|
/* Return the exit code of process p. */
|
||||||
/* On error, return -1. */
|
/* On error, return -1. */
|
||||||
int process_reap(process_info_t *p);
|
int process_reap(process_info_t *p);
|
||||||
|
|
||||||
/* Clean up after terminating process `p` (e.g. free the output buffer etc.) */
|
/* Clean up after terminating process `p` (e.g. free the output buffer etc.). */
|
||||||
void process_cleanup(process_info_t *p);
|
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. */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user