diff --git a/test/main.c b/test/main.c index 3d111dbf..7f3e3dfc 100644 --- a/test/main.c +++ b/test/main.c @@ -1,18 +1,11 @@ // 10 april 2019 #include "test.h" -static void timeoutMain(testingT *t, void *data) +void timeoutMain(testingT *t, void *data) { uiMain(); } -void timeout_uiMain(testingT *t, int64_t timeout, int failNowOnError) -{ - testingRunWithTimeout(t, timeout, - timeoutMain, NULL, - "uiMain()", failNowOnError); -} - int main(void) { return testingMain(); diff --git a/test/test.h b/test/test.h index 47a255b9..e82015a1 100644 --- a/test/test.h +++ b/test/test.h @@ -3,4 +3,8 @@ #include "testing.h" // main.c -extern void timeout_uiMain(testingT *t, int64_t timeout, int failNowOnError); +extern void timeoutMain(testingT *t, void *data); +#define timeout_uiMain(t, timeout, failNowOnError) \ + testingRunWithTimeout(t, timeout, \ + timeoutMain, NULL, \ + "uiMain()", failNowOnError); diff --git a/test/testing.h b/test/testing.h index c575dcd3..3f0ee2c9 100644 --- a/test/testing.h +++ b/test/testing.h @@ -78,7 +78,8 @@ extern int64_t testingTimerNsec(testingTimer *t); extern char *testingNsecString(int64_t nsec); extern void testingFreeNsecString(char *s); -extern void testingRunWithTimeout(testingT *t, int64_t timeout, void (*f)(testingT *t, void *data), void *data, const char *comment, int failNowOnError); +#define testingRunWithTimeout(t, timeout, f, data, comment, failNowOnError) \ + testingprivRunWithTimeout(t, __FILE__, __LINE__, timeout, f, data, comment, failNowOnError) extern void testingprivRegisterTest(const char *, void (*)(testingT *), const char *, long); extern void testingprivRegisterTestBefore(const char *, void (*)(testingT *), const char *, long); @@ -89,3 +90,4 @@ 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); +extern void testingprivRunWithTimeout(testingT *, const char *, long, int64_t, void (*)(testingT *, void *), void *, const char *, int); diff --git a/test/testing_darwinunix.c b/test/testing_darwinunix.c index f004ed0a..94ae9bf9 100644 --- a/test/testing_darwinunix.c +++ b/test/testing_darwinunix.c @@ -14,7 +14,7 @@ static void onTimeout(int sig) longjmp(timeout_ret, 1); } -void testingRunWithTimeout(testingT *t, int64_t timeout, void (*f)(testingT *t, void *data), void *data, const char *comment, int failNowOnError) +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; sig_t prevsig; @@ -30,15 +30,18 @@ void testingRunWithTimeout(testingT *t, int64_t timeout, void (*f)(testingT *t, timer.it_value.tv_usec = (timeout % testingNsecPerSec) / testingNsecPerUsec; if (setitimer(ITIMER_REAL, &timer, &prevtimer) != 0) { setitimerError = errno; - testingTErrorf(t, "error applying %s timeout: %s", comment, strerror(setitimerError)); + testingprivTLogfFull(t, file, line, "error applying %s timeout: %s", comment, strerror(setitimerError)); + testingTFail(t); goto out; } if (setjmp(timeout_ret) == 0) { (*f)(t, data); failNowOnError = 0; // we succeeded - } else - testingTErrorf(t, "%s timeout passed (%s)", comment, timeoutstr); + } else { + testingprivTLogfFull(t, file, line, "%s timeout passed (%s)", comment, timeoutstr); + testingTFail(t); + } out: if (setitimerError == 0)