diff options
author | Thomas Haller <thaller@redhat.com> | 2020-11-02 12:55:24 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-11-03 14:31:20 +0100 |
commit | 230250e62900be4ba71f90c391e25638f476125e (patch) | |
tree | dbf6ceb62618932f59e5f5449abfe293a672c095 | |
parent | ca2b79d9aa9999bdb09b31599a4bd942122b282e (diff) | |
download | NetworkManager-230250e62900be4ba71f90c391e25638f476125e.tar.gz |
shared/tests: add nmtst_main_context_iterate_until_full() helper
-rw-r--r-- | shared/nm-utils/nm-test-utils.h | 80 |
1 files changed, 51 insertions, 29 deletions
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index a6a5c5d171..42b584c982 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1206,39 +1206,61 @@ _nmtst_main_loop_quit_on_notify(GObject *object, GParamSpec *pspec, gpointer use } #define nmtst_main_loop_quit_on_notify ((GCallback) _nmtst_main_loop_quit_on_notify) -#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; \ - typeof(timeout_msec) _timeout_msec0 = (timeout_msec); \ - gint64 _timeout_msec = _timeout_msec0; \ - \ - g_assert_cmpint(_timeout_msec0, ==, _timeout_msec); \ - \ - _source = g_timeout_source_new(NM_CLAMP(_timeout_msec, 0, (gint64) G_MAXUINT)); \ - g_source_set_callback(_source, nmtst_g_source_set_boolean_true, &_had_timeout, NULL); \ - g_source_attach(_source, _context); \ - \ - while (TRUE) { \ - if (condition) \ - break; \ - g_main_context_iteration(_context, TRUE); \ - if (_had_timeout) \ - break; \ - } \ - \ - !_had_timeout; \ +#define nmtst_main_context_iterate_until_full(context, timeout_msec, poll_msec, condition) \ + ({ \ + nm_auto_destroy_and_unref_gsource GSource *_source_timeout = NULL; \ + nm_auto_destroy_and_unref_gsource GSource *_source_poll = NULL; \ + GMainContext * _context = (context); \ + gboolean _had_timeout = FALSE; \ + typeof(timeout_msec) _timeout_msec0 = (timeout_msec); \ + typeof(poll_msec) _poll_msec0 = (poll_msec); \ + gint64 _timeout_msec = _timeout_msec0; \ + guint _poll_msec = _poll_msec0; \ + \ + g_assert_cmpint(_timeout_msec0, ==, _timeout_msec); \ + g_assert_cmpint(_poll_msec0, ==, _poll_msec); \ + \ + _source_timeout = g_timeout_source_new(NM_CLAMP(_timeout_msec, 0, (gint64) G_MAXUINT)); \ + g_source_set_callback(_source_timeout, \ + nmtst_g_source_set_boolean_true, \ + &_had_timeout, \ + NULL); \ + g_source_attach(_source_timeout, _context); \ + \ + if (_poll_msec > 0) { \ + _source_poll = g_timeout_source_new(_poll_msec); \ + g_source_set_callback(_source_poll, nmtst_g_source_nop, NULL, NULL); \ + g_source_attach(_source_poll, _context); \ + } \ + \ + while (TRUE) { \ + if (condition) \ + break; \ + g_main_context_iteration(_context, TRUE); \ + 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); \ - } \ +#define nmtst_main_context_iterate_until(context, timeout_msec, condition) \ + nmtst_main_context_iterate_until_full((context), (timeout_msec), 0, condition) + +#define nmtst_main_context_iterate_until_assert_full(context, timeout_msec, poll_msec, condition) \ + G_STMT_START \ + { \ + if (!nmtst_main_context_iterate_until_full((context), \ + (timeout_msec), \ + (poll_msec), \ + condition)) \ + g_assert(FALSE &&#condition); \ + } \ G_STMT_END +#define nmtst_main_context_iterate_until_assert(context, timeout_msec, condition) \ + nmtst_main_context_iterate_until_assert_full((context), (timeout_msec), 0, condition) + /*****************************************************************************/ static inline void |