diff --git a/test/initmain.c b/test/initmain.c index 11489e41..f920bb65 100644 --- a/test/initmain.c +++ b/test/initmain.c @@ -61,7 +61,7 @@ testingTest(QueueMain) int flag = 0; uiQueueMain(queued, &flag); - timeout_uiMain(t, 5 * testingNsecPerSec, 0); + timeout_uiMain(t, 5 * timerSecond, 0); if (flag != 1) testingTErrorf(t, "uiQueueMain() didn't set flag properly: got %d, want 1", flag); } @@ -122,7 +122,7 @@ testingTest(QueueMain_Sequence) uint32_t flag; queueOrder(&flag); - timeout_uiMain(t, 5 * testingNsecPerSec, 0); + timeout_uiMain(t, 5 * timerSecond, 0); checkOrder(t, flag); } @@ -130,7 +130,8 @@ static void queueThread(void *data) { int *flag = (int *) data; - testingSleep(1250 * testingNsecPerMsec); + // TODO error check + timerSleep(1250 * timerMillisecond); uiQueueMain(queued, flag); } @@ -140,7 +141,7 @@ testingTest(QueueMain_DifferentThread) int flag = 0; thread = testingNewThread(queueThread, &flag); - timeout_uiMain(t, 5 * testingNsecPerSec, 0); + timeout_uiMain(t, 5 * timerSecond, 0); testingThreadWaitAndFree(thread); if (flag != 1) testingTErrorf(t, "uiQueueMain() didn't set flag properly: got %d, want 1", flag); @@ -150,7 +151,8 @@ static void queueOrderThread(void *data) { uint32_t *flag = (uint32_t *) data; - testingSleep(1250 * testingNsecPerMsec); + // TODO error check + timerSleep(1250 * timerMillisecond); queueOrder(flag); } @@ -160,7 +162,7 @@ testingTest(QueueMain_DifferentThreadSequence) uint32_t flag = 1; // make sure it's initialized just in case thread = testingNewThread(queueOrderThread, &flag); - timeout_uiMain(t, 5 * testingNsecPerSec, 0); + timeout_uiMain(t, 5 * timerSecond, 0); testingThreadWaitAndFree(thread); checkOrder(t, flag); } diff --git a/test/meson.build b/test/meson.build index 1faec94b..33e183e3 100644 --- a/test/meson.build +++ b/test/meson.build @@ -4,10 +4,14 @@ libui_test_sources = [ 'initmain.c', 'main.c', 'testing.c', + 'timer.c', ] if libui_OS == 'windows' - libui_test_sources += ['testing_windows.c'] + libui_test_sources += [ + 'testing_windows.c', + 'timer_windows.c', + ] elif libui_OS == 'darwin' libui_test_sources += [ 'testing_darwin.c', diff --git a/test/test.h b/test/test.h index e82015a1..8d4f8922 100644 --- a/test/test.h +++ b/test/test.h @@ -1,6 +1,7 @@ // 28 april 2019 #include "../ui.h" #include "testing.h" +#include "timer.h" // main.c extern void timeoutMain(testingT *t, void *data); diff --git a/test/testing.c b/test/testing.c index bd168b4e..978a796b 100644 --- a/test/testing.c +++ b/test/testing.c @@ -163,10 +163,9 @@ static void testsetRun(struct testset *set, int *anyFailed) testingT *t; const char *status; timerTime start, end; - char timerstr[timeDurationStringLen]; + char timerstr[timerDurationStringLen]; t = set->tests; - timer = testingNewTimer(); for (i = 0; i < set->len; i++) { printf("=== RUN %s\n", t->name); start = timerMonotonicNow(); @@ -186,7 +185,6 @@ static void testsetRun(struct testset *set, int *anyFailed) printf("--- %s: %s (%s)\n", status, t->name, timerstr); t++; } - testingFreeTimer(timer); } int testingMain(void) diff --git a/test/testing.h b/test/testing.h index edbf367f..7f374923 100644 --- a/test/testing.h +++ b/test/testing.h @@ -81,4 +81,5 @@ extern void testingprivRegisterTestAfter(const char *, void (*)(testingT *), con #define testingprivTLogvfThen(then, t, format, ap) ((testingprivTLogvfFull(t, __FILE__, __LINE__, format, ap)), (then(t))) extern void testingprivTLogfFull(testingT *, const char *, long, const char *, ...); extern void testingprivTLogvfFull(testingT *, const char *, long, const char *, va_list); +// TODO change int64_t to timerDuration extern void testingprivRunWithTimeout(testingT *, const char *, long, int64_t, void (*)(testingT *, void *), void *, const char *, int); diff --git a/test/testing_windows.c b/test/testing_windows.c index 70e9f326..037e94a4 100644 --- a/test/testing_windows.c +++ b/test/testing_windows.c @@ -15,6 +15,7 @@ #include #include #include +#include "timer.h" #include "testing.h" #include "testingpriv.h" @@ -254,7 +255,7 @@ static unsigned __stdcall timerThreadProc(void *data) void testingprivRunWithTimeout(testingT *t, const char *file, long line, int64_t timeout, void (*f)(testingT *t, void *data), void *data, const char *comment, int failNowOnError) { - char *timeoutstr; + char timeoutstr[timerDurationStringLen]; MSG msg; int closeTargetThread = 0; uintptr_t timerThread = 0; @@ -262,7 +263,7 @@ void testingprivRunWithTimeout(testingT *t, const char *file, long line, int64_t int waitForTimerThread = 0; HRESULT hr; - timeoutstr = testingNsecString(timeout); + timerDurationString(timeout, timeoutstr); // to ensure that the PostThreadMessage() above will not fail because the thread doesn't have a message queue PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); @@ -351,7 +352,6 @@ out: if (closeTargetThread) CloseHandle(timeout_targetThread); timeout_targetThread = NULL; - testingFreeNsecString(timeoutstr); if (failNowOnError) testingTFailNow(t); } diff --git a/test/timer.c b/test/timer.c index d9dc32bf..b7203397 100644 --- a/test/timer.c +++ b/test/timer.c @@ -72,7 +72,7 @@ void timerDurationString(timerDuration d, char buf[timerDurationStringLen]) int start; const struct timerStringPart *p; - memset(buf, 0, timerTimeStringLen * sizeof (char)); + memset(buf, 0, timerDurationStringLen * sizeof (char)); start = 32; if (d == 0) { diff --git a/test/timer.h b/test/timer.h index fe387b52..e992bcb7 100644 --- a/test/timer.h +++ b/test/timer.h @@ -5,10 +5,10 @@ typedef int64_t timerDuration; typedef int64_t timerTime; -#define timerNanosecond ((Duration) 1) -#define timerMicrosecond ((Duration) 1000) -#define timerMillisecond ((Duration) 1000000) -#define timerSecond ((Duration) 1000000000) +#define timerNanosecond ((timerDuration) 1) +#define timerMicrosecond ((timerDuration) 1000) +#define timerMillisecond ((timerDuration) 1000000) +#define timerSecond ((timerDuration) 1000000000) extern timerTime timerMonotonicNow(void); extern timerDuration timerTimeSub(timerTime end, timerTime start);