X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Futils.h;h=3576df594a70db81f7b3bfda871ba518f50051b8;hb=cb2c4617316df5b467c6a76bf118ee65f6e1c3a2;hp=e1073df8f7e8468c1ee0936dc7d0c0c6323c912f;hpb=6bf3ea32f0afa91f1fed494542e873ca6abca9c9;p=meshlink diff --git a/test/utils.h b/test/utils.h index e1073df8..3576df59 100644 --- a/test/utils.h +++ b/test/utils.h @@ -1,6 +1,9 @@ #ifndef MESHLINK_TEST_UTILS_H #define MESHLINK_TEST_UTILS_H +#include +#include + #include "../src/meshlink.h" // Simple synchronisation between threads @@ -10,7 +13,8 @@ struct sync_flag { bool flag; }; -extern void set_sync_flag(struct sync_flag *s); +extern void set_sync_flag(struct sync_flag *s, bool value); +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. @@ -23,7 +27,32 @@ extern void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); extern void stop_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); /// Stop and cleanup a pair of meshlink instances. -extern void close_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b, const char *prefix); +extern void close_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); + +/// Link two meshlink instances. +extern void link_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b); + +/// Default log callback +extern void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text); + +#define assert_after(cond, timeout)\ + do {\ + for(int i = 0; i++ <= timeout;) {\ + if(cond)\ + break;\ + if(i == timeout)\ + assert(cond);\ + sleep(1);\ + }\ + } while(0) #endif +/// Compare two timespec values. +static 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; + } +}