mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 03:00:20 +01:00
shared/tests: add nmtst_main_context_iterate_until_full() helper
(cherry picked from commit230250e629) (cherry picked from commit20cfc1f395) (cherry picked from commitc6666589a8) (cherry picked from commitfa82b66327) (cherry picked from commit08a8b757a3)
This commit is contained in:
parent
7a9af7213b
commit
96b63d3fee
1 changed files with 32 additions and 10 deletions
|
|
@ -1051,19 +1051,32 @@ _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(context, timeout_msec, condition) \
|
||||
#define nmtst_main_context_iterate_until_full(context, timeout_msec, poll_msec, condition) \
|
||||
({ \
|
||||
nm_auto_destroy_and_unref_gsource GSource *_source = NULL; \
|
||||
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 (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 (_timeout_msec0, ==, _timeout_msec); \
|
||||
g_assert_cmpint (_poll_msec0, ==, _poll_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); \
|
||||
_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) \
|
||||
|
|
@ -1076,12 +1089,21 @@ _nmtst_main_loop_quit_on_notify (GObject *object, GParamSpec *pspec, gpointer us
|
|||
!_had_timeout; \
|
||||
})
|
||||
|
||||
#define nmtst_main_context_iterate_until_assert(context, timeout_msec, 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 (context, timeout_msec, condition)) \
|
||||
g_assert (FALSE && #condition); \
|
||||
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 const char *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue