mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 05:20:08 +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.
(cherry picked from commit 57453189e0)
Conflicts:
src/tests/test-route-manager.c
This commit is contained in:
parent
d0172aa4d6
commit
897ac18bbb
2 changed files with 32 additions and 4 deletions
|
|
@ -652,14 +652,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,
|
||||
|
|
@ -673,14 +687,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 */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue