summary refs log tree commit diff
path: root/src/devices/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/tests')
-rw-r--r--src/devices/tests/meson.build18
-rw-r--r--src/devices/tests/test-arping.c (renamed from src/devices/tests/test-acd.c)63
-rw-r--r--src/devices/tests/test-lldp.c52
3 files changed, 35 insertions, 98 deletions
diff --git a/src/devices/tests/meson.build b/src/devices/tests/meson.build
deleted file mode 100644
index 02c61ced..00000000
--- a/src/devices/tests/meson.build
+++ /dev/null
@@ -1,18 +0,0 @@
-test_units = [
-  'test-acd',
-  'test-lldp'
-]
-
-foreach test_unit: test_units
-  exe = executable(
-    test_unit,
-    test_unit + '.c',
-    dependencies: test_nm_dep
-  )
-
-  test(
-    'devices/' + test_unit,
-    test_script,
-    args: test_args + [exe.full_path()]
-  )
-endforeach
diff --git a/src/devices/tests/test-acd.c b/src/devices/tests/test-arping.c
index 8a2852a2..f0537545 100644
--- a/src/devices/tests/test-acd.c
+++ b/src/devices/tests/test-arping.c
@@ -20,7 +20,7 @@
 
 #include "nm-default.h"
 
-#include "devices/nm-acd-manager.h"
+#include "devices/nm-arping-manager.h"
 #include "platform/tests/test-common.h"
 
 #define IFACE_VETH0 "nm-test-veth0"
@@ -34,10 +34,6 @@
 typedef struct {
 	int ifindex0;
 	int ifindex1;
-	const guint8 *hwaddr0;
-	const guint8 *hwaddr1;
-	size_t hwaddr0_len;
-	size_t hwaddr1_len;
 } test_fixture;
 
 static void
@@ -49,9 +45,6 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data)
 
 	g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex0, NULL));
 	g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex1, NULL));
-
-	fixture->hwaddr0 = nm_platform_link_get_address (NM_PLATFORM_GET, fixture->ifindex0, &fixture->hwaddr0_len);
-	fixture->hwaddr1 = nm_platform_link_get_address (NM_PLATFORM_GET, fixture->ifindex1, &fixture->hwaddr1_len);
 }
 
 typedef struct {
@@ -61,21 +54,26 @@ typedef struct {
 } TestInfo;
 
 static void
-acd_manager_probe_terminated (NMAcdManager *acd_manager, GMainLoop *loop)
+arping_manager_probe_terminated (NMArpingManager *arping_manager, GMainLoop *loop)
 {
 	g_main_loop_quit (loop);
 }
 
 static void
-test_acd_common (test_fixture *fixture, TestInfo *info)
+test_arping_common (test_fixture *fixture, TestInfo *info)
 {
-	gs_unref_object NMAcdManager *manager = NULL;
+	gs_unref_object NMArpingManager *manager = NULL;
 	GMainLoop *loop;
 	int i;
 	const guint WAIT_TIME_OPTIMISTIC = 50;
 	guint wait_time;
 	gulong signal_id;
 
+	if (!nm_utils_find_helper ("arping", NULL, NULL)) {
+		g_test_skip ("arping binary is missing");
+		return;
+	}
+
 	/* first, try with a short waittime. We hope that this is long enough
 	 * to successfully complete the test. Only if that's not the case, we
 	 * assume the computer is currently busy (high load) and we retry with
@@ -83,11 +81,11 @@ test_acd_common (test_fixture *fixture, TestInfo *info)
 	wait_time = WAIT_TIME_OPTIMISTIC;
 again:
 
-	manager = nm_acd_manager_new (fixture->ifindex0, fixture->hwaddr0, fixture->hwaddr0_len);
+	manager = nm_arping_manager_new (fixture->ifindex0);
 	g_assert (manager != NULL);
 
 	for (i = 0; info->addresses[i]; i++)
-		g_assert (nm_acd_manager_add_address (manager, info->addresses[i]));
+		g_assert (nm_arping_manager_add_address (manager, info->addresses[i]));
 
 	for (i = 0; info->peer_addresses[i]; i++) {
 		nmtstp_ip4_address_add (NULL, FALSE, fixture->ifindex1, info->peer_addresses[i],
@@ -95,9 +93,9 @@ again:
 	}
 
 	loop = g_main_loop_new (NULL, FALSE);
-	signal_id = g_signal_connect (manager, NM_ACD_MANAGER_PROBE_TERMINATED,
-	                              G_CALLBACK (acd_manager_probe_terminated), loop);
-	g_assert (nm_acd_manager_start_probe (manager, wait_time));
+	signal_id = g_signal_connect (manager, NM_ARPING_MANAGER_PROBE_TERMINATED,
+	                              G_CALLBACK (arping_manager_probe_terminated), loop);
+	g_assert (nm_arping_manager_start_probe (manager, wait_time, NULL));
 	g_assert (nmtst_main_loop_run (loop, 2000));
 	g_signal_handler_disconnect (manager, signal_id);
 	g_main_loop_unref (loop);
@@ -105,7 +103,7 @@ again:
 	for (i = 0; info->addresses[i]; i++) {
 		gboolean val;
 
-		val = nm_acd_manager_check_address (manager, info->addresses[i]);
+		val = nm_arping_manager_check_address (manager, info->addresses[i]);
 		if (val == info->expected_result[i])
 			continue;
 
@@ -124,41 +122,23 @@ again:
 }
 
 static void
-test_acd_probe_1 (test_fixture *fixture, gconstpointer user_data)
+test_arping_1 (test_fixture *fixture, gconstpointer user_data)
 {
 	TestInfo info = { .addresses       = { ADDR1, ADDR2, ADDR3 },
 	                  .peer_addresses  = { ADDR4 },
 	                  .expected_result = { TRUE, TRUE, TRUE } };
 
-	test_acd_common (fixture, &info);
+	test_arping_common (fixture, &info);
 }
 
 static void
-test_acd_probe_2 (test_fixture *fixture, gconstpointer user_data)
+test_arping_2 (test_fixture *fixture, gconstpointer user_data)
 {
 	TestInfo info = { .addresses       = { ADDR1, ADDR2, ADDR3, ADDR4 },
 	                  .peer_addresses  = { ADDR3, ADDR2 },
 	                  .expected_result = { TRUE, FALSE, FALSE, TRUE } };
 
-	test_acd_common (fixture, &info);
-}
-
-static void
-test_acd_announce (test_fixture *fixture, gconstpointer user_data)
-{
-	gs_unref_object NMAcdManager *manager = NULL;
-	GMainLoop *loop;
-
-	manager = nm_acd_manager_new (fixture->ifindex0, fixture->hwaddr0, fixture->hwaddr0_len);
-	g_assert (manager != NULL);
-
-	g_assert (nm_acd_manager_add_address (manager, ADDR1));
-	g_assert (nm_acd_manager_add_address (manager, ADDR2));
-
-	loop = g_main_loop_new (NULL, FALSE);
-	nm_acd_manager_announce_addresses (manager);
-	g_assert (!nmtst_main_loop_run (loop, 200));
-	g_main_loop_unref (loop);
+	test_arping_common (fixture, &info);
 }
 
 static void
@@ -179,7 +159,6 @@ _nmtstp_init_tests (int *argc, char ***argv)
 void
 _nmtstp_setup_tests (void)
 {
-	g_test_add ("/acd/probe/1", test_fixture, NULL, fixture_setup, test_acd_probe_1, fixture_teardown);
-	g_test_add ("/acd/probe/2", test_fixture, NULL, fixture_setup, test_acd_probe_2, fixture_teardown);
-	g_test_add ("/acd/announce", test_fixture, NULL, fixture_setup, test_acd_announce, fixture_teardown);
+	g_test_add ("/arping/1", test_fixture, NULL, fixture_setup, test_arping_1, fixture_teardown);
+	g_test_add ("/arping/2", test_fixture, NULL, fixture_setup, test_arping_2, fixture_teardown);
 }
diff --git a/src/devices/tests/test-lldp.c b/src/devices/tests/test-lldp.c
index 5d0625f8..c3c4f0d2 100644
--- a/src/devices/tests/test-lldp.c
+++ b/src/devices/tests/test-lldp.c
@@ -347,7 +347,8 @@ static void
 _test_recv_fixture_setup (TestRecvFixture *fixture, gconstpointer user_data)
 {
 	const NMPlatformLink *link;
-	nm_auto_close int fd = -1;
+	struct ifreq ifr = { };
+	int fd, s;
 
 	fd = open ("/dev/net/tun", O_RDWR | O_CLOEXEC);
 	if (fd == -1) {
@@ -356,45 +357,20 @@ _test_recv_fixture_setup (TestRecvFixture *fixture, gconstpointer user_data)
 		return;
 	}
 
-	if (nmtst_get_rand_bool ()) {
-		const NMPlatformLnkTun lnk = {
-			.type = IFF_TAP,
-			.pi = FALSE,
-			.vnet_hdr = FALSE,
-			.multi_queue = FALSE,
-			.persist = FALSE,
-		};
-
-		nm_close (nm_steal_fd (&fd));
-
-		link = nmtstp_link_tun_add (NM_PLATFORM_GET,
-		                            FALSE,
-		                            TEST_IFNAME,
-		                            &lnk,
-		                            &fd);
-		g_assert (link);
-		nmtstp_link_set_updown (NM_PLATFORM_GET, -1, link->ifindex, TRUE);
-		link = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, TEST_IFNAME, NM_LINK_TYPE_TUN, 0);
-	} else {
-		int s;
-		struct ifreq ifr = { };
-
-		ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-		nm_utils_ifname_cpy (ifr.ifr_name, TEST_IFNAME);
-		g_assert (ioctl (fd, TUNSETIFF, &ifr) >= 0);
-
-		/* Bring the interface up */
-		s = socket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
-		g_assert (s >= 0);
-		ifr.ifr_flags |= IFF_UP;
-		g_assert (ioctl (s, SIOCSIFFLAGS, &ifr) >= 0);
-		nm_close (s);
-
-		link = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, TEST_IFNAME, NM_LINK_TYPE_TUN, 100);
-	}
+	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+	nm_utils_ifname_cpy (ifr.ifr_name, TEST_IFNAME);
+	g_assert (ioctl (fd, TUNSETIFF, &ifr) >= 0);
+
+	/* Bring the interface up */
+	s = socket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	g_assert (s >= 0);
+	ifr.ifr_flags |= IFF_UP;
+	g_assert (ioctl (s, SIOCSIFFLAGS, &ifr) >= 0);
+	nm_close (s);
 
+	link = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, TEST_IFNAME, NM_LINK_TYPE_TAP, 100);
 	fixture->ifindex = link->ifindex;
-	fixture->fd = nm_steal_fd (&fd);
+	fixture->fd = fd;
 	memcpy (fixture->mac, link->addr.data, ETH_ALEN);
 }