diff --git a/tests/general/clocks.c b/tests/general/clocks.c new file mode 100644 index 0000000..36908e5 --- /dev/null +++ b/tests/general/clocks.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +static void test_clock(void) { + clock_t a = clock(); + clock_t b = clock(); + assert(a != -1); + assert(b != -1); + assert(a > 0); + assert(b >= a); +} + +static void test_times(void) { + struct tms before; + struct tms after; + clock_t a = times(&before); + clock_t b = times(&after); + assert(a != -1); + assert(b != -1); + assert(b >= a); + assert(after.tms_utime >= before.tms_utime); +} + +static void test_getrusage(void) { + struct rusage before; + struct rusage after; + int a = getrusage(RUSAGE_SELF, &before); + int b = getrusage(RUSAGE_SELF, &after); + assert(a != -1); + assert(b != -1); + assert(after.ru_utime.tv_sec >= before.ru_utime.tv_sec); + assert(after.ru_utime.tv_sec != before.ru_utime.tv_sec || + after.ru_utime.tv_usec >= before.ru_utime.tv_usec); +} + +int main(void) { + test_clock(); + test_times(); + test_getrusage(); + return 0; +} diff --git a/tests/general/clocks.c.options b/tests/general/clocks.c.options new file mode 100644 index 0000000..03953a9 --- /dev/null +++ b/tests/general/clocks.c.options @@ -0,0 +1 @@ +-D_WASI_EMULATED_PROCESS_CLOCKS -lwasi-emulated-process-clocks