File: uv.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 (77 lines) | stat: -rw-r--r-- 2,683 bytes parent folder | download | duplicates (6)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * Add support for using the libuv loop in tests.
 */

#ifndef TEST_UV_H
#define TEST_UV_H

#include <uv.h>

#include "munit.h"

/* Max n. of loop iterations ran by a single function call */
#define TEST_UV_MAX_LOOP_RUN 10

/**
 * Initialize the given libuv loop.
 */
void test_uv_setup(const MunitParameter params[], struct uv_loop_s *l);

/**
 * Run the loop until there are no pending active handles.
 *
 * If there are still pending active handles after 10 loop iterations, the test
 * will fail.
 *
 * This is meant to be used in tear down functions.
 */
void test_uv_stop(struct uv_loop_s *l);

/**
 * Tear down the loop making sure no active handles are left.
 */
void test_uv_tear_down(struct uv_loop_s *l);

/**
 * Run the loop until there are no pending active handles or the given amount of
 * iterations is reached.
 *
 * Return non-zero if there are pending handles.
 */
int test_uv_run(struct uv_loop_s *l, unsigned n);

/**
 * Run the loop until the given function returns true.
 *
 * If the loop exhausts all active handles or if #TEST_UV_MAX_LOOP_RUN is
 * reached without @f returning #true, the test fails.
 */
#define test_uv_run_until(DATA, FUNC)                                        \
	{                                                                    \
		unsigned i;                                                  \
		int rv;                                                      \
		for (i = 0; i < TEST_UV_MAX_LOOP_RUN; i++) {                 \
			if (FUNC(DATA)) {                                    \
				break;                                       \
			}                                                    \
			rv = uv_run(&f->loop, UV_RUN_ONCE);                  \
			if (rv < 0) {                                        \
				munit_errorf("uv_run: %s", uv_strerror(rv)); \
			}                                                    \
			if (rv == 0) {                                       \
				if (FUNC(DATA)) {                            \
					break;                               \
				}                                            \
				munit_errorf(                                \
				    "uv_run: stopped after %u iterations",   \
				    i + 1);                                  \
			}                                                    \
		}                                                            \
		if (i == TEST_UV_MAX_LOOP_RUN) {                             \
			munit_errorf(                                        \
			    "uv_run: condition not met in %d iterations",    \
			    TEST_UV_MAX_LOOP_RUN);                           \
		}                                                            \
	}

#endif /* TEST_UV_H */