]> git.meshlink.io Git - meshlink/blob - test/utils.h
Refactor the non-blackbox test suite.
[meshlink] / test / utils.h
1 #ifndef MESHLINK_TEST_UTILS_H
2 #define MESHLINK_TEST_UTILS_H
3
4 #include "../src/meshlink.h"
5
6 // Simple synchronisation between threads
7 struct sync_flag {
8         pthread_mutex_t mutex;
9         pthread_cond_t cond;
10         bool flag;
11 };
12
13 extern void set_sync_flag(struct sync_flag *s, bool value);
14 extern bool check_sync_flag(struct sync_flag *s);
15 extern bool wait_sync_flag(struct sync_flag *s, int seconds);
16
17 /// Create a pair of meshlink instances that are already joined together.
18 extern void open_meshlink_pair(meshlink_handle_t **a, meshlink_handle_t **b, const char *prefix);
19
20 /// Start a pair of meshlink instances and wait for them to connect together.
21 extern void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
22
23 /// Stop a pair of meshlink instances.
24 extern void stop_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
25
26 /// Stop and cleanup a pair of meshlink instances.
27 extern void close_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
28
29 /// Link two meshlink instances.
30 extern void link_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
31
32 /// Default log callback
33 extern void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text);
34
35 #define assert_after(cond, timeout)\
36         do {\
37                 for(int i = 0; i++ <= timeout;) {\
38                         if(cond)\
39                                 break;\
40                         if(i == timeout)\
41                                 assert(cond);\
42                         sleep(1);\
43                 }\
44         } while(0)
45
46 #endif