From 998772805cf393c5855320c7121ba2df8935e8b1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 26 Nov 2015 23:26:00 +0100 Subject: [PATCH] nmtst: refactor NMTST_BUSY_WAIT() and rename to NMTST_WAIT*() --- include/nm-test-utils.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 09ba64276..43d5604ca 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -128,16 +128,26 @@ nmtst_assert_error (GError *error, } } -#define NMTST_BUSY_WAIT(max_wait_ms, condition, wait) \ - G_STMT_START { \ +#define NMTST_WAIT(max_wait_ms, wait) \ + ({ \ + gboolean _not_expired = TRUE; \ gint64 _nmtst_end, _nmtst_max_wait_us = (max_wait_ms) * 1000L; \ \ _nmtst_end = g_get_monotonic_time () + _nmtst_max_wait_us; \ - while (!(condition)) { \ + while (TRUE) { \ { wait }; \ - if (g_get_monotonic_time () > _nmtst_end) \ - g_assert_not_reached (); \ + if (g_get_monotonic_time () > _nmtst_end) { \ + _not_expired = FALSE; \ + break; \ + } \ } \ + _not_expired; \ + }) + +#define NMTST_WAIT_ASSERT(max_wait_ms, wait) \ + G_STMT_START { \ + if (!(NMTST_WAIT (max_wait_ms, wait))) \ + g_assert_not_reached (); \ } G_STMT_END inline static void