diff options
| author | Michael Biebl <biebl@debian.org> | 2018-06-04 00:07:45 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2018-06-04 00:07:45 +0200 |
| commit | 04bc9e1cd3544445d883ad29ea108c1645c8e7b7 (patch) | |
| tree | d10c354b1b980ca8a7b9e48ec9019e8ed88bde2b /src/devices/tests | |
| parent | ee9c73a923909e23a649407be77e25235d769e25 (diff) | |
New upstream version 1.11.4 upstream/1.11.4
Diffstat (limited to 'src/devices/tests')
| -rw-r--r-- | src/devices/tests/meson.build | 18 | ||||
| -rw-r--r-- | src/devices/tests/test-acd.c (renamed from src/devices/tests/test-arping.c) | 63 | ||||
| -rw-r--r-- | src/devices/tests/test-lldp.c | 53 |
3 files changed, 98 insertions, 36 deletions
diff --git a/src/devices/tests/meson.build b/src/devices/tests/meson.build new file mode 100644 index 00000000..02c61ced --- /dev/null +++ b/src/devices/tests/meson.build @@ -0,0 +1,18 @@ +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-arping.c b/src/devices/tests/test-acd.c index f0537545..8a2852a2 100644 --- a/src/devices/tests/test-arping.c +++ b/src/devices/tests/test-acd.c @@ -20,7 +20,7 @@ #include "nm-default.h" -#include "devices/nm-arping-manager.h" +#include "devices/nm-acd-manager.h" #include "platform/tests/test-common.h" #define IFACE_VETH0 "nm-test-veth0" @@ -34,6 +34,10 @@ typedef struct { int ifindex0; int ifindex1; + const guint8 *hwaddr0; + const guint8 *hwaddr1; + size_t hwaddr0_len; + size_t hwaddr1_len; } test_fixture; static void @@ -45,6 +49,9 @@ 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 { @@ -54,26 +61,21 @@ typedef struct { } TestInfo; static void -arping_manager_probe_terminated (NMArpingManager *arping_manager, GMainLoop *loop) +acd_manager_probe_terminated (NMAcdManager *acd_manager, GMainLoop *loop) { g_main_loop_quit (loop); } static void -test_arping_common (test_fixture *fixture, TestInfo *info) +test_acd_common (test_fixture *fixture, TestInfo *info) { - gs_unref_object NMArpingManager *manager = NULL; + gs_unref_object NMAcdManager *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 @@ -81,11 +83,11 @@ test_arping_common (test_fixture *fixture, TestInfo *info) wait_time = WAIT_TIME_OPTIMISTIC; again: - manager = nm_arping_manager_new (fixture->ifindex0); + manager = nm_acd_manager_new (fixture->ifindex0, fixture->hwaddr0, fixture->hwaddr0_len); g_assert (manager != NULL); for (i = 0; info->addresses[i]; i++) - g_assert (nm_arping_manager_add_address (manager, info->addresses[i])); + g_assert (nm_acd_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], @@ -93,9 +95,9 @@ again: } loop = g_main_loop_new (NULL, FALSE); - 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)); + 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)); g_assert (nmtst_main_loop_run (loop, 2000)); g_signal_handler_disconnect (manager, signal_id); g_main_loop_unref (loop); @@ -103,7 +105,7 @@ again: for (i = 0; info->addresses[i]; i++) { gboolean val; - val = nm_arping_manager_check_address (manager, info->addresses[i]); + val = nm_acd_manager_check_address (manager, info->addresses[i]); if (val == info->expected_result[i]) continue; @@ -122,23 +124,41 @@ again: } static void -test_arping_1 (test_fixture *fixture, gconstpointer user_data) +test_acd_probe_1 (test_fixture *fixture, gconstpointer user_data) { TestInfo info = { .addresses = { ADDR1, ADDR2, ADDR3 }, .peer_addresses = { ADDR4 }, .expected_result = { TRUE, TRUE, TRUE } }; - test_arping_common (fixture, &info); + test_acd_common (fixture, &info); } static void -test_arping_2 (test_fixture *fixture, gconstpointer user_data) +test_acd_probe_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_arping_common (fixture, &info); + 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); } static void @@ -159,6 +179,7 @@ _nmtstp_init_tests (int *argc, char ***argv) void _nmtstp_setup_tests (void) { - 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); + 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); } diff --git a/src/devices/tests/test-lldp.c b/src/devices/tests/test-lldp.c index c3c4f0d2..c2ac8e19 100644 --- a/src/devices/tests/test-lldp.c +++ b/src/devices/tests/test-lldp.c @@ -169,7 +169,6 @@ _test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener) TEST_RECV_DATA_DEFINE (_test_recv_data0, 1, _test_recv_data0_check, &_test_recv_data0_frame0); TEST_RECV_DATA_DEFINE (_test_recv_data0_twice, 1, _test_recv_data0_check, &_test_recv_data0_frame0, &_test_recv_data0_frame0); - TEST_RECV_FRAME_DEFINE (_test_recv_data1_frame0, /* lldp.detailed.pcap from * https://wiki.wireshark.org/SampleCaptures#Link_Layer_Discovery_Protocol_.28LLDP.29 */ @@ -347,8 +346,7 @@ static void _test_recv_fixture_setup (TestRecvFixture *fixture, gconstpointer user_data) { const NMPlatformLink *link; - struct ifreq ifr = { }; - int fd, s; + nm_auto_close int fd = -1; fd = open ("/dev/net/tun", O_RDWR | O_CLOEXEC); if (fd == -1) { @@ -357,20 +355,45 @@ _test_recv_fixture_setup (TestRecvFixture *fixture, gconstpointer user_data) return; } - 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); + 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); + } - link = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, TEST_IFNAME, NM_LINK_TYPE_TAP, 100); fixture->ifindex = link->ifindex; - fixture->fd = fd; + fixture->fd = nm_steal_fd (&fd); memcpy (fixture->mac, link->addr.data, ETH_ALEN); } |