platform/tests: pass platform argument to nmtstp helper functions

Make the test helper independent from the platform singleton instance.
That way, we can also use them for other platform instances (e.g. in a
different namespace).
This commit is contained in:
Thomas Haller 2016-03-14 15:23:05 +01:00
parent 9995699116
commit ad345cdf7d
6 changed files with 90 additions and 83 deletions

View file

@ -41,8 +41,8 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data)
{ {
/* create veth pair. */ /* create veth pair. */
nmtstp_run_command_check ("ip link add dev %s type veth peer name %s", IFACE_VETH0, IFACE_VETH1); nmtstp_run_command_check ("ip link add dev %s type veth peer name %s", IFACE_VETH0, IFACE_VETH1);
fixture->ifindex0 = nmtstp_assert_wait_for_link (IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex; fixture->ifindex0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex;
fixture->ifindex1 = nmtstp_assert_wait_for_link (IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex; fixture->ifindex1 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex;
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex0, NULL)); g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex0, NULL));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex1, NULL)); g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex1, NULL));

View file

@ -367,7 +367,7 @@ _test_recv_fixture_setup (TestRecvFixture *fixture, gconstpointer user_data)
g_assert (ioctl (s, SIOCSIFFLAGS, &ifr) >= 0); g_assert (ioctl (s, SIOCSIFFLAGS, &ifr) >= 0);
close (s); close (s);
link = nmtstp_assert_wait_for_link (TEST_IFNAME, NM_LINK_TYPE_TAP, 100); link = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, TEST_IFNAME, NM_LINK_TYPE_TAP, 100);
fixture->ifindex = link->ifindex; fixture->ifindex = link->ifindex;
fixture->fd = fd; fixture->fd = fd;
memcpy (fixture->mac, link->addr.data, ETH_ALEN); memcpy (fixture->mac, link->addr.data, ETH_ALEN);

View file

@ -338,30 +338,32 @@ _wait_for_signal_timeout (gpointer user_data)
} }
gboolean gboolean
nmtstp_wait_for_signal (guint timeout_ms) nmtstp_wait_for_signal (NMPlatform *platform, guint timeout_ms)
{ {
WaitForSignalData data = { 0 }; WaitForSignalData data = { 0 };
gulong id_link, id_ip4_address, id_ip6_address, id_ip4_route, id_ip6_route; gulong id_link, id_ip4_address, id_ip6_address, id_ip4_route, id_ip6_route;
if (!platform)
platform = NM_PLATFORM_GET;
data.loop = g_main_loop_new (NULL, FALSE); data.loop = g_main_loop_new (NULL, FALSE);
id_link = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); id_link = g_signal_connect (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
id_ip4_address = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); id_ip4_address = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
id_ip6_address = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); id_ip6_address = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
id_ip4_route = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); id_ip4_route = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
id_ip6_route = g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); id_ip6_route = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data);
if (timeout_ms != 0) if (timeout_ms != 0)
data.id = g_timeout_add (timeout_ms, _wait_for_signal_timeout, &data); data.id = g_timeout_add (timeout_ms, _wait_for_signal_timeout, &data);
g_main_loop_run (data.loop); g_main_loop_run (data.loop);
g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_link)); g_assert (nm_clear_g_signal_handler (platform, &id_link));
g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_ip4_address)); g_assert (nm_clear_g_signal_handler (platform, &id_ip4_address));
g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_ip6_address)); g_assert (nm_clear_g_signal_handler (platform, &id_ip6_address));
g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_ip4_route)); g_assert (nm_clear_g_signal_handler (platform, &id_ip4_route));
g_assert (nm_clear_g_signal_handler (NM_PLATFORM_GET, &id_ip6_route)); g_assert (nm_clear_g_signal_handler (platform, &id_ip6_route));
if (nm_clear_g_source (&data.id)) if (nm_clear_g_source (&data.id))
g_assert (timeout_ms != 0 && !data.timeout); g_assert (timeout_ms != 0 && !data.timeout);
@ -372,7 +374,7 @@ nmtstp_wait_for_signal (guint timeout_ms)
} }
gboolean gboolean
nmtstp_wait_for_signal_until (gint64 until_ms) nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms)
{ {
gint64 now; gint64 now;
@ -382,19 +384,19 @@ nmtstp_wait_for_signal_until (gint64 until_ms)
if (until_ms < now) if (until_ms < now)
return FALSE; return FALSE;
if (nmtstp_wait_for_signal (MAX (1, until_ms - now))) if (nmtstp_wait_for_signal (platform, MAX (1, until_ms - now)))
return TRUE; return TRUE;
} }
} }
const NMPlatformLink * const NMPlatformLink *
nmtstp_wait_for_link (const char *ifname, NMLinkType expected_link_type, guint timeout_ms) nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, guint timeout_ms)
{ {
return nmtstp_wait_for_link_until (ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms); return nmtstp_wait_for_link_until (platform, ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms);
} }
const NMPlatformLink * const NMPlatformLink *
nmtstp_wait_for_link_until (const char *ifname, NMLinkType expected_link_type, gint64 until_ms) nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 until_ms)
{ {
const NMPlatformLink *plink; const NMPlatformLink *plink;
gint64 now; gint64 now;
@ -402,7 +404,7 @@ nmtstp_wait_for_link_until (const char *ifname, NMLinkType expected_link_type, g
while (TRUE) { while (TRUE) {
now = nm_utils_get_monotonic_timestamp_ms (); now = nm_utils_get_monotonic_timestamp_ms ();
plink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, ifname); plink = nm_platform_link_get_by_ifname (platform ?: NM_PLATFORM_GET, ifname);
if ( plink if ( plink
&& (expected_link_type == NM_LINK_TYPE_NONE || plink->type == expected_link_type)) && (expected_link_type == NM_LINK_TYPE_NONE || plink->type == expected_link_type))
return plink; return plink;
@ -410,22 +412,22 @@ nmtstp_wait_for_link_until (const char *ifname, NMLinkType expected_link_type, g
if (until_ms < now) if (until_ms < now)
return NULL; return NULL;
nmtstp_wait_for_signal (MAX (1, until_ms - now)); nmtstp_wait_for_signal (platform, MAX (1, until_ms - now));
} }
} }
const NMPlatformLink * const NMPlatformLink *
nmtstp_assert_wait_for_link (const char *ifname, NMLinkType expected_link_type, guint timeout_ms) nmtstp_assert_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, guint timeout_ms)
{ {
return nmtstp_assert_wait_for_link_until (ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms); return nmtstp_assert_wait_for_link_until (platform, ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms);
} }
const NMPlatformLink * const NMPlatformLink *
nmtstp_assert_wait_for_link_until (const char *ifname, NMLinkType expected_link_type, gint64 until_ms) nmtstp_assert_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 until_ms)
{ {
const NMPlatformLink *plink; const NMPlatformLink *plink;
plink = nmtstp_wait_for_link_until (ifname, expected_link_type, until_ms); plink = nmtstp_wait_for_link_until (platform, ifname, expected_link_type, until_ms);
g_assert (plink); g_assert (plink);
return plink; return plink;
} }
@ -686,20 +688,20 @@ _ip_address_add (gboolean external_command,
/* for internal command, we expect not to reach this line.*/ /* for internal command, we expect not to reach this line.*/
g_assert (external_command); g_assert (external_command);
g_assert (nmtstp_wait_for_signal_until (end_time)); g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
} while (TRUE); } while (TRUE);
} }
#define _assert_pllink(success, pllink, name, type) \ #define _assert_pllink(platform, success, pllink, name, type) \
G_STMT_START { \ G_STMT_START { \
const NMPlatformLink *_pllink = (pllink); \ const NMPlatformLink *_pllink = (pllink); \
\ \
if ((success)) { \ if ((success)) { \
g_assert (_pllink); \ g_assert (_pllink); \
g_assert (_pllink == nmtstp_link_get_typed (_pllink->ifindex, (name), (type))); \ g_assert (_pllink == nmtstp_link_get_typed (platform, _pllink->ifindex, (name), (type))); \
} else { \ } else { \
g_assert (!_pllink); \ g_assert (!_pllink); \
g_assert (!nmtstp_link_get (0, (name))); \ g_assert (!nmtstp_link_get (platform, 0, (name))); \
} \ } \
} G_STMT_END } G_STMT_END
@ -718,12 +720,12 @@ nmtstp_link_dummy_add (gboolean external_command,
success = !nmtstp_run_command ("ip link add %s type dummy", success = !nmtstp_run_command ("ip link add %s type dummy",
name); name);
if (success) if (success)
pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_DUMMY, 100); pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_DUMMY, 100);
} else } else
success = nm_platform_link_dummy_add (NM_PLATFORM_GET, name, &pllink) == NM_PLATFORM_ERROR_SUCCESS; success = nm_platform_link_dummy_add (NM_PLATFORM_GET, name, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
g_assert (success); g_assert (success);
_assert_pllink (success, pllink, name, NM_LINK_TYPE_DUMMY); _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_DUMMY);
return pllink; return pllink;
} }
@ -755,11 +757,11 @@ nmtstp_link_gre_add (gboolean external_command,
lnk->tos, lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success) if (success)
pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_GRE, 100); pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_GRE, 100);
} else } else
success = nm_platform_link_gre_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS; success = nm_platform_link_gre_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (success, pllink, name, NM_LINK_TYPE_GRE); _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_GRE);
return pllink; return pllink;
} }
@ -806,11 +808,11 @@ nmtstp_link_ip6tnl_add (gboolean external_command,
lnk->encap_limit, lnk->encap_limit,
lnk->flow_label); lnk->flow_label);
if (success) if (success)
pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_IP6TNL, 100); pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_IP6TNL, 100);
} else } else
success = nm_platform_link_ip6tnl_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS; success = nm_platform_link_ip6tnl_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (success, pllink, name, NM_LINK_TYPE_IP6TNL); _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_IP6TNL);
return pllink; return pllink;
} }
@ -843,11 +845,11 @@ nmtstp_link_ipip_add (gboolean external_command,
lnk->tos, lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success) if (success)
pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_IPIP, 100); pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_IPIP, 100);
} else } else
success = nm_platform_link_ipip_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS; success = nm_platform_link_ipip_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (success, pllink, name, NM_LINK_TYPE_IPIP); _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_IPIP);
return pllink; return pllink;
} }
@ -888,11 +890,11 @@ nmtstp_link_macvlan_add (gboolean external_command,
modes[lnk->mode], modes[lnk->mode],
lnk->no_promisc ? "nopromisc" : ""); lnk->no_promisc ? "nopromisc" : "");
if (success) if (success)
pllink = nmtstp_assert_wait_for_link (name, link_type, 100); pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, link_type, 100);
} else } else
success = nm_platform_link_macvlan_add (NM_PLATFORM_GET, name, parent, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS; success = nm_platform_link_macvlan_add (NM_PLATFORM_GET, name, parent, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (success, pllink, name, link_type); _assert_pllink (NM_PLATFORM_GET, success, pllink, name, link_type);
return pllink; return pllink;
} }
@ -930,11 +932,11 @@ nmtstp_link_sit_add (gboolean external_command,
lnk->tos, lnk->tos,
lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc");
if (success) if (success)
pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_SIT, 100); pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_SIT, 100);
} else } else
success = nm_platform_link_sit_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS; success = nm_platform_link_sit_add (NM_PLATFORM_GET, name, lnk, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
_assert_pllink (success, pllink, name, NM_LINK_TYPE_SIT); _assert_pllink (NM_PLATFORM_GET, success, pllink, name, NM_LINK_TYPE_SIT);
return pllink; return pllink;
} }
@ -983,7 +985,7 @@ nmtstp_link_vxlan_add (gboolean external_command,
/* Older versions of iproute2 don't support adding vxlan devices. /* Older versions of iproute2 don't support adding vxlan devices.
* On failure, fallback to using platform code. */ * On failure, fallback to using platform code. */
if (err == 0) if (err == 0)
pllink = nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_VXLAN, 100); pllink = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, name, NM_LINK_TYPE_VXLAN, 100);
else else
_LOGI ("Adding vxlan device via iproute2 failed. Assume iproute2 is not up to the task."); _LOGI ("Adding vxlan device via iproute2 failed. Assume iproute2 is not up to the task.");
} }
@ -1128,7 +1130,7 @@ _ip_address_del (gboolean external_command,
/* for internal command, we expect not to reach this line.*/ /* for internal command, we expect not to reach this line.*/
g_assert (external_command); g_assert (external_command);
g_assert (nmtstp_wait_for_signal_until (end_time)); g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
} while (TRUE); } while (TRUE);
} }
@ -1162,14 +1164,18 @@ nmtstp_ip6_address_del (gboolean external_command,
} }
const NMPlatformLink * const NMPlatformLink *
nmtstp_link_get_typed (int ifindex, nmtstp_link_get_typed (NMPlatform *platform,
int ifindex,
const char *name, const char *name,
NMLinkType link_type) NMLinkType link_type)
{ {
const NMPlatformLink *pllink = NULL; const NMPlatformLink *pllink = NULL;
if (!platform)
platform = NM_PLATFORM_GET;
if (ifindex > 0) { if (ifindex > 0) {
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex); pllink = nm_platform_link_get (platform, ifindex);
if (pllink) { if (pllink) {
g_assert_cmpint (pllink->ifindex, ==, ifindex); g_assert_cmpint (pllink->ifindex, ==, ifindex);
@ -1177,12 +1183,12 @@ nmtstp_link_get_typed (int ifindex,
g_assert_cmpstr (name, ==, pllink->name); g_assert_cmpstr (name, ==, pllink->name);
} else { } else {
if (name) if (name)
g_assert (!nm_platform_link_get_by_ifname (NM_PLATFORM_GET, name)); g_assert (!nm_platform_link_get_by_ifname (platform, name));
} }
} else { } else {
g_assert (name); g_assert (name);
pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, name); pllink = nm_platform_link_get_by_ifname (platform, name);
if (pllink) if (pllink)
g_assert_cmpstr (name, ==, pllink->name); g_assert_cmpstr (name, ==, pllink->name);
@ -1197,10 +1203,11 @@ nmtstp_link_get_typed (int ifindex,
} }
const NMPlatformLink * const NMPlatformLink *
nmtstp_link_get (int ifindex, nmtstp_link_get (NMPlatform *platform,
int ifindex,
const char *name) const char *name)
{ {
return nmtstp_link_get_typed (ifindex, name, NM_LINK_TYPE_NONE); return nmtstp_link_get_typed (platform, ifindex, name, NM_LINK_TYPE_NONE);
} }
void void
@ -1213,7 +1220,7 @@ nmtstp_link_del (gboolean external_command,
gboolean success; gboolean success;
gs_free char *name_copy = NULL; gs_free char *name_copy = NULL;
pllink = nmtstp_link_get (ifindex, name); pllink = nmtstp_link_get (NM_PLATFORM_GET, ifindex, name);
g_assert (pllink); g_assert (pllink);
@ -1243,7 +1250,7 @@ nmtstp_link_del (gboolean external_command,
/* for internal command, we expect not to reach this line.*/ /* for internal command, we expect not to reach this line.*/
g_assert (external_command); g_assert (external_command);
g_assert (nmtstp_wait_for_signal_until (end_time)); g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
} while (TRUE); } while (TRUE);
} }
@ -1289,7 +1296,7 @@ nmtstp_link_set_updown (gboolean external_command,
/* for internal command, we expect not to reach this line.*/ /* for internal command, we expect not to reach this line.*/
g_assert (external_command); g_assert (external_command);
g_assert (nmtstp_wait_for_signal_until (end_time)); g_assert (nmtstp_wait_for_signal_until (NM_PLATFORM_GET, end_time));
} while (TRUE); } while (TRUE);
} }

View file

@ -91,13 +91,13 @@ void link_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, N
int nmtstp_run_command (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2))); int nmtstp_run_command (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
#define nmtstp_run_command_check(...) do { g_assert_cmpint (nmtstp_run_command (__VA_ARGS__), ==, 0); } while (0) #define nmtstp_run_command_check(...) do { g_assert_cmpint (nmtstp_run_command (__VA_ARGS__), ==, 0); } while (0)
gboolean nmtstp_wait_for_signal (guint timeout_ms); gboolean nmtstp_wait_for_signal (NMPlatform *platform, guint timeout_ms);
gboolean nmtstp_wait_for_signal_until (gint64 until_ms); gboolean nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms);
const NMPlatformLink *nmtstp_wait_for_link (const char *ifname, NMLinkType expected_link_type, guint timeout_ms); const NMPlatformLink *nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, guint timeout_ms);
const NMPlatformLink *nmtstp_wait_for_link_until (const char *ifname, NMLinkType expected_link_type, gint64 until_ms); const NMPlatformLink *nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 until_ms);
const NMPlatformLink *nmtstp_assert_wait_for_link (const char *ifname, NMLinkType expected_link_type, guint timeout_ms); const NMPlatformLink *nmtstp_assert_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, guint timeout_ms);
const NMPlatformLink *nmtstp_assert_wait_for_link_until (const char *ifname, NMLinkType expected_link_type, gint64 until_ms); const NMPlatformLink *nmtstp_assert_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 until_ms);
int nmtstp_run_command_check_external_global (void); int nmtstp_run_command_check_external_global (void);
gboolean nmtstp_run_command_check_external (int external_command); gboolean nmtstp_run_command_check_external (int external_command);
@ -137,8 +137,8 @@ void nmtstp_ip6_address_del (gboolean external_command,
struct in6_addr address, struct in6_addr address,
int plen); int plen);
const NMPlatformLink *nmtstp_link_get_typed (int ifindex, const char *name, NMLinkType link_type); const NMPlatformLink *nmtstp_link_get_typed (NMPlatform *platform, int ifindex, const char *name, NMLinkType link_type);
const NMPlatformLink *nmtstp_link_get (int ifindex, const char *name); const NMPlatformLink *nmtstp_link_get (NMPlatform *platform, int ifindex, const char *name);
void nmtstp_link_set_updown (gboolean external_command, void nmtstp_link_set_updown (gboolean external_command,
int ifindex, int ifindex,

View file

@ -692,7 +692,7 @@ test_software_detect (gconstpointer user_data)
const gboolean ext = test_data->external_command; const gboolean ext = test_data->external_command;
nmtstp_run_command_check ("ip link add %s type dummy", PARENT_NAME); nmtstp_run_command_check ("ip link add %s type dummy", PARENT_NAME);
ifindex_parent = nmtstp_assert_wait_for_link (PARENT_NAME, NM_LINK_TYPE_DUMMY, 100)->ifindex; ifindex_parent = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, PARENT_NAME, NM_LINK_TYPE_DUMMY, 100)->ifindex;
switch (test_data->link_type) { switch (test_data->link_type) {
case NM_LINK_TYPE_GRE: { case NM_LINK_TYPE_GRE: {
@ -854,7 +854,7 @@ test_software_detect (gconstpointer user_data)
g_assert_not_reached (); g_assert_not_reached ();
} }
ifindex = nmtstp_assert_wait_for_link (DEVICE_NAME, test_data->link_type, 100)->ifindex; ifindex = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, DEVICE_NAME, test_data->link_type, 100)->ifindex;
nmtstp_link_set_updown (-1, ifindex_parent, TRUE); nmtstp_link_set_updown (-1, ifindex_parent, TRUE);
@ -1139,10 +1139,10 @@ test_vlan_set_xgress (void)
int ifindex, ifindex_parent; int ifindex, ifindex_parent;
nmtstp_run_command_check ("ip link add %s type dummy", PARENT_NAME); nmtstp_run_command_check ("ip link add %s type dummy", PARENT_NAME);
ifindex_parent = nmtstp_assert_wait_for_link (PARENT_NAME, NM_LINK_TYPE_DUMMY, 100)->ifindex; ifindex_parent = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, PARENT_NAME, NM_LINK_TYPE_DUMMY, 100)->ifindex;
nmtstp_run_command_check ("ip link add name %s link %s type vlan id 1245", DEVICE_NAME, PARENT_NAME); nmtstp_run_command_check ("ip link add name %s link %s type vlan id 1245", DEVICE_NAME, PARENT_NAME);
ifindex = nmtstp_assert_wait_for_link (DEVICE_NAME, NM_LINK_TYPE_VLAN, 100)->ifindex; ifindex = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, DEVICE_NAME, NM_LINK_TYPE_VLAN, 100)->ifindex;
/* ingress-qos-map */ /* ingress-qos-map */
@ -1687,8 +1687,8 @@ test_nl_bugs_veth (void)
/* create veth pair. */ /* create veth pair. */
nmtstp_run_command_check ("ip link add dev %s type veth peer name %s", IFACE_VETH0, IFACE_VETH1); nmtstp_run_command_check ("ip link add dev %s type veth peer name %s", IFACE_VETH0, IFACE_VETH1);
ifindex_veth0 = nmtstp_assert_wait_for_link (IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex; ifindex_veth0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex;
ifindex_veth1 = nmtstp_assert_wait_for_link (IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex; ifindex_veth1 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex;
/* assert that nm_platform_link_veth_get_properties() returns the expected peer ifindexes. */ /* assert that nm_platform_link_veth_get_properties() returns the expected peer ifindexes. */
g_assert (nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex_veth0, &i)); g_assert (nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex_veth0, &i));
@ -1724,7 +1724,7 @@ test_nl_bugs_veth (void)
nmtstp_run_command_check ("ip link set %s netns %ld", IFACE_VETH1, (long) nmtstp_namespace_handle_get_pid (ns_handle)); nmtstp_run_command_check ("ip link set %s netns %ld", IFACE_VETH1, (long) nmtstp_namespace_handle_get_pid (ns_handle));
NMTST_WAIT_ASSERT (100, { NMTST_WAIT_ASSERT (100, {
nmtstp_wait_for_signal (50); nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
nm_platform_process_events (NM_PLATFORM_GET); nm_platform_process_events (NM_PLATFORM_GET);
pllink_veth1 = nm_platform_link_get (NM_PLATFORM_GET, ifindex_veth1); pllink_veth1 = nm_platform_link_get (NM_PLATFORM_GET, ifindex_veth1);
@ -1738,8 +1738,8 @@ test_nl_bugs_veth (void)
out: out:
nmtstp_link_del (-1, ifindex_veth0, IFACE_VETH0); nmtstp_link_del (-1, ifindex_veth0, IFACE_VETH0);
g_assert (!nmtstp_link_get (ifindex_veth0, IFACE_VETH0)); g_assert (!nmtstp_link_get (NM_PLATFORM_GET, ifindex_veth0, IFACE_VETH0));
g_assert (!nmtstp_link_get (ifindex_veth1, IFACE_VETH1)); g_assert (!nmtstp_link_get (NM_PLATFORM_GET, ifindex_veth1, IFACE_VETH1));
nmtstp_namespace_handle_release (ns_handle); nmtstp_namespace_handle_release (ns_handle);
} }
@ -1757,16 +1757,16 @@ test_nl_bugs_spuroius_newlink (void)
/* see https://bugzilla.redhat.com/show_bug.cgi?id=1285719 */ /* see https://bugzilla.redhat.com/show_bug.cgi?id=1285719 */
nmtstp_run_command_check ("ip link add %s type dummy", IFACE_DUMMY0); nmtstp_run_command_check ("ip link add %s type dummy", IFACE_DUMMY0);
ifindex_dummy0 = nmtstp_assert_wait_for_link (IFACE_DUMMY0, NM_LINK_TYPE_DUMMY, 100)->ifindex; ifindex_dummy0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_DUMMY0, NM_LINK_TYPE_DUMMY, 100)->ifindex;
nmtstp_run_command_check ("ip link add %s type bond", IFACE_BOND0); nmtstp_run_command_check ("ip link add %s type bond", IFACE_BOND0);
ifindex_bond0 = nmtstp_assert_wait_for_link (IFACE_BOND0, NM_LINK_TYPE_BOND, 100)->ifindex; ifindex_bond0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_BOND0, NM_LINK_TYPE_BOND, 100)->ifindex;
nmtstp_link_set_updown (-1, ifindex_bond0, TRUE); nmtstp_link_set_updown (-1, ifindex_bond0, TRUE);
nmtstp_run_command_check ("ip link set %s master %s", IFACE_DUMMY0, IFACE_BOND0); nmtstp_run_command_check ("ip link set %s master %s", IFACE_DUMMY0, IFACE_BOND0);
NMTST_WAIT_ASSERT (100, { NMTST_WAIT_ASSERT (100, {
nmtstp_wait_for_signal (50); nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_dummy0); pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_dummy0);
g_assert (pllink); g_assert (pllink);
@ -1777,7 +1777,7 @@ test_nl_bugs_spuroius_newlink (void)
nmtstp_run_command_check ("ip link del %s", IFACE_BOND0); nmtstp_run_command_check ("ip link del %s", IFACE_BOND0);
wait_for_settle = TRUE; wait_for_settle = TRUE;
nmtstp_wait_for_signal (50); nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
again: again:
nm_platform_process_events (NM_PLATFORM_GET); nm_platform_process_events (NM_PLATFORM_GET);
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_bond0); pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_bond0);
@ -1785,11 +1785,11 @@ again:
if (wait_for_settle) { if (wait_for_settle) {
wait_for_settle = FALSE; wait_for_settle = FALSE;
NMTST_WAIT (300, { nmtstp_wait_for_signal (50); }); NMTST_WAIT (300, { nmtstp_wait_for_signal (NM_PLATFORM_GET, 50); });
goto again; goto again;
} }
g_assert (!nmtstp_link_get (ifindex_bond0, IFACE_BOND0)); g_assert (!nmtstp_link_get (NM_PLATFORM_GET, ifindex_bond0, IFACE_BOND0));
nmtstp_link_del (-1, ifindex_dummy0, IFACE_DUMMY0); nmtstp_link_del (-1, ifindex_dummy0, IFACE_DUMMY0);
} }
@ -1807,16 +1807,16 @@ test_nl_bugs_spuroius_dellink (void)
/* see https://bugzilla.redhat.com/show_bug.cgi?id=1285719 */ /* see https://bugzilla.redhat.com/show_bug.cgi?id=1285719 */
nmtstp_run_command_check ("ip link add %s type dummy", IFACE_DUMMY0); nmtstp_run_command_check ("ip link add %s type dummy", IFACE_DUMMY0);
ifindex_dummy0 = nmtstp_assert_wait_for_link (IFACE_DUMMY0, NM_LINK_TYPE_DUMMY, 100)->ifindex; ifindex_dummy0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_DUMMY0, NM_LINK_TYPE_DUMMY, 100)->ifindex;
nmtstp_run_command_check ("ip link add %s type bridge", IFACE_BRIDGE0); nmtstp_run_command_check ("ip link add %s type bridge", IFACE_BRIDGE0);
ifindex_bridge0 = nmtstp_assert_wait_for_link (IFACE_BRIDGE0, NM_LINK_TYPE_BRIDGE, 100)->ifindex; ifindex_bridge0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_BRIDGE0, NM_LINK_TYPE_BRIDGE, 100)->ifindex;
nmtstp_link_set_updown (-1, ifindex_bridge0, TRUE); nmtstp_link_set_updown (-1, ifindex_bridge0, TRUE);
nmtstp_run_command_check ("ip link set %s master %s", IFACE_DUMMY0, IFACE_BRIDGE0); nmtstp_run_command_check ("ip link set %s master %s", IFACE_DUMMY0, IFACE_BRIDGE0);
NMTST_WAIT_ASSERT (100, { NMTST_WAIT_ASSERT (100, {
nmtstp_wait_for_signal (50); nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_dummy0); pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_dummy0);
g_assert (pllink); g_assert (pllink);
@ -1829,7 +1829,7 @@ test_nl_bugs_spuroius_dellink (void)
nmtstp_run_command_check ("ip link set %s nomaster", IFACE_DUMMY0); nmtstp_run_command_check ("ip link set %s nomaster", IFACE_DUMMY0);
wait_for_settle = TRUE; wait_for_settle = TRUE;
nmtstp_wait_for_signal (50); nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
again: again:
nm_platform_process_events (NM_PLATFORM_GET); nm_platform_process_events (NM_PLATFORM_GET);
pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_bridge0); pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex_bridge0);
@ -1840,7 +1840,7 @@ again:
if (wait_for_settle) { if (wait_for_settle) {
wait_for_settle = FALSE; wait_for_settle = FALSE;
NMTST_WAIT (300, { nmtstp_wait_for_signal (50); }); NMTST_WAIT (300, { nmtstp_wait_for_signal (NM_PLATFORM_GET, 50); });
goto again; goto again;
} }

View file

@ -314,7 +314,7 @@ test_ip4_zero_gateway (void)
nmtstp_run_command_check ("ip route add 1.2.3.2/32 dev %s", DEVICE_NAME); nmtstp_run_command_check ("ip route add 1.2.3.2/32 dev %s", DEVICE_NAME);
NMTST_WAIT_ASSERT (100, { NMTST_WAIT_ASSERT (100, {
nmtstp_wait_for_signal (10); nmtstp_wait_for_signal (NM_PLATFORM_GET, 10);
if ( nm_platform_ip4_route_get (NM_PLATFORM_GET, ifindex, nmtst_inet4_from_string ("1.2.3.1"), 32, 0) if ( nm_platform_ip4_route_get (NM_PLATFORM_GET, ifindex, nmtst_inet4_from_string ("1.2.3.1"), 32, 0)
&& nm_platform_ip4_route_get (NM_PLATFORM_GET, ifindex, nmtst_inet4_from_string ("1.2.3.2"), 32, 0)) && nm_platform_ip4_route_get (NM_PLATFORM_GET, ifindex, nmtst_inet4_from_string ("1.2.3.2"), 32, 0))
break; break;
@ -322,7 +322,7 @@ test_ip4_zero_gateway (void)
nmtstp_run_command_check ("ip route flush dev %s", DEVICE_NAME); nmtstp_run_command_check ("ip route flush dev %s", DEVICE_NAME);
nmtstp_wait_for_signal (50); nmtstp_wait_for_signal (NM_PLATFORM_GET, 50);
nm_platform_process_events (NM_PLATFORM_GET); nm_platform_process_events (NM_PLATFORM_GET);
} }