summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-11-02 15:25:30 +0100
committerThomas Haller <thaller@redhat.com>2019-11-07 11:34:36 +0100
commit88ef02ec332b6dc1e94f4831ecb5f2e2d0c68033 (patch)
tree2bbd8ce5a55c49f5b96ac4d454ec77fc28c1637d
parentafa54fdfd530392c1c50d578d5366b999a60eef1 (diff)
downloadNetworkManager-88ef02ec332b6dc1e94f4831ecb5f2e2d0c68033.tar.gz
shared/tests: add nmtst_main_context_iterate_until() helper
-rw-r--r--shared/nm-utils/nm-test-utils.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h
index d4b9578ad1..f0ea11790d 100644
--- a/shared/nm-utils/nm-test-utils.h
+++ b/shared/nm-utils/nm-test-utils.h
@@ -1010,6 +1010,34 @@ _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)
+static inline gboolean
+_nmtst_main_context_iterate_until_timeout (gpointer user_data)
+{
+ gboolean *p_had_pointer = user_data;
+
+ g_assert (!*p_had_pointer);
+ *p_had_pointer = TRUE;
+ return G_SOURCE_CONTINUE;
+}
+
+#define nmtst_main_context_iterate_until(context, timeout_ms, condition) \
+ G_STMT_START { \
+ nm_auto_destroy_and_unref_gsource GSource *_source = NULL; \
+ GMainContext *_context = (context); \
+ gboolean _had_timeout = FALSE; \
+ \
+ _source = g_timeout_source_new (timeout_ms); \
+ g_source_set_callback (_source, _nmtst_main_context_iterate_until_timeout, &_had_timeout, NULL); \
+ g_source_attach (_source, _context); \
+ \
+ while (TRUE) { \
+ if (condition) \
+ break; \
+ g_main_context_iteration (_context, TRUE); \
+ g_assert (!_had_timeout && #condition); \
+ } \
+ } G_STMT_END
+
/*****************************************************************************/
static inline const char *