]> git.meshlink.io Git - meshlink/blob - test/utils.h
27bb38c3fe9e20a8abae834c1d802d941daee2a2
[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 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)\
29         do {\
30                 for(int i = 0; i++ <= timeout;) {\
31                         if(cond)\
32                                 break;\
33                         if(i == timeout)\
34                                 assert(cond);\
35                         sleep(1);\
36                 }\
37         } while(0)
38 #endif