]> git.meshlink.io Git - meshlink/blob - test/utils.h
488721dd37af86748e9642879cad1da8588725d9
[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);
14 extern bool wait_sync_flag(struct sync_flag *s, int seconds);
15
16 /// Create a pair of meshlink instances that are already joined together.
17 extern void open_meshlink_pair(meshlink_handle_t **a, meshlink_handle_t **b, const char *prefix);
18
19 /// Start a pair of meshlink instances and wait for them to connect together.
20 extern void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
21
22 /// Stop a pair of meshlink instances.
23 extern void stop_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
24
25 /// Stop and cleanup a pair of meshlink instances.
26 extern void close_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b, const char *prefix);
27
28 #define assert_after(cond, timeout) do {\
29         for(int i = 0; i++ <= timeout;) {\
30                 if(cond)\
31                         break;\
32                 if(i == timeout)\
33                         assert(cond);\
34                 sleep(1);\
35         }\
36 } while(0);
37
38 #endif