From 108aa30f2eadf0f6ef0041376033733bb14a063f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 4 Jan 2020 08:40:19 +0100 Subject: [PATCH] shared/tests: add nmtst_main_context_iterate_until() helper Like nmtst_main_context_iterate_until_assert(), but allows to run into timeout. (cherry picked from commit f2baa10bb8b0f7d4a00312bf6fa55f9bab027a14) (cherry picked from commit 3e41eb83f755d1cb3c144c8d05ef0224062909f0) (cherry picked from commit 6237d89cf164579eaa0d7811a43c8967d2e01c59) --- shared/nm-utils/nm-test-utils.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 6d39ec87e4..2b52792f05 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1046,8 +1046,8 @@ _nmtst_main_loop_quit_on_notify (GObject *object, GParamSpec *pspec, gpointer us } #define nmtst_main_loop_quit_on_notify ((GCallback) _nmtst_main_loop_quit_on_notify) -#define nmtst_main_context_iterate_until_assert(context, timeout_msec, condition) \ - G_STMT_START { \ +#define nmtst_main_context_iterate_until(context, timeout_msec, condition) \ + ({ \ nm_auto_destroy_and_unref_gsource GSource *_source = NULL; \ GMainContext *_context = (context); \ gboolean _had_timeout = FALSE; \ @@ -1060,8 +1060,17 @@ _nmtst_main_loop_quit_on_notify (GObject *object, GParamSpec *pspec, gpointer us if (condition) \ break; \ g_main_context_iteration (_context, TRUE); \ - g_assert (!_had_timeout && #condition); \ + if (_had_timeout) \ + break; \ } \ + \ + !_had_timeout; \ + }) + +#define nmtst_main_context_iterate_until_assert(context, timeout_msec, condition) \ + G_STMT_START { \ + if (!nmtst_main_context_iterate_until (context, timeout_msec, condition)) \ + g_assert (FALSE && #condition); \ } G_STMT_END /*****************************************************************************/