platform: add test for address/route cleanup on link removal
The improved tests can be also used to test the previous commit.
This commit is contained in:
@@ -24,7 +24,9 @@ noinst_PROGRAMS = \
|
||||
test-address-fake \
|
||||
test-address-linux \
|
||||
test-route-fake \
|
||||
test-route-linux
|
||||
test-route-linux \
|
||||
test-cleanup-fake \
|
||||
test-cleanup-linux
|
||||
|
||||
EXTRA_DIST = test-common.h
|
||||
|
||||
@@ -106,6 +108,28 @@ test_route_linux_CPPFLAGS = \
|
||||
-DKERNEL_HACKS=1
|
||||
test_route_linux_LDADD = $(PLATFORM_LDADD)
|
||||
|
||||
test_cleanup_fake_SOURCES = \
|
||||
test-cleanup.c \
|
||||
test-common.c \
|
||||
${srcdir}/../nm-platform.c \
|
||||
${srcdir}/../nm-fake-platform.c
|
||||
test_cleanup_fake_CPPFLAGS = \
|
||||
$(AM_CPPFLAGS) \
|
||||
-DSETUP=nm_fake_platform_setup \
|
||||
-DKERNEL_HACKS=0
|
||||
test_cleanup_fake_LDADD = $(PLATFORM_LDADD)
|
||||
|
||||
test_cleanup_linux_SOURCES = \
|
||||
test-cleanup.c \
|
||||
test-common.c \
|
||||
${srcdir}/../nm-platform.c \
|
||||
${srcdir}/../nm-linux-platform.c
|
||||
test_cleanup_linux_CPPFLAGS = \
|
||||
$(AM_CPPFLAGS) \
|
||||
-DSETUP=nm_linux_platform_setup \
|
||||
-DKERNEL_HACKS=1
|
||||
test_cleanup_linux_LDADD = $(PLATFORM_LDADD)
|
||||
|
||||
# Unfortunately, we cannot run nm-linux-platform-test as an automatic test
|
||||
# program by default, as it requires root access and modifies kernel
|
||||
# configuration.
|
||||
@@ -114,8 +138,8 @@ test_route_linux_LDADD = $(PLATFORM_LDADD)
|
||||
# correctly.
|
||||
|
||||
@VALGRIND_RULES@
|
||||
TESTS = ./test-link-fake ./test-address-fake ./test-route-fake
|
||||
ROOTTESTS = ./test-link-linux ./test-address-linux ./test-route-linux
|
||||
TESTS = ./test-link-fake ./test-address-fake ./test-route-fake ./test-cleanup-fake
|
||||
ROOTTESTS = ./test-link-linux ./test-address-linux ./test-route-linux ./test-cleanup-linux
|
||||
|
||||
# If explicitly enabled, we can run the root tests
|
||||
if RUN_ROOT_TESTS
|
||||
|
89
src/platform/tests/test-cleanup.c
Normal file
89
src/platform/tests/test-cleanup.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "test-common.h"
|
||||
|
||||
#define DEVICE_NAME "nm-test-device"
|
||||
|
||||
static void
|
||||
test_cleanup_internal ()
|
||||
{
|
||||
int ifindex;
|
||||
GArray *addresses4;
|
||||
GArray *addresses6;
|
||||
GArray *routes4;
|
||||
GArray *routes6;
|
||||
in_addr_t addr4;
|
||||
in_addr_t network4;
|
||||
int plen4 = 24;
|
||||
in_addr_t gateway4;
|
||||
struct in6_addr addr6;
|
||||
struct in6_addr network6;
|
||||
int plen6 = 64;
|
||||
struct in6_addr gateway6;
|
||||
int metric = 20;
|
||||
int mss = 1000;
|
||||
|
||||
inet_pton (AF_INET, "192.0.2.1", &addr4);
|
||||
inet_pton (AF_INET, "192.0.3.0", &network4);
|
||||
inet_pton (AF_INET, "198.51.100.1", &gateway4);
|
||||
inet_pton (AF_INET6, "2001:db8:a:b:1:2:3:4", &addr6);
|
||||
inet_pton (AF_INET6, "2001:db8:c:d:0:0:0:0", &network6);
|
||||
inet_pton (AF_INET6, "2001:db8:e:f:1:2:3:4", &gateway6);
|
||||
|
||||
/* Create device */
|
||||
g_assert (nm_platform_dummy_add (DEVICE_NAME));
|
||||
ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
|
||||
g_assert (ifindex > 0);
|
||||
g_assert (nm_platform_link_set_up (ifindex));
|
||||
|
||||
/* Add routes and addresses */
|
||||
g_assert (nm_platform_ip4_address_add (ifindex, addr4, plen4));
|
||||
g_assert (nm_platform_ip6_address_add (ifindex, addr6, plen6));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, gateway4, 32, INADDR_ANY, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, network4, plen4, gateway4, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, 0, 0, gateway4, metric, mss));
|
||||
g_assert (nm_platform_ip6_route_add (ifindex, gateway6, 128, in6addr_any, metric, mss));
|
||||
g_assert (nm_platform_ip6_route_add (ifindex, network6, plen6, gateway6, metric, mss));
|
||||
g_assert (nm_platform_ip6_route_add (ifindex, in6addr_any, 0, gateway6, metric, mss));
|
||||
|
||||
addresses4 = nm_platform_ip4_address_get_all (ifindex);
|
||||
addresses6 = nm_platform_ip6_address_get_all (ifindex);
|
||||
routes4 = nm_platform_ip4_route_get_all (ifindex);
|
||||
routes6 = nm_platform_ip6_route_get_all (ifindex);
|
||||
|
||||
g_assert_cmpint (addresses4->len, ==, 1);
|
||||
g_assert_cmpint (addresses6->len, ==, 1);
|
||||
g_assert_cmpint (routes4->len, ==, 3);
|
||||
g_assert_cmpint (routes6->len, ==, 3);
|
||||
|
||||
g_array_unref (addresses4);
|
||||
g_array_unref (addresses6);
|
||||
g_array_unref (routes4);
|
||||
g_array_unref (routes6);
|
||||
|
||||
/* Delete interface with all addresses and routes */
|
||||
g_assert (nm_platform_link_delete (ifindex));
|
||||
|
||||
addresses4 = nm_platform_ip4_address_get_all (ifindex);
|
||||
addresses6 = nm_platform_ip6_address_get_all (ifindex);
|
||||
routes4 = nm_platform_ip4_route_get_all (ifindex);
|
||||
routes6 = nm_platform_ip6_route_get_all (ifindex);
|
||||
|
||||
g_assert_cmpint (addresses4->len, ==, 0);
|
||||
g_assert_cmpint (addresses6->len, ==, 0);
|
||||
g_assert_cmpint (routes4->len, ==, 0);
|
||||
g_assert_cmpint (routes6->len, ==, 0);
|
||||
|
||||
g_array_unref (addresses4);
|
||||
g_array_unref (addresses6);
|
||||
g_array_unref (routes4);
|
||||
g_array_unref (routes6);
|
||||
}
|
||||
|
||||
void
|
||||
setup_tests (void)
|
||||
{
|
||||
nm_platform_link_delete_by_name (DEVICE_NAME);
|
||||
g_assert (!nm_platform_link_exists (DEVICE_NAME));
|
||||
|
||||
g_test_add_func ("/internal", test_cleanup_internal);
|
||||
/* FIXME: add external cleanup check */
|
||||
}
|
@@ -52,8 +52,8 @@ test_ip4_route ()
|
||||
int metric = 20;
|
||||
int mss = 1000;
|
||||
|
||||
inet_pton (AF_INET, "192.0.2.0", &network);
|
||||
inet_pton (AF_INET, "198.51.100.0", &gateway);
|
||||
inet_pton (AF_INET, "192.0.3.0", &network);
|
||||
inet_pton (AF_INET, "198.51.100.1", &gateway);
|
||||
|
||||
/* Add route to gateway */
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, gateway, 32, INADDR_ANY, metric, mss)); no_error ();
|
||||
|
Reference in New Issue
Block a user