Fixed the timer functions on Windows.

This commit is contained in:
Pietro Gagliardi 2019-05-02 22:03:57 -04:00
parent 42623f92e9
commit 313f5864f5
8 changed files with 24 additions and 18 deletions

View File

@ -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);
}

View File

@ -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',

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -15,6 +15,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}

View File

@ -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) {

View File

@ -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);