X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Futils.h;h=110c50a6a1a5448d8a0c91a4d69e37e899139225;hb=HEAD;hp=bce2f9a5cc1e1a37fbca7b8d85292ad73e6f6c76;hpb=9a2520c36431a8a5fd90451e97f488c22f4decc5;p=meshlink diff --git a/test/utils.h b/test/utils.h index bce2f9a5..11facfc3 100644 --- a/test/utils.h +++ b/test/utils.h @@ -1,6 +1,10 @@ #ifndef MESHLINK_TEST_UTILS_H #define MESHLINK_TEST_UTILS_H +#include +#include +#include + #include "../src/meshlink.h" // Simple synchronisation between threads @@ -10,12 +14,15 @@ struct sync_flag { bool flag; }; +extern void init_sync_flag(struct sync_flag *s); extern void set_sync_flag(struct sync_flag *s, bool value); +extern void reset_sync_flag(struct sync_flag *s); extern bool check_sync_flag(struct sync_flag *s); extern bool wait_sync_flag(struct sync_flag *s, int seconds); /// Create a pair of meshlink instances that are already joined together. extern void open_meshlink_pair(meshlink_handle_t **a, meshlink_handle_t **b, const char *prefix); +extern void open_meshlink_pair_ephemeral(meshlink_handle_t **a, meshlink_handle_t **b, const char *prefix); /// Start a pair of meshlink instances and wait for them to connect together. extern void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); @@ -44,3 +51,12 @@ extern void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const ch } while(0) #endif + +/// Compare two timespec values. +static inline bool timespec_lt(const struct timespec *a, const struct timespec *b) { + if(a->tv_sec == b->tv_sec) { + return a->tv_nsec < b->tv_nsec; + } else { + return a->tv_sec < b->tv_sec; + } +}