Test runner minor fixes

This commit is contained in:
Bert Belder 2011-04-05 03:03:45 +02:00
parent ad94c9297e
commit 56608452af
4 changed files with 28 additions and 17 deletions

View File

@ -55,7 +55,7 @@ int process_start(char *name, process_info_t *p) {
if (_snwprintf_s((wchar_t*)&args,
sizeof(args) / sizeof(wchar_t),
_TRUNCATE,
L"\"%s\" %S meh",
L"\"%s\" %S",
image,
name) < 0)
goto error;
@ -95,7 +95,7 @@ error:
/* 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 i;
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) {
/* Any errors in this function are ignored */
DWORD read;
char buf[1024];
@ -162,7 +161,6 @@ char* process_get_name(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))
return -1;
return 0;

View File

@ -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 <stdio.h>
/* Windows has no snprintf, only _snprintf. */
#define snprintf _snprintf
typedef struct {
@ -7,4 +19,4 @@ typedef struct {
HANDLE stdio_in;
HANDLE stdio_out;
char *name;
} process_info_t;
} process_info_t;

View File

@ -39,12 +39,12 @@ int run_test(test_entry_t *test) {
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++) {
if (helper->is_helper &&
strcmp(test->test_name, helper->test_name) == 0) {
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;
}
process_count++;
@ -53,7 +53,7 @@ int run_test(test_entry_t *test) {
/* Start the main test process. */
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;
}
main_process = &processes[process_count];
@ -64,14 +64,14 @@ int run_test(test_entry_t *test) {
if (result == -1) {
FATAL("process_wait failed\n");
} else if (result == -2) {
sprintf_s((char*)&errmsg, sizeof(errmsg), "timeout.");
snprintf((char*)&errmsg, sizeof(errmsg), "timeout.");
goto finalize;
}
/* Reap main process */
/* Reap the main process. */
result = process_reap(main_process);
if (result != 0) {
sprintf_s((char*)&errmsg, sizeof(errmsg), "exit code %d.", result);
snprintf((char*)&errmsg, sizeof(errmsg), "exit code %d.", result);
goto finalize;
}
@ -81,6 +81,7 @@ int run_test(test_entry_t *test) {
finalize:
/* Kill all (helper) processes that are still running. */
for (i = 0; i < process_count; i++)
/* If terminate fails the process is probably already closed. */
process_terminate(&processes[i]);
/* Wait until all processes have really terminated. */
@ -128,11 +129,11 @@ int main(int argc, char **argv) {
test_entry_t *test;
#ifdef _WIN32
/* On windows disable the "application crashed" popup */
/* On windows disable the "application crashed" popup. */
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
#endif
/* Disable output buffering */
/* Disable stdio output buffering. */
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
@ -146,7 +147,7 @@ int main(int argc, char **argv) {
return 255;
} else {
/* Count the number of tests */
/* Count the number of tests. */
total = 0;
test = (test_entry_t*)&TESTS;
for (test = (test_entry_t*)&TESTS; test->main; test++) {
@ -154,7 +155,7 @@ int main(int argc, char **argv) {
total++;
}
/* Run all tests */
/* Run all tests. */
passed = 0;
failed = 0;
test = (test_entry_t*)&TESTS;

View File

@ -70,11 +70,11 @@ char* process_get_name(process_info_t *p);
/* Terminate process `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. */
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);
/* Move the console cursor one line up and back to the first column. */