diff options
author | Thomas Haller <thaller@redhat.com> | 2015-03-26 18:05:42 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-04-09 11:21:08 +0200 |
commit | 897ac18bbbc3126a5437de449678d9df56d33f6f (patch) | |
tree | 88f5367d9e55900062ea49ee3b4c7a42be8b2610 | |
parent | d0172aa4d67714708bc50332818dcc70056d5c1d (diff) | |
download | NetworkManager-897ac18bbbc3126a5437de449678d9df56d33f6f.tar.gz |
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 57453189e05067be831d61805fbd45c7565b0085)
Conflicts:
src/tests/test-route-manager.c
-rw-r--r-- | include/nm-test-utils.h | 32 | ||||
-rw-r--r-- | src/platform/tests/test-route.c | 4 |
2 files changed, 32 insertions, 4 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index ab243e00cd..98aa5a5faf 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -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, diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c index d863057b2e..2d3caaf150 100644 --- a/src/platform/tests/test-route.c +++ b/src/platform/tests/test-route.c @@ -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 */ |