X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=test%2Futils.c;h=c526ff0ddbcd7d17ecbf59305f18a7d05544484a;hb=4b6c01b1d5383b1a7417244a31ad4652aab2d5db;hp=f7dd3b3caff93aa037bbb3d5eaae53e43c1b1061;hpb=3e671a6a114a31ca1e6bbd0d13921637ee7ce1b5;p=meshlink diff --git a/test/utils.c b/test/utils.c index f7dd3b3c..c526ff0d 100644 --- a/test/utils.c +++ b/test/utils.c @@ -1,5 +1,9 @@ #define _GNU_SOURCE 1 +#ifdef NDEBUG +#undef NDEBUG +#endif + #include #include #include @@ -9,18 +13,23 @@ #include "utils.h" +void init_sync_flag(struct sync_flag *s) { + assert(pthread_mutex_init(&s->mutex, NULL) == 0); + assert(pthread_cond_init(&s->cond, NULL) == 0); +} + void set_sync_flag(struct sync_flag *s, bool value) { - pthread_mutex_lock(&s->mutex); + assert(pthread_mutex_lock(&s->mutex) == 0); s->flag = value; - pthread_cond_broadcast(&s->cond); - pthread_mutex_unlock(&s->mutex); + assert(pthread_cond_broadcast(&s->cond) == 0); + assert(pthread_mutex_unlock(&s->mutex) == 0); } bool check_sync_flag(struct sync_flag *s) { bool flag; - pthread_mutex_lock(&s->mutex); + assert(pthread_mutex_lock(&s->mutex) == 0); flag = s->flag; - pthread_mutex_unlock(&s->mutex); + assert(pthread_mutex_unlock(&s->mutex) == 0); return flag; } @@ -29,7 +38,7 @@ bool wait_sync_flag(struct sync_flag *s, int seconds) { clock_gettime(CLOCK_REALTIME, &timeout); timeout.tv_sec += seconds; - pthread_mutex_lock(&s->mutex); + assert(pthread_mutex_lock(&s->mutex) == 0); while(!s->flag) { if(!pthread_cond_timedwait(&s->cond, &s->mutex, &timeout) || errno != EINTR) { @@ -37,7 +46,7 @@ bool wait_sync_flag(struct sync_flag *s, int seconds) { } } - pthread_mutex_unlock(&s->mutex); + assert(pthread_mutex_unlock(&s->mutex) == 0); return s->flag; } @@ -45,8 +54,8 @@ bool wait_sync_flag(struct sync_flag *s, int seconds) { void link_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) { // Import and export both side's data - meshlink_add_address(a, "localhost"); - meshlink_add_address(b, "localhost"); + assert(meshlink_set_canonical_address(a, meshlink_get_self(a), "localhost", NULL)); + assert(meshlink_set_canonical_address(b, meshlink_get_self(b), "localhost", NULL)); char *data = meshlink_export(a); assert(data); @@ -104,6 +113,7 @@ static void pair_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) { struct sync_flag pair_status = {.flag = false}; + init_sync_flag(&pair_status); a->priv = &pair_status; meshlink_set_node_status_cb(a, pair_status_cb);