diff --git a/test/runtests.c b/test/runtests.c index f0ce8f7..f3e2a88 100644 --- a/test/runtests.c +++ b/test/runtests.c @@ -14,12 +14,10 @@ #include #include #include -#include #include #include #include -#include #include "optparse/optparse.h" @@ -32,11 +30,11 @@ #define TIMEOUT_STR_MAX_LEN 16 #define ACTION_RUN 0 -thread_local char bufa[CMPFILE_BUF_LEN]; -thread_local char bufb[CMPFILE_BUF_LEN]; -thread_local char timeoutfname[PATH_MAX]; -thread_local char reffname[PATH_MAX]; -thread_local char outfname[PATH_MAX]; +_Thread_local char bufa[CMPFILE_BUF_LEN]; +_Thread_local char bufb[CMPFILE_BUF_LEN]; +_Thread_local char timeoutfname[PATH_MAX]; +_Thread_local char reffname[PATH_MAX]; +_Thread_local char outfname[PATH_MAX]; int silent_success = 1; @@ -96,15 +94,14 @@ check_test_artefacts(const char *testname) { return -1; } - struct dirent dent; - struct dirent *result; - while (!readdir_r(tdir, &dent, &result) && result) { - const char *refdot = strstr(dent.d_name, "ref."); + struct dirent *dent; + while ((dent = readdir(tdir))) { + const char *refdot = strstr(dent->d_name, "ref."); if (!refdot) { continue; } - size_t ref_off = refdot - dent.d_name; - sprintf(reffname, "%s/%s", testname, dent.d_name); + size_t ref_off = refdot - dent->d_name; + sprintf(reffname, "%s/%s", testname, dent->d_name); strcpy(outfname, reffname); memcpy(outfname + strlen(testname) + 1 + ref_off, "out", 3); if (cmpfiles(reffname, outfname)) { @@ -151,6 +148,9 @@ get_test_timeout(const char *testname) { } #ifndef _WIN32 + +#include + static void * thread_wait(void *arg) { struct test_wait_arg *wa = arg; @@ -195,11 +195,38 @@ run_test(const void *arg) { return result; } #else -static void * -run_test(void *arg) { - const char *test_name = arg; - return (void *)-1; +#include +#include +#include +#include +#include + +static void * +run_test(const void *arg) { + const char *test_name = arg; + void *result = NULL; + STARTUPINFO si; + PROCESS_INFORMATION pi; + memset(&si, 0, sizeof(si)); + memset(&pi, 0, sizeof(pi)); + unsigned tout = get_test_timeout(test_name); + + if(!CreateProcess(NULL, "../../umka_shell -ri run.us -o out.log", NULL, + NULL, FALSE, 0, NULL, NULL, &si, &pi)) { + fprintf(stderr, "CreateProcess failed: %lu\n", GetLastError()); + return (void *)-1; + } + + DWORD wait_res = WaitForSingleObject(pi.hProcess, tout*1000); + if (wait_res == WAIT_TIMEOUT) { + TerminateProcess(pi.hProcess, 1); + result = (void *)(intptr_t)-1; + } + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + return result; } #endif diff --git a/test/t019/timeout.txt b/test/t019/timeout.txt index 39e1887..220ad04 100644 --- a/test/t019/timeout.txt +++ b/test/t019/timeout.txt @@ -1 +1 @@ -10s +20s diff --git a/test/t056/timeout.txt b/test/t056/timeout.txt index 39e1887..38823f7 100644 --- a/test/t056/timeout.txt +++ b/test/t056/timeout.txt @@ -1 +1 @@ -10s +30s diff --git a/test/t057/timeout.txt b/test/t057/timeout.txt index 39e1887..220ad04 100644 --- a/test/t057/timeout.txt +++ b/test/t057/timeout.txt @@ -1 +1 @@ -10s +20s diff --git a/test/t058/timeout.txt b/test/t058/timeout.txt index d6c4f3f..72ad887 100644 --- a/test/t058/timeout.txt +++ b/test/t058/timeout.txt @@ -1 +1 @@ -1m0s +2m0s diff --git a/test/t060/timeout.txt b/test/t060/timeout.txt index 39e1887..38823f7 100644 --- a/test/t060/timeout.txt +++ b/test/t060/timeout.txt @@ -1 +1 @@ -10s +30s diff --git a/test/t064/timeout.txt b/test/t064/timeout.txt index d6c4f3f..72ad887 100644 --- a/test/t064/timeout.txt +++ b/test/t064/timeout.txt @@ -1 +1 @@ -1m0s +2m0s