mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 16:30:31 +01:00
test: add option in nmtst_platform_ip4_routes_equal() to ignore ordering
Same for nmtst_platform_ip6_routes_equal(). It's useful to check for equal routes ignoring the ordering.
This commit is contained in:
parent
ba8ce3bbe5
commit
57453189e0
3 changed files with 40 additions and 12 deletions
|
|
@ -686,14 +686,28 @@ nmtst_platform_ip6_route_full (const char *network, guint plen, const char *gate
|
|||
return route;
|
||||
}
|
||||
|
||||
inline static int
|
||||
_nmtst_platform_ip4_routes_equal_sort (gconstpointer a, gconstpointer b, gpointer user_data)
|
||||
{
|
||||
return nm_platform_ip4_route_cmp ((const NMPlatformIP4Route *) a, (const NMPlatformIP4Route *) b);
|
||||
}
|
||||
|
||||
inline static void
|
||||
nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gsize len)
|
||||
nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gsize len, gboolean ignore_order)
|
||||
{
|
||||
gsize i;
|
||||
gs_free const NMPlatformIP4Route *c_a = NULL, *c_b = NULL;
|
||||
|
||||
g_assert (a);
|
||||
g_assert (b);
|
||||
|
||||
if (ignore_order) {
|
||||
a = c_a = g_memdup (a, sizeof (NMPlatformIP4Route) * len);
|
||||
b = c_b = g_memdup (b, sizeof (NMPlatformIP4Route) * len);
|
||||
g_qsort_with_data (c_a, len, sizeof (NMPlatformIP4Route), _nmtst_platform_ip4_routes_equal_sort, NULL);
|
||||
g_qsort_with_data (c_b, len, sizeof (NMPlatformIP4Route), _nmtst_platform_ip4_routes_equal_sort, NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (nm_platform_ip4_route_cmp (&a[i], &b[i]) != 0) {
|
||||
g_error ("Error comparing IPv4 route[%lu]: %s vs %s", (long unsigned) i,
|
||||
|
|
@ -707,14 +721,28 @@ nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP
|
|||
}
|
||||
}
|
||||
|
||||
inline static int
|
||||
_nmtst_platform_ip6_routes_equal_sort (gconstpointer a, gconstpointer b, gpointer user_data)
|
||||
{
|
||||
return nm_platform_ip6_route_cmp ((const NMPlatformIP6Route *) a, (const NMPlatformIP6Route *) b);
|
||||
}
|
||||
|
||||
inline static void
|
||||
nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gsize len)
|
||||
nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gsize len, gboolean ignore_order)
|
||||
{
|
||||
gsize i;
|
||||
gs_free const NMPlatformIP6Route *c_a = NULL, *c_b = NULL;
|
||||
|
||||
g_assert (a);
|
||||
g_assert (b);
|
||||
|
||||
if (ignore_order) {
|
||||
a = c_a = g_memdup (a, sizeof (NMPlatformIP6Route) * len);
|
||||
b = c_b = g_memdup (b, sizeof (NMPlatformIP6Route) * len);
|
||||
g_qsort_with_data (c_a, len, sizeof (NMPlatformIP6Route), _nmtst_platform_ip6_routes_equal_sort, NULL);
|
||||
g_qsort_with_data (c_b, len, sizeof (NMPlatformIP6Route), _nmtst_platform_ip6_routes_equal_sort, NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (nm_platform_ip6_route_cmp (&a[i], &b[i]) != 0) {
|
||||
g_error ("Error comparing IPv6 route[%lu]: %s vs %s", (long unsigned) i,
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ test_ip4_route (void)
|
|||
rts[2].mss = mss;
|
||||
g_assert_cmpint (routes->len, ==, 3);
|
||||
g_assert (!memcmp (routes->data, rts, sizeof (rts)));
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, rts, routes->len);
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, rts, routes->len, TRUE);
|
||||
g_array_unref (routes);
|
||||
|
||||
/* Remove route */
|
||||
|
|
@ -293,7 +293,7 @@ test_ip6_route (void)
|
|||
rts[2].mss = mss;
|
||||
g_assert_cmpint (routes->len, ==, 3);
|
||||
g_assert (!memcmp (routes->data, rts, sizeof (rts)));
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, rts, routes->len);
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, rts, routes->len, TRUE);
|
||||
g_array_unref (routes);
|
||||
|
||||
/* Remove route */
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
|
|||
* 8.0.0.0/8 could not be added. */
|
||||
routes = ip4_routes (fixture);
|
||||
g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state1));
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state1, routes->len);
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state1, routes->len, TRUE);
|
||||
g_array_free (routes, TRUE);
|
||||
|
||||
setup_dev1_ip4 (fixture->ifindex1);
|
||||
|
|
@ -265,7 +265,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
|
|||
/* Ensure nothing changed. */
|
||||
routes = ip4_routes (fixture);
|
||||
g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state1));
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state1, routes->len);
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state1, routes->len, TRUE);
|
||||
g_array_free (routes, TRUE);
|
||||
|
||||
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*error adding 8.0.0.0/8 via 6.6.6.2 dev nm-test-device1 *");
|
||||
|
|
@ -275,7 +275,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
|
|||
/* 7.0.0.0/8 on dev0 was updated for gateway removal*/
|
||||
routes = ip4_routes (fixture);
|
||||
g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state2));
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state2, routes->len);
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state2, routes->len, TRUE);
|
||||
g_array_free (routes, TRUE);
|
||||
|
||||
nm_route_manager_route_flush (nm_route_manager_get (), fixture->ifindex0);
|
||||
|
|
@ -286,7 +286,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
|
|||
* No dev0 routes left. */
|
||||
routes = ip4_routes (fixture);
|
||||
g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state3));
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state3, routes->len);
|
||||
nmtst_platform_ip4_routes_equal ((NMPlatformIP4Route *) routes->data, state3, routes->len, TRUE);
|
||||
g_array_free (routes, TRUE);
|
||||
|
||||
nm_route_manager_route_flush (nm_route_manager_get (), fixture->ifindex1);
|
||||
|
|
@ -592,7 +592,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
|
|||
* 2001:db8:abad:c0de::/64 routes did not clash */
|
||||
routes = ip6_routes (fixture);
|
||||
g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state1));
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state1, routes->len);
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state1, routes->len, TRUE);
|
||||
g_array_free (routes, TRUE);
|
||||
|
||||
setup_dev1_ip6 (fixture->ifindex1);
|
||||
|
|
@ -603,7 +603,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
|
|||
/* Ensure nothing changed. */
|
||||
routes = ip6_routes (fixture);
|
||||
g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state1));
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state1, routes->len);
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state1, routes->len, TRUE);
|
||||
g_array_free (routes, TRUE);
|
||||
|
||||
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*error adding 2001:db8:d34d::/64 via 2001:db8:8086::2 dev nm-test-device1 *");
|
||||
|
|
@ -613,7 +613,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
|
|||
/* 2001:db8:abad:c0de::/64 on dev0 was updated for gateway removal*/
|
||||
routes = ip6_routes (fixture);
|
||||
g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state2));
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state2, routes->len);
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state2, routes->len, TRUE);
|
||||
g_array_free (routes, TRUE);
|
||||
|
||||
nm_route_manager_route_flush (nm_route_manager_get (), fixture->ifindex0);
|
||||
|
|
@ -625,7 +625,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
|
|||
* No dev0 routes left. */
|
||||
routes = ip6_routes (fixture);
|
||||
g_assert_cmpint (routes->len, ==, G_N_ELEMENTS (state3));
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state3, routes->len);
|
||||
nmtst_platform_ip6_routes_equal ((NMPlatformIP6Route *) routes->data, state3, routes->len, TRUE);
|
||||
g_array_free (routes, TRUE);
|
||||
|
||||
nm_route_manager_route_flush (nm_route_manager_get (), fixture->ifindex1);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue