Debian Codegraph @

src/util/test-nsec.c

raw
1 /*
2 * Test nanosecond time management
3 */
4
5 #undef NDEBUG
6 #include <c-stdaux.h>
7 #include <stdlib.h>
8 #include "util/nsec.h"
9
10 static void test_nsec(void) {
11 nsec_t n0, n1, n2;
12
13 n0 = nsec_now(CLOCK_MONOTONIC);
14 c_assert(n0 > 0);
15
16 n1 = n0 + 8000;
17 nsec_sleep(CLOCK_MONOTONIC, n1);
18
19 n2 = nsec_now(CLOCK_MONOTONIC);
20 c_assert(n2 > 0);
21 c_assert(n2 > n0);
22 c_assert(n2 - n0 >= 8000);
23 }
24
25 int main(int argc, char **argv) {
26 test_nsec();
27 return 0;
28 }