File: util.h

package info (click to toggle)
dqlite 1.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,372 kB
  • sloc: ansic: 57,583; makefile: 336; sh: 243
file content (27 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
 * Utility macros and functions.
 */

#ifndef TEST_UTIL_H
#define TEST_UTIL_H

#include "munit.h"

#include <time.h>

/* Wait a bounded time in seconds until a condition is true. */
#define AWAIT_TRUE(FN, ARG, SEC)                                            \
	do {                                                                \
		struct timespec _start = {0};                               \
		struct timespec _end = {0};                                 \
		clock_gettime(CLOCK_MONOTONIC, &_start);                    \
		clock_gettime(CLOCK_MONOTONIC, &_end);                      \
		while (!FN(ARG) && ((_end.tv_sec - _start.tv_sec) < SEC)) { \
			clock_gettime(CLOCK_MONOTONIC, &_end);              \
		}                                                           \
		if (!FN(ARG)) {                                             \
			return MUNIT_FAIL;                                  \
		}                                                           \
	} while (0)

#endif /* TEST_UTIL_H */