Skip to content

Commit 84801ba

Browse files
authored
Add tests for clock, times, and getrusage. (#177)
1 parent 04293e5 commit 84801ba

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/general/clocks.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <time.h>
2+
#include <sys/resource.h>
3+
#include <sys/times.h>
4+
#include <assert.h>
5+
6+
static void test_clock(void) {
7+
clock_t a = clock();
8+
clock_t b = clock();
9+
assert(a != -1);
10+
assert(b != -1);
11+
assert(a > 0);
12+
assert(b >= a);
13+
}
14+
15+
static void test_times(void) {
16+
struct tms before;
17+
struct tms after;
18+
clock_t a = times(&before);
19+
clock_t b = times(&after);
20+
assert(a != -1);
21+
assert(b != -1);
22+
assert(b >= a);
23+
assert(after.tms_utime >= before.tms_utime);
24+
}
25+
26+
static void test_getrusage(void) {
27+
struct rusage before;
28+
struct rusage after;
29+
int a = getrusage(RUSAGE_SELF, &before);
30+
int b = getrusage(RUSAGE_SELF, &after);
31+
assert(a != -1);
32+
assert(b != -1);
33+
assert(after.ru_utime.tv_sec >= before.ru_utime.tv_sec);
34+
assert(after.ru_utime.tv_sec != before.ru_utime.tv_sec ||
35+
after.ru_utime.tv_usec >= before.ru_utime.tv_usec);
36+
}
37+
38+
int main(void) {
39+
test_clock();
40+
test_times();
41+
test_getrusage();
42+
return 0;
43+
}

tests/general/clocks.c.options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-D_WASI_EMULATED_PROCESS_CLOCKS -lwasi-emulated-process-clocks

0 commit comments

Comments
 (0)