platform/test: fix fake platform to emit signals synchronously (analog to Linux platform)
When adding a link, the Linux platform implementation raises the link-changed signal synchronously. Fix the fake platform to behave identically and also fix all the tests. This also fixes the Linux platform tests for the most part because now the test functions (and fake platform) behave like the Linux system implementation. https://bugzilla.gnome.org/show_bug.cgi?id=706293 Co-Authored-By: Thomas Haller <thaller@redhat.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:

committed by
Thomas Haller

parent
accd10b501
commit
f008c9fbea
@@ -36,8 +36,6 @@ typedef struct {
|
||||
GArray *ip6_addresses;
|
||||
GArray *ip4_routes;
|
||||
GArray *ip6_routes;
|
||||
|
||||
GSList *link_added_ids;
|
||||
} NMFakePlatformPrivate;
|
||||
|
||||
typedef struct {
|
||||
@@ -163,27 +161,6 @@ link_get_all (NMPlatform *platform)
|
||||
return links;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
NMPlatform *platform;
|
||||
int ifindex;
|
||||
guint id;
|
||||
} LinkAddedInfo;
|
||||
|
||||
static gboolean
|
||||
link_added_emit (gpointer user_data)
|
||||
{
|
||||
LinkAddedInfo *info = user_data;
|
||||
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (info->platform);
|
||||
NMFakePlatformLink *device;
|
||||
|
||||
priv->link_added_ids = g_slist_remove (priv->link_added_ids, GUINT_TO_POINTER (info->id));
|
||||
|
||||
device = link_get (info->platform, info->ifindex);
|
||||
g_assert (device);
|
||||
g_signal_emit_by_name (info->platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, info->ifindex, &device->link, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_nm_platform_link_get (NMPlatform *platform, int ifindex, NMPlatformLink *link)
|
||||
{
|
||||
@@ -199,23 +176,13 @@ link_add (NMPlatform *platform, const char *name, NMLinkType type, const void *a
|
||||
{
|
||||
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
|
||||
NMFakePlatformLink device;
|
||||
LinkAddedInfo *info;
|
||||
|
||||
link_init (&device, priv->links->len, type, name);
|
||||
|
||||
g_array_append_val (priv->links, device);
|
||||
|
||||
if (device.link.ifindex) {
|
||||
/* Platform requires LINK_ADDED signal emission from an idle handler */
|
||||
info = g_new0 (LinkAddedInfo, 1);
|
||||
info->platform = platform;
|
||||
info->ifindex = device.link.ifindex;
|
||||
info->id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
|
||||
link_added_emit,
|
||||
info,
|
||||
g_free);
|
||||
priv->link_added_ids = g_slist_prepend (priv->link_added_ids, GUINT_TO_POINTER (info->id));
|
||||
}
|
||||
if (device.link.ifindex)
|
||||
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, device.link.ifindex, &device, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_REASON_INTERNAL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1260,11 +1227,6 @@ nm_fake_platform_finalize (GObject *object)
|
||||
{
|
||||
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (object);
|
||||
int i;
|
||||
GSList *iter;
|
||||
|
||||
for (iter = priv->link_added_ids; iter; iter = iter->next)
|
||||
g_source_remove (GPOINTER_TO_UINT (iter->data));
|
||||
g_slist_free (priv->link_added_ids);
|
||||
|
||||
g_hash_table_unref (priv->options);
|
||||
for (i = 0; i < priv->links->len; i++) {
|
||||
|
@@ -1636,7 +1636,7 @@ event_notification (struct nl_msg *msg, gpointer user_data)
|
||||
return NL_OK;
|
||||
|
||||
nl_cache_remove (cached_object);
|
||||
/* Don't announced removed interfaces that are not recognized by
|
||||
/* Don't announce removed interfaces that are not recognized by
|
||||
* udev. They were either not yet discovered or they have been
|
||||
* already removed and announced.
|
||||
*/
|
||||
|
@@ -314,7 +314,7 @@ nm_platform_sysctl_get_int_checked (const char *path, guint base, gint64 min, gi
|
||||
/**
|
||||
* nm_platform_query_devices:
|
||||
*
|
||||
* Emit #NMPlatform:link-added signals for all currently-known links.
|
||||
* Emit #NMPlatform:link-changed ADDED signals for all currently-known links.
|
||||
* Should only be called at startup.
|
||||
*/
|
||||
void
|
||||
@@ -468,8 +468,8 @@ nm_platform_link_get (int ifindex, NMPlatformLink *link)
|
||||
* @address_len: the length of the @address
|
||||
*
|
||||
* Add a software interface. Sets platform->error to NM_PLATFORM_ERROR_EXISTS
|
||||
* if interface is already already exists. Any link-added signal will be
|
||||
* emitted from an idle handler and not within this function.
|
||||
* if interface is already already exists. Any link-changed ADDED signal will be
|
||||
* emitted directly, before this function finishes.
|
||||
*/
|
||||
static gboolean
|
||||
nm_platform_link_add (const char *name, NMLinkType type, const void *address, size_t address_len)
|
||||
|
@@ -252,7 +252,7 @@ setup_tests (void)
|
||||
nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME));
|
||||
g_assert (!nm_platform_link_exists (DEVICE_NAME));
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
wait_signal (link_added);
|
||||
accept_signal (link_added);
|
||||
free_signal (link_added);
|
||||
|
||||
g_test_add_func ("/address/internal/ip4", test_ip4_address);
|
||||
|
@@ -34,7 +34,7 @@ test_cleanup_internal ()
|
||||
|
||||
/* Create and set up device */
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
wait_signal (link_added);
|
||||
accept_signal (link_added);
|
||||
free_signal (link_added);
|
||||
g_assert (nm_platform_link_set_up (nm_platform_link_get_ifindex (DEVICE_NAME)));
|
||||
ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
|
||||
|
@@ -48,6 +48,9 @@ accept_signal (SignalData *data)
|
||||
void
|
||||
wait_signal (SignalData *data)
|
||||
{
|
||||
if (data->received)
|
||||
g_error ("Signal '%s' received before waiting for it.", data->name);
|
||||
|
||||
data->loop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (data->loop);
|
||||
g_clear_pointer (&data->loop, g_main_loop_unref);
|
||||
@@ -96,6 +99,11 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl
|
||||
debug ("Received signal '%s-%s' ifindex %d ifname '%s'.", data->name, _change_type_to_string (data->change_type), ifindex, received->name);
|
||||
data->received = TRUE;
|
||||
|
||||
if (change_type == NM_PLATFORM_SIGNAL_REMOVED)
|
||||
g_assert (!nm_platform_link_get_name (ifindex));
|
||||
else
|
||||
g_assert (nm_platform_link_get_name (ifindex));
|
||||
|
||||
/* Check the data */
|
||||
g_assert (received->ifindex > 0);
|
||||
links = nm_platform_link_get_all ();
|
||||
|
@@ -113,7 +113,7 @@ software_add (NMLinkType link_type, const char *name)
|
||||
/* Don't call link_callback for the bridge interface */
|
||||
parent_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, PARENT_NAME);
|
||||
if (nm_platform_bridge_add (PARENT_NAME, NULL, 0))
|
||||
wait_signal (parent_added);
|
||||
accept_signal (parent_added);
|
||||
free_signal (parent_added);
|
||||
|
||||
{
|
||||
@@ -145,7 +145,7 @@ test_slave (int master, int type, SignalData *master_changed)
|
||||
g_assert (ifindex > 0);
|
||||
link_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, ifindex);
|
||||
link_removed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_REMOVED, link_callback, ifindex);
|
||||
wait_signal (link_added);
|
||||
accept_signal (link_added);
|
||||
|
||||
/* Set the slave up to see whether master's IFF_LOWER_UP is set correctly.
|
||||
*
|
||||
@@ -247,7 +247,7 @@ test_software (NMLinkType link_type, const char *link_typename)
|
||||
link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_ADDED, link_callback, DEVICE_NAME);
|
||||
g_assert (software_add (link_type, DEVICE_NAME));
|
||||
no_error ();
|
||||
wait_signal (link_added);
|
||||
accept_signal (link_added);
|
||||
g_assert (nm_platform_link_exists (DEVICE_NAME));
|
||||
ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
|
||||
g_assert (ifindex >= 0);
|
||||
@@ -389,7 +389,7 @@ test_internal (void)
|
||||
/* Add device */
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
no_error ();
|
||||
wait_signal (link_added);
|
||||
accept_signal (link_added);
|
||||
|
||||
/* Try to add again */
|
||||
g_assert (!nm_platform_dummy_add (DEVICE_NAME));
|
||||
|
@@ -220,7 +220,7 @@ setup_tests (void)
|
||||
nm_platform_link_delete (nm_platform_link_get_ifindex (DEVICE_NAME));
|
||||
g_assert (!nm_platform_link_exists (DEVICE_NAME));
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
wait_signal (link_added);
|
||||
accept_signal (link_added);
|
||||
free_signal (link_added);
|
||||
|
||||
g_assert (nm_platform_link_set_up (nm_platform_link_get_ifindex (DEVICE_NAME)));
|
||||
|
Reference in New Issue
Block a user