1 #ifndef MESHLINK_TEST_UTILS_H
2 #define MESHLINK_TEST_UTILS_H
8 #include "../src/meshlink-tiny.h"
10 // Simple synchronisation between threads
12 pthread_mutex_t mutex;
17 extern void init_sync_flag(struct sync_flag *s);
18 extern void set_sync_flag(struct sync_flag *s, bool value);
19 extern void reset_sync_flag(struct sync_flag *s);
20 extern bool check_sync_flag(struct sync_flag *s);
21 extern bool wait_sync_flag(struct sync_flag *s, int seconds);
23 /// Create a pair of meshlink instances that are already joined together.
24 extern void open_meshlink_pair(meshlink_handle_t **a, meshlink_handle_t **b, const char *prefix);
25 extern void open_meshlink_pair_ephemeral(meshlink_handle_t **a, meshlink_handle_t **b, const char *prefix);
27 /// Start a pair of meshlink instances and wait for them to connect together.
28 extern void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
29 extern void start_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b);
31 /// Stop a pair of meshlink instances.
32 extern void stop_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
33 extern void stop_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b);
35 /// Stop and cleanup a pair of meshlink instances.
36 extern void close_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
37 extern void close_full_tiny_pair(meshlink_handle_t *a, meshlink_handle_t *b);
39 /// Link two meshlink instances.
40 extern void link_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b);
42 /// Default log callback
43 extern void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text);
45 #define assert_after(cond, timeout)\
47 for(int i = 0; i++ <= timeout;) {\
58 /// Compare two timespec values.
59 static inline bool timespec_lt(const struct timespec *a, const struct timespec *b) {
60 if(a->tv_sec == b->tv_sec) {
61 return a->tv_nsec < b->tv_nsec;
63 return a->tv_sec < b->tv_sec;