Debian Codegraph @

test/lib/util.h

raw
1 /**
2 * Utility macros and functions.
3 */
4
5 #ifndef TEST_UTIL_H
6 #define TEST_UTIL_H
7
8 #include "munit.h"
9
10 #include <time.h>
11
12 /* Wait a bounded time in seconds until a condition is true. */
13 #define AWAIT_TRUE(FN, ARG, SEC) \
14 do { \
15 struct timespec _start = {0}; \
16 struct timespec _end = {0}; \
17 clock_gettime(CLOCK_MONOTONIC, &_start); \
18 clock_gettime(CLOCK_MONOTONIC, &_end); \
19 while (!FN(ARG) && ((_end.tv_sec - _start.tv_sec) < SEC)) { \
20 clock_gettime(CLOCK_MONOTONIC, &_end); \
21 } \
22 if (!FN(ARG)) { \
23 return MUNIT_FAIL; \
24 } \
25 } while (0)
26
27 #endif /* TEST_UTIL_H */