diff options
Diffstat (limited to 'src/devices/tests')
| -rw-r--r-- | src/devices/tests/Makefile.am | 18 | ||||
| -rw-r--r-- | src/devices/tests/Makefile.in | 88 | ||||
| -rw-r--r-- | src/devices/tests/test-arping.c | 139 | ||||
| -rw-r--r-- | src/devices/tests/test-lldp.c | 44 |
4 files changed, 259 insertions, 30 deletions
diff --git a/src/devices/tests/Makefile.am b/src/devices/tests/Makefile.am index 330377b0..e4f4d3fe 100644 --- a/src/devices/tests/Makefile.am +++ b/src/devices/tests/Makefile.am @@ -23,7 +23,8 @@ DEVICES_LDADD = \ @GNOME_CODE_COVERAGE_RULES@ noinst_PROGRAMS = \ - test-lldp + test-lldp \ + test-arping test_lldp_SOURCES = \ test-lldp.c \ @@ -37,6 +38,19 @@ test_lldp_CPPFLAGS = \ test_lldp_LDADD = $(DEVICES_LDADD) +test_arping_SOURCES = \ + test-arping.c \ + ../nm-arping-manager.c \ + $(top_srcdir)/src/platform/tests/test-common.c + +test_arping_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I$(top_srcdir)/src/platform/tests \ + -DSETUP=nm_linux_platform_setup + +test_arping_LDADD = $(DEVICES_LDADD) + @VALGRIND_RULES@ TESTS = \ - test-lldp + test-lldp \ + test-arping diff --git a/src/devices/tests/Makefile.in b/src/devices/tests/Makefile.in index 1cfe46b6..1cb73d28 100644 --- a/src/devices/tests/Makefile.in +++ b/src/devices/tests/Makefile.in @@ -88,8 +88,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -noinst_PROGRAMS = test-lldp$(EXEEXT) -TESTS = test-lldp$(EXEEXT) +noinst_PROGRAMS = test-lldp$(EXEEXT) test-arping$(EXEEXT) +TESTS = test-lldp$(EXEEXT) test-arping$(EXEEXT) subdir = src/devices/tests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \ @@ -113,15 +113,20 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) +am_test_arping_OBJECTS = test_arping-test-arping.$(OBJEXT) \ + test_arping-nm-arping-manager.$(OBJEXT) \ + test_arping-test-common.$(OBJEXT) +test_arping_OBJECTS = $(am_test_arping_OBJECTS) +test_arping_DEPENDENCIES = $(DEVICES_LDADD) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = am_test_lldp_OBJECTS = test_lldp-test-lldp.$(OBJEXT) \ test_lldp-nm-lldp-listener.$(OBJEXT) \ test_lldp-test-common.$(OBJEXT) test_lldp_OBJECTS = $(am_test_lldp_OBJECTS) test_lldp_DEPENDENCIES = $(DEVICES_LDADD) -AM_V_lt = $(am__v_lt_@AM_V@) -am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) -am__v_lt_0 = --silent -am__v_lt_1 = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -156,8 +161,8 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(test_lldp_SOURCES) -DIST_SOURCES = $(test_lldp_SOURCES) +SOURCES = $(test_arping_SOURCES) $(test_lldp_SOURCES) +DIST_SOURCES = $(test_arping_SOURCES) $(test_lldp_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -685,6 +690,17 @@ test_lldp_CPPFLAGS = \ -DSETUP=nm_linux_platform_setup test_lldp_LDADD = $(DEVICES_LDADD) +test_arping_SOURCES = \ + test-arping.c \ + ../nm-arping-manager.c \ + $(top_srcdir)/src/platform/tests/test-common.c + +test_arping_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I$(top_srcdir)/src/platform/tests \ + -DSETUP=nm_linux_platform_setup + +test_arping_LDADD = $(DEVICES_LDADD) all: all-am .SUFFIXES: @@ -728,6 +744,10 @@ clean-noinstPROGRAMS: echo " rm -f" $$list; \ rm -f $$list +test-arping$(EXEEXT): $(test_arping_OBJECTS) $(test_arping_DEPENDENCIES) $(EXTRA_test_arping_DEPENDENCIES) + @rm -f test-arping$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(test_arping_OBJECTS) $(test_arping_LDADD) $(LIBS) + test-lldp$(EXEEXT): $(test_lldp_OBJECTS) $(test_lldp_DEPENDENCIES) $(EXTRA_test_lldp_DEPENDENCIES) @rm -f test-lldp$(EXEEXT) $(AM_V_CCLD)$(LINK) $(test_lldp_OBJECTS) $(test_lldp_LDADD) $(LIBS) @@ -738,6 +758,9 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_arping-nm-arping-manager.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_arping-test-arping.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_arping-test-common.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_lldp-nm-lldp-listener.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_lldp-test-common.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_lldp-test-lldp.Po@am__quote@ @@ -763,6 +786,48 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +test_arping-test-arping.o: test-arping.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_arping-test-arping.o -MD -MP -MF $(DEPDIR)/test_arping-test-arping.Tpo -c -o test_arping-test-arping.o `test -f 'test-arping.c' || echo '$(srcdir)/'`test-arping.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_arping-test-arping.Tpo $(DEPDIR)/test_arping-test-arping.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='test-arping.c' object='test_arping-test-arping.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_arping-test-arping.o `test -f 'test-arping.c' || echo '$(srcdir)/'`test-arping.c + +test_arping-test-arping.obj: test-arping.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_arping-test-arping.obj -MD -MP -MF $(DEPDIR)/test_arping-test-arping.Tpo -c -o test_arping-test-arping.obj `if test -f 'test-arping.c'; then $(CYGPATH_W) 'test-arping.c'; else $(CYGPATH_W) '$(srcdir)/test-arping.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_arping-test-arping.Tpo $(DEPDIR)/test_arping-test-arping.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='test-arping.c' object='test_arping-test-arping.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_arping-test-arping.obj `if test -f 'test-arping.c'; then $(CYGPATH_W) 'test-arping.c'; else $(CYGPATH_W) '$(srcdir)/test-arping.c'; fi` + +test_arping-nm-arping-manager.o: ../nm-arping-manager.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_arping-nm-arping-manager.o -MD -MP -MF $(DEPDIR)/test_arping-nm-arping-manager.Tpo -c -o test_arping-nm-arping-manager.o `test -f '../nm-arping-manager.c' || echo '$(srcdir)/'`../nm-arping-manager.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_arping-nm-arping-manager.Tpo $(DEPDIR)/test_arping-nm-arping-manager.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../nm-arping-manager.c' object='test_arping-nm-arping-manager.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_arping-nm-arping-manager.o `test -f '../nm-arping-manager.c' || echo '$(srcdir)/'`../nm-arping-manager.c + +test_arping-nm-arping-manager.obj: ../nm-arping-manager.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_arping-nm-arping-manager.obj -MD -MP -MF $(DEPDIR)/test_arping-nm-arping-manager.Tpo -c -o test_arping-nm-arping-manager.obj `if test -f '../nm-arping-manager.c'; then $(CYGPATH_W) '../nm-arping-manager.c'; else $(CYGPATH_W) '$(srcdir)/../nm-arping-manager.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_arping-nm-arping-manager.Tpo $(DEPDIR)/test_arping-nm-arping-manager.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../nm-arping-manager.c' object='test_arping-nm-arping-manager.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_arping-nm-arping-manager.obj `if test -f '../nm-arping-manager.c'; then $(CYGPATH_W) '../nm-arping-manager.c'; else $(CYGPATH_W) '$(srcdir)/../nm-arping-manager.c'; fi` + +test_arping-test-common.o: $(top_srcdir)/src/platform/tests/test-common.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_arping-test-common.o -MD -MP -MF $(DEPDIR)/test_arping-test-common.Tpo -c -o test_arping-test-common.o `test -f '$(top_srcdir)/src/platform/tests/test-common.c' || echo '$(srcdir)/'`$(top_srcdir)/src/platform/tests/test-common.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_arping-test-common.Tpo $(DEPDIR)/test_arping-test-common.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(top_srcdir)/src/platform/tests/test-common.c' object='test_arping-test-common.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_arping-test-common.o `test -f '$(top_srcdir)/src/platform/tests/test-common.c' || echo '$(srcdir)/'`$(top_srcdir)/src/platform/tests/test-common.c + +test_arping-test-common.obj: $(top_srcdir)/src/platform/tests/test-common.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_arping-test-common.obj -MD -MP -MF $(DEPDIR)/test_arping-test-common.Tpo -c -o test_arping-test-common.obj `if test -f '$(top_srcdir)/src/platform/tests/test-common.c'; then $(CYGPATH_W) '$(top_srcdir)/src/platform/tests/test-common.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/src/platform/tests/test-common.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_arping-test-common.Tpo $(DEPDIR)/test_arping-test-common.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(top_srcdir)/src/platform/tests/test-common.c' object='test_arping-test-common.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_arping_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_arping-test-common.obj `if test -f '$(top_srcdir)/src/platform/tests/test-common.c'; then $(CYGPATH_W) '$(top_srcdir)/src/platform/tests/test-common.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/src/platform/tests/test-common.c'; fi` + test_lldp-test-lldp.o: test-lldp.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_lldp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_lldp-test-lldp.o -MD -MP -MF $(DEPDIR)/test_lldp-test-lldp.Tpo -c -o test_lldp-test-lldp.o `test -f 'test-lldp.c' || echo '$(srcdir)/'`test-lldp.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_lldp-test-lldp.Tpo $(DEPDIR)/test_lldp-test-lldp.Po @@ -1011,6 +1076,13 @@ test-lldp.log: test-lldp$(EXEEXT) --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +test-arping.log: test-arping$(EXEEXT) + @p='test-arping$(EXEEXT)'; \ + b='test-arping'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) .test.log: @p='$<'; \ $(am__set_b); \ diff --git a/src/devices/tests/test-arping.c b/src/devices/tests/test-arping.c new file mode 100644 index 00000000..36e17631 --- /dev/null +++ b/src/devices/tests/test-arping.c @@ -0,0 +1,139 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* nm-platform.c - Handle runtime kernel networking configuration + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2015 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-arping-manager.h" +#include "test-common.h" + +#define IFACE_VETH0 "nm-test-veth0" +#define IFACE_VETH1 "nm-test-veth1" + +#define ADDR1 0x01010101 +#define ADDR2 0x02020202 +#define ADDR3 0x03030303 +#define ADDR4 0x04040404 + +typedef struct { + int ifindex0; + int ifindex1; +} test_fixture; + +static void +fixture_setup (test_fixture *fixture, gconstpointer user_data) +{ + /* create veth pair. */ + nmtstp_run_command_check ("ip link add dev %s type veth peer name %s", IFACE_VETH0, IFACE_VETH1); + fixture->ifindex0 = nmtstp_assert_wait_for_link (IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex; + fixture->ifindex1 = nmtstp_assert_wait_for_link (IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex; + + 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)); +} + +typedef struct { + in_addr_t addresses[8]; + in_addr_t peer_addresses[8]; + gboolean expected_result[8]; +} TestInfo; + +static void +arping_manager_probe_terminated (NMArpingManager *arping_manager, GMainLoop *loop) +{ + g_main_loop_quit (loop); +} + +static void +test_arping_common (test_fixture *fixture, TestInfo *info) +{ + gs_unref_object NMArpingManager *manager = NULL; + GMainLoop *loop; + int i; + + if (!nm_utils_find_helper ("arping", NULL, NULL)) { + g_test_skip ("arping binary is missing"); + return; + } + + manager = nm_arping_manager_new (fixture->ifindex0); + g_assert (manager != NULL); + + for (i = 0; info->addresses[i]; i++) + g_assert (nm_arping_manager_add_address (manager, info->addresses[i])); + + for (i = 0; info->peer_addresses[i]; i++) { + nmtstp_ip4_address_add (FALSE, fixture->ifindex1, info->peer_addresses[i], + 24, 0, 3600, 1800, NULL); + } + + loop = g_main_loop_new (NULL, FALSE); + g_signal_connect (manager, NM_ARPING_MANAGER_PROBE_TERMINATED, + G_CALLBACK (arping_manager_probe_terminated), loop); + g_assert (nm_arping_manager_start_probe (manager, 100, NULL)); + g_assert (nmtst_main_loop_run (loop, 1000)); + + for (i = 0; info->addresses[i]; i++) { + g_assert_cmpint (nm_arping_manager_check_address (manager, info->addresses[i]), + ==, + info->expected_result[i]); + } + + g_main_loop_unref (loop); +} + +static void +test_arping_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); +} + +static void +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_arping_common (fixture, &info); +} + +static void +fixture_teardown (test_fixture *fixture, gconstpointer user_data) +{ + nm_platform_link_delete (NM_PLATFORM_GET, fixture->ifindex0); + nm_platform_link_delete (NM_PLATFORM_GET, fixture->ifindex1); +} + +void +init_tests (int *argc, char ***argv) +{ + nmtst_init_with_logging (argc, argv, NULL, "ALL"); +} + +void +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); +} diff --git a/src/devices/tests/test-lldp.c b/src/devices/tests/test-lldp.c index c339d9ca..dfae58b1 100644 --- a/src/devices/tests/test-lldp.c +++ b/src/devices/tests/test-lldp.c @@ -18,7 +18,7 @@ * Copyright (C) 2015 Red Hat, Inc. */ -#include "config.h" +#include "nm-default.h" #include <fcntl.h> #include <linux/if_tun.h> @@ -26,7 +26,6 @@ #include <sys/stat.h> #include <sys/types.h> -#include "nm-default.h" #include "nm-lldp-listener.h" #include "test-common.h" @@ -95,7 +94,6 @@ get_lldp_neighbor_attribute (GVariant *neighbors, GVariantIter iter, attrs_iter; GVariant *variant, *attr_variant; const char *attr_name; - GVariant *chassis_v, *port_v, *attr_v; g_return_val_if_fail (g_variant_is_of_type (neighbors, G_VARIANT_TYPE ("aa{sv}")), @@ -103,31 +101,34 @@ get_lldp_neighbor_attribute (GVariant *neighbors, g_variant_iter_init (&iter, neighbors); while (g_variant_iter_next (&iter, "@a{sv}", &variant)) { - g_variant_iter_init (&attrs_iter, variant); - chassis_v = NULL; - port_v = NULL; - attr_v = NULL; + gs_unref_variant GVariant *chassis_v = NULL; + gs_unref_variant GVariant *port_v = NULL; + gs_unref_variant GVariant *attr_v = NULL; + g_variant_iter_init (&attrs_iter, variant); while (g_variant_iter_next (&attrs_iter, "{&sv}", &attr_name, &attr_variant)) { - if (!g_strcmp0 (attr_name, NM_LLDP_ATTR_CHASSIS_ID)) + if (!g_strcmp0 (attr_name, NM_LLDP_ATTR_CHASSIS_ID)) { + g_assert (!chassis_v); chassis_v = attr_variant; - else if (!g_strcmp0 (attr_name, NM_LLDP_ATTR_PORT_ID)) + } else if (!g_strcmp0 (attr_name, NM_LLDP_ATTR_PORT_ID)) { + g_assert (!port_v); port_v = attr_variant; - else if (!g_strcmp0 (attr_name, name)) + } else if (!g_strcmp0 (attr_name, name)) { + g_assert (!attr_v); attr_v = attr_variant; + } else + g_variant_unref (attr_variant); } - if ( g_variant_is_of_type (chassis_v, G_VARIANT_TYPE_STRING) + g_variant_unref (variant); + + if ( chassis_v + && port_v + && g_variant_is_of_type (chassis_v, G_VARIANT_TYPE_STRING) && g_variant_is_of_type (port_v, G_VARIANT_TYPE_STRING) && !g_strcmp0 (chassis, g_variant_get_string (chassis_v, NULL)) - && !g_strcmp0 (port, g_variant_get_string (port_v, NULL))) { - - g_variant_ref (attr_v); - g_variant_unref (variant); - - return attr_v; - } - g_variant_unref (variant); + && !g_strcmp0 (port, g_variant_get_string (port_v, NULL))) + return g_variant_ref (attr_v); } /* neighbor not found */ @@ -137,7 +138,7 @@ get_lldp_neighbor_attribute (GVariant *neighbors, static void test_receive_frame (test_fixture *fixture, gconstpointer user_data) { - NMLldpListener *listener; + gs_unref_object NMLldpListener *listener = NULL; GMainLoop *loop; TestInfo info = { }; GVariant *neighbors, *attr; @@ -182,6 +183,7 @@ test_receive_frame (test_fixture *fixture, gconstpointer user_data) g_assert (attr != NULL); g_assert (g_variant_is_of_type (attr, G_VARIANT_TYPE_STRING)); g_assert_cmpstr (g_variant_get_string (attr, NULL), ==, "Port"); + nm_clear_g_variant (&attr); /* Check system name */ attr = get_lldp_neighbor_attribute (neighbors, "00:01:02:03:04:05", "1/3", @@ -189,6 +191,7 @@ test_receive_frame (test_fixture *fixture, gconstpointer user_data) g_assert (attr != NULL); g_assert (g_variant_is_of_type (attr, G_VARIANT_TYPE_STRING)); g_assert_cmpstr (g_variant_get_string (attr, NULL), ==, "SYS"); + nm_clear_g_variant (&attr); /* Check destination */ attr = get_lldp_neighbor_attribute (neighbors, "00:01:02:03:04:05", "1/3", @@ -197,6 +200,7 @@ test_receive_frame (test_fixture *fixture, gconstpointer user_data) g_assert (g_variant_is_of_type (attr, G_VARIANT_TYPE_STRING)); g_assert_cmpstr (g_variant_get_string (attr, NULL), ==, NM_LLDP_DEST_NEAREST_NON_TPMR_BRIDGE); + nm_clear_g_variant (&attr); g_clear_pointer (&loop, g_main_loop_unref); } |