mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 19:10:09 +01:00
platform/test: make asserting signals more flexible
Support accepting more then one signal at a time. It is to be expected, that one change in platform raises several signals. Extend the assertion helpers to express that.
This commit is contained in:
parent
4bdd83127d
commit
050c644cce
4 changed files with 37 additions and 29 deletions
|
|
@ -24,10 +24,8 @@ ip4_address_callback (NMPlatform *platform, int ifindex, NMPlatformIP4Address *r
|
|||
if (data->loop)
|
||||
g_main_loop_quit (data->loop);
|
||||
|
||||
if (data->received)
|
||||
g_error ("Received signal '%s' a second time.", data->name);
|
||||
|
||||
data->received = TRUE;
|
||||
data->received_count++;
|
||||
debug ("Received signal '%s' %dth time.", data->name, data->received_count);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -46,10 +44,8 @@ ip6_address_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Address *r
|
|||
if (data->loop)
|
||||
g_main_loop_quit (data->loop);
|
||||
|
||||
if (data->received)
|
||||
g_error ("Received signal '%s' a second time.", data->name);
|
||||
|
||||
data->received = TRUE;
|
||||
data->received_count++;
|
||||
debug ("Received signal '%s' %dth time.", data->name, data->received_count);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ add_signal_full (const char *name, NMPlatformSignalChangeType change_type, GCall
|
|||
|
||||
data->name = name;
|
||||
data->change_type = change_type;
|
||||
data->received = FALSE;
|
||||
data->received_count = 0;
|
||||
data->handler_id = g_signal_connect (nm_platform_get (), name, callback, data);
|
||||
data->ifindex = ifindex;
|
||||
data->ifname = ifname;
|
||||
|
|
@ -52,16 +52,33 @@ void
|
|||
accept_signal (SignalData *data)
|
||||
{
|
||||
debug ("Accepting signal '%s-%s' ifindex %d ifname %s.", data->name, _change_type_to_string (data->change_type), data->ifindex, data->ifname);
|
||||
if (!data->received)
|
||||
if (data->received_count == 0)
|
||||
g_error ("Attemted to accept a non-received signal '%s-%s'.", data->name, _change_type_to_string (data->change_type));
|
||||
if (data->received_count != 1)
|
||||
g_error ("Signal already received %d times: '%s-%s'.", data->received_count, data->name, _change_type_to_string (data->change_type));
|
||||
|
||||
data->received = FALSE;
|
||||
data->received_count = 0;
|
||||
}
|
||||
|
||||
void
|
||||
accept_signals (SignalData *data, int min, int max)
|
||||
{
|
||||
if (data->received_count < min || data->received_count > max)
|
||||
g_error ("Expect [%d,%d] signals, but %s signals queued -- '%s-%s' ifindex %d ifname %s.", min, max, data->received_count, data->name, _change_type_to_string (data->change_type), data->ifindex, data->ifname);
|
||||
data->received_count = 0;
|
||||
}
|
||||
|
||||
void
|
||||
ensure_no_signal (SignalData *data)
|
||||
{
|
||||
if (data->received_count > 0)
|
||||
g_error ("Unepexted signal '%s-%s'.", data->name, _change_type_to_string (data->change_type));
|
||||
}
|
||||
|
||||
void
|
||||
wait_signal (SignalData *data)
|
||||
{
|
||||
if (data->received)
|
||||
if (data->received_count)
|
||||
g_error ("Signal '%s' received before waiting for it.", data->name);
|
||||
|
||||
data->loop = g_main_loop_new (NULL, FALSE);
|
||||
|
|
@ -74,7 +91,7 @@ wait_signal (SignalData *data)
|
|||
void
|
||||
free_signal (SignalData *data)
|
||||
{
|
||||
if (data->received)
|
||||
if (data->received_count != 0)
|
||||
g_error ("Attempted to free received but not accepted signal '%s-%s'.", data->name, _change_type_to_string (data->change_type));
|
||||
|
||||
g_signal_handler_disconnect (nm_platform_get (), data->handler_id);
|
||||
|
|
@ -106,11 +123,8 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl
|
|||
g_main_loop_quit (data->loop);
|
||||
}
|
||||
|
||||
if (data->received)
|
||||
g_error ("Received signal '%s-%s' a second time.", data->name, _change_type_to_string (data->change_type));
|
||||
|
||||
debug ("Received signal '%s-%s' ifindex %d ifname '%s'.", data->name, _change_type_to_string (data->change_type), ifindex, received->name);
|
||||
data->received = TRUE;
|
||||
data->received_count++;
|
||||
debug ("Received signal '%s-%s' ifindex %d ifname '%s' %dth time.", data->name, _change_type_to_string (data->change_type), ifindex, received->name, data->received_count);
|
||||
|
||||
if (change_type == NM_PLATFORM_SIGNAL_REMOVED)
|
||||
g_assert (!nm_platform_link_get_name (NM_PLATFORM_GET, ifindex));
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ typedef struct {
|
|||
int handler_id;
|
||||
const char *name;
|
||||
NMPlatformSignalChangeType change_type;
|
||||
gboolean received;
|
||||
gint received_count;
|
||||
GMainLoop *loop;
|
||||
int ifindex;
|
||||
const char *ifname;
|
||||
|
|
@ -35,7 +35,9 @@ SignalData *add_signal_full (const char *name, NMPlatformSignalChangeType change
|
|||
#define add_signal_ifindex(name, change_type, callback, ifindex) add_signal_full (name, change_type, (GCallback) callback, ifindex, NULL)
|
||||
#define add_signal_ifname(name, change_type, callback, ifname) add_signal_full (name, change_type, (GCallback) callback, 0, ifname)
|
||||
void accept_signal (SignalData *data);
|
||||
void accept_signals (SignalData *data, int min, int max);
|
||||
void wait_signal (SignalData *data);
|
||||
void ensure_no_signal (SignalData *data);
|
||||
void free_signal (SignalData *data);
|
||||
|
||||
gboolean ip4_route_exists (const char *ifname, guint32 network, int plen, guint32 metric);
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ ip4_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP4Route *recei
|
|||
if (data->loop)
|
||||
g_main_loop_quit (data->loop);
|
||||
|
||||
if (data->received)
|
||||
g_error ("Received signal '%s' a second time.", data->name);
|
||||
|
||||
data->received = TRUE;
|
||||
data->received_count++;
|
||||
debug ("Received signal '%s' %dth time.", data->name, data->received_count);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -44,10 +42,8 @@ ip6_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Route *recei
|
|||
if (data->loop)
|
||||
g_main_loop_quit (data->loop);
|
||||
|
||||
if (data->received)
|
||||
g_error ("Received signal '%s' a second time.", data->name);
|
||||
|
||||
data->received = TRUE;
|
||||
data->received_count++;
|
||||
debug ("Received signal '%s' %dth time.", data->name, data->received_count);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -77,7 +73,7 @@ test_ip4_route_metric0 (void)
|
|||
/* Deleting route with metric 0 does nothing */
|
||||
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
|
||||
no_error ();
|
||||
g_assert (!route_removed->received);
|
||||
ensure_no_signal (route_removed);
|
||||
|
||||
assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, 0);
|
||||
assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric);
|
||||
|
|
@ -101,7 +97,7 @@ test_ip4_route_metric0 (void)
|
|||
/* Delete route with metric 0 again (we expect nothing to happen) */
|
||||
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
|
||||
no_error ();
|
||||
g_assert (!route_removed->received);
|
||||
ensure_no_signal (route_removed);
|
||||
|
||||
assert_ip4_route_exists (FALSE, DEVICE_NAME, network, plen, 0);
|
||||
assert_ip4_route_exists (TRUE, DEVICE_NAME, network, plen, metric);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue