From 5eb4dfe7ab777dc5ab07aa9f66e61097725826ae Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 10 Dec 2016 14:53:14 +0100 Subject: [PATCH] platform/tests: add nmtstp_netns_select_random() util --- src/platform/tests/test-common.c | 19 +++++++++++++++++++ src/platform/tests/test-common.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index f23cec4606..860e6b7caa 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -1554,6 +1554,25 @@ nmtstp_namespace_get_fd_for_process (pid_t pid, const char *ns_name) /*****************************************************************************/ +void +nmtstp_netns_select_random (NMPlatform **platforms, gsize n_platforms, NMPNetns **netns) +{ + int i; + + g_assert (platforms); + g_assert (n_platforms && n_platforms <= G_MAXINT32); + g_assert (netns && !*netns); + for (i = 0; i < n_platforms; i++) + g_assert (NM_IS_PLATFORM (platforms[i])); + + i = nmtst_get_rand_int () % (n_platforms + 1); + if (i == 0) + return; + g_assert (nm_platform_netns_push (platforms[i - 1], netns)); +} + +/*****************************************************************************/ + NMTST_DEFINE(); static gboolean diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h index a9f4959091..48a41de63a 100644 --- a/src/platform/tests/test-common.h +++ b/src/platform/tests/test-common.h @@ -53,6 +53,10 @@ int nmtstp_namespace_get_fd_for_process (pid_t pid, const char *ns_name); /*****************************************************************************/ +void nmtstp_netns_select_random (NMPlatform **platforms, gsize n_platforms, NMPNetns **netns); + +/*****************************************************************************/ + typedef struct { gulong handler_id; const char *name;