Fixed bad timers on GTK+ tests. Turns out that clock() doesn't count when the process isn't actively running code (for instance, if it's waiting for I/O) :|
This commit is contained in:
parent
74468bb38f
commit
3257710fb7
|
@ -42,6 +42,15 @@ if libui_OS == 'windows'
|
||||||
required: true),
|
required: true),
|
||||||
]
|
]
|
||||||
endif
|
endif
|
||||||
|
elif libui_OS == 'darwin'
|
||||||
|
# do nothing
|
||||||
|
else
|
||||||
|
libui_test_deps += [
|
||||||
|
# satisfy old versions of glibc
|
||||||
|
# TODO is this really needed?
|
||||||
|
meson.get_compiler('c').find_library('rt',
|
||||||
|
required: false),
|
||||||
|
]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# TODO once we upgrade to 0.49.0, add pie: true
|
# TODO once we upgrade to 0.49.0, add pie: true
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
|
||||||
// TODO testingTimers after this fails are wrong on GTK+
|
|
||||||
// TODO don't start the timer on any platform until after we call setjmp(); also decide whether to start the timer before or after resuming the thread on Windows
|
// TODO don't start the timer on any platform until after we call setjmp(); also decide whether to start the timer before or after resuming the thread on Windows
|
||||||
|
|
||||||
static jmp_buf timeout_ret;
|
static jmp_buf timeout_ret;
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
|
||||||
struct testingTimer {
|
struct testingTimer {
|
||||||
clock_t start;
|
struct timespec start;
|
||||||
clock_t end;
|
struct timespec end;
|
||||||
};
|
};
|
||||||
|
|
||||||
testingTimer *testingNewTimer(void)
|
testingTimer *testingNewTimer(void)
|
||||||
|
@ -26,34 +26,24 @@ void testingFreeTimer(testingTimer *t)
|
||||||
|
|
||||||
void testingTimerStart(testingTimer *t)
|
void testingTimerStart(testingTimer *t)
|
||||||
{
|
{
|
||||||
t->start = clock();
|
// TODO check errors
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &(t->start));
|
||||||
}
|
}
|
||||||
|
|
||||||
void testingTimerEnd(testingTimer *t)
|
void testingTimerEnd(testingTimer *t)
|
||||||
{
|
{
|
||||||
t->end = clock();
|
// TODO check errors
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &(t->end));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO replace with proper subtraction code
|
||||||
int64_t testingTimerNsec(testingTimer *t)
|
int64_t testingTimerNsec(testingTimer *t)
|
||||||
{
|
{
|
||||||
clock_t c;
|
int64_t nstart, nend;
|
||||||
clock_t sec;
|
|
||||||
int64_t sec64;
|
|
||||||
clock_t subsec;
|
|
||||||
double subsecf;
|
|
||||||
int64_t subsec64;
|
|
||||||
|
|
||||||
c = t->end - t->start;
|
nstart = ((int64_t) (t->start.tv_sec)) * testingNsecPerSec;
|
||||||
|
nstart += t->start.tv_nsec;
|
||||||
sec = c / CLOCKS_PER_SEC;
|
nend = ((int64_t) (t->end.tv_sec)) * testingNsecPerSec;
|
||||||
sec64 = (int64_t) sec;
|
nend += t->end.tv_nsec;
|
||||||
sec64 *= testingNsecPerSec;
|
return nend - nstart;
|
||||||
|
|
||||||
subsec = c % CLOCKS_PER_SEC;
|
|
||||||
subsecf = (double) subsec;
|
|
||||||
subsecf /= CLOCKS_PER_SEC;
|
|
||||||
subsecf *= testingNsecPerSec;
|
|
||||||
subsec64 = (int64_t) subsecf;
|
|
||||||
|
|
||||||
return sec64 + subsec64;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue