diff options
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/Makefile.am | 16 | ||||
| -rw-r--r-- | src/tests/Makefile.in | 64 | ||||
| -rw-r--r-- | src/tests/config/nm-test-device.c | 2 | ||||
| -rw-r--r-- | src/tests/config/test-config.c | 4 | ||||
| -rw-r--r-- | src/tests/test-dcb.c | 3 | ||||
| -rw-r--r-- | src/tests/test-general-with-expect.c | 57 | ||||
| -rw-r--r-- | src/tests/test-general.c | 155 | ||||
| -rw-r--r-- | src/tests/test-ip4-config.c | 3 | ||||
| -rw-r--r-- | src/tests/test-ip6-config.c | 3 | ||||
| -rw-r--r-- | src/tests/test-resolvconf-capture.c | 3 | ||||
| -rw-r--r-- | src/tests/test-route-manager.c | 3 | ||||
| -rw-r--r-- | src/tests/test-systemd.c | 53 | ||||
| -rw-r--r-- | src/tests/test-utils.c | 4 | ||||
| -rw-r--r-- | src/tests/test-wired-defname.c | 8 |
14 files changed, 321 insertions, 57 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 26c2ed7f..a3447fbf 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -23,6 +23,7 @@ noinst_PROGRAMS = \ test-route-manager-linux \ test-route-manager-fake \ test-dcb \ + test-systemd \ test-resolvconf-capture \ test-wired-defname \ test-utils @@ -111,6 +112,20 @@ test_wired_defname_SOURCES = \ test_wired_defname_LDADD = \ $(top_builddir)/src/libNetworkManager.la +####### systemd test ####### + +test_systemd_CFLAGS = \ + "-I$(srcdir)/../" \ + "-I$(srcdir)/../platform" \ + "-I$(srcdir)/../systemd/src/systemd" + +test_systemd_SOURCES = \ + test-systemd.c + +test_systemd_LDADD = \ + $(top_builddir)/src/libNetworkManager-base.la \ + $(top_builddir)/src/libsystemd-nm.la + ####### utils test ####### test_utils_SOURCES = \ @@ -143,6 +158,7 @@ TESTS = \ test-resolvconf-capture \ test-general \ test-general-with-expect \ + test-systemd \ test-wired-defname \ test-utils diff --git a/src/tests/Makefile.in b/src/tests/Makefile.in index e0967f7b..9d67063e 100644 --- a/src/tests/Makefile.in +++ b/src/tests/Makefile.in @@ -92,14 +92,14 @@ noinst_PROGRAMS = test-general$(EXEEXT) \ test-general-with-expect$(EXEEXT) test-ip4-config$(EXEEXT) \ test-ip6-config$(EXEEXT) test-route-manager-linux$(EXEEXT) \ test-route-manager-fake$(EXEEXT) test-dcb$(EXEEXT) \ - test-resolvconf-capture$(EXEEXT) test-wired-defname$(EXEEXT) \ - test-utils$(EXEEXT) + test-systemd$(EXEEXT) test-resolvconf-capture$(EXEEXT) \ + test-wired-defname$(EXEEXT) test-utils$(EXEEXT) TESTS = test-ip4-config$(EXEEXT) test-ip6-config$(EXEEXT) \ test-route-manager-fake$(EXEEXT) \ test-route-manager-linux$(EXEEXT) test-dcb$(EXEEXT) \ test-resolvconf-capture$(EXEEXT) test-general$(EXEEXT) \ - test-general-with-expect$(EXEEXT) test-wired-defname$(EXEEXT) \ - test-utils$(EXEEXT) + test-general-with-expect$(EXEEXT) test-systemd$(EXEEXT) \ + test-wired-defname$(EXEEXT) test-utils$(EXEEXT) subdir = src/tests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \ @@ -167,6 +167,14 @@ test_route_manager_linux_OBJECTS = \ $(am_test_route_manager_linux_OBJECTS) test_route_manager_linux_DEPENDENCIES = \ $(top_builddir)/src/libNetworkManager.la +am_test_systemd_OBJECTS = test_systemd-test-systemd.$(OBJEXT) +test_systemd_OBJECTS = $(am_test_systemd_OBJECTS) +test_systemd_DEPENDENCIES = \ + $(top_builddir)/src/libNetworkManager-base.la \ + $(top_builddir)/src/libsystemd-nm.la +test_systemd_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(test_systemd_CFLAGS) \ + $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ am_test_utils_OBJECTS = test_utils-test-utils.$(OBJEXT) test_utils_OBJECTS = $(am_test_utils_OBJECTS) am_test_wired_defname_OBJECTS = test-wired-defname.$(OBJEXT) @@ -211,14 +219,14 @@ SOURCES = $(test_dcb_SOURCES) $(test_general_SOURCES) \ $(test_general_with_expect_SOURCES) $(test_ip4_config_SOURCES) \ $(test_ip6_config_SOURCES) $(test_resolvconf_capture_SOURCES) \ $(test_route_manager_fake_SOURCES) \ - $(test_route_manager_linux_SOURCES) $(test_utils_SOURCES) \ - $(test_wired_defname_SOURCES) + $(test_route_manager_linux_SOURCES) $(test_systemd_SOURCES) \ + $(test_utils_SOURCES) $(test_wired_defname_SOURCES) DIST_SOURCES = $(test_dcb_SOURCES) $(test_general_SOURCES) \ $(test_general_with_expect_SOURCES) $(test_ip4_config_SOURCES) \ $(test_ip6_config_SOURCES) $(test_resolvconf_capture_SOURCES) \ $(test_route_manager_fake_SOURCES) \ - $(test_route_manager_linux_SOURCES) $(test_utils_SOURCES) \ - $(test_wired_defname_SOURCES) + $(test_route_manager_linux_SOURCES) $(test_systemd_SOURCES) \ + $(test_utils_SOURCES) $(test_wired_defname_SOURCES) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ @@ -855,6 +863,20 @@ test_wired_defname_LDADD = \ $(top_builddir)/src/libNetworkManager.la +####### systemd test ####### +test_systemd_CFLAGS = \ + "-I$(srcdir)/../" \ + "-I$(srcdir)/../platform" \ + "-I$(srcdir)/../systemd/src/systemd" + +test_systemd_SOURCES = \ + test-systemd.c + +test_systemd_LDADD = \ + $(top_builddir)/src/libNetworkManager-base.la \ + $(top_builddir)/src/libsystemd-nm.la + + ####### utils test ####### test_utils_SOURCES = \ test-utils.c @@ -948,6 +970,10 @@ test-route-manager-linux$(EXEEXT): $(test_route_manager_linux_OBJECTS) $(test_ro @rm -f test-route-manager-linux$(EXEEXT) $(AM_V_CCLD)$(LINK) $(test_route_manager_linux_OBJECTS) $(test_route_manager_linux_LDADD) $(LIBS) +test-systemd$(EXEEXT): $(test_systemd_OBJECTS) $(test_systemd_DEPENDENCIES) $(EXTRA_test_systemd_DEPENDENCIES) + @rm -f test-systemd$(EXEEXT) + $(AM_V_CCLD)$(test_systemd_LINK) $(test_systemd_OBJECTS) $(test_systemd_LDADD) $(LIBS) + test-utils$(EXEEXT): $(test_utils_OBJECTS) $(test_utils_DEPENDENCIES) $(EXTRA_test_utils_DEPENDENCIES) @rm -f test-utils$(EXEEXT) $(AM_V_CCLD)$(LINK) $(test_utils_OBJECTS) $(test_utils_LDADD) $(LIBS) @@ -973,6 +999,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_route_manager_fake-test-route-manager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_route_manager_linux-test-common.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_route_manager_linux-test-route-manager.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_systemd-test-systemd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_utils-test-utils.Po@am__quote@ .c.o: @@ -1052,6 +1079,20 @@ test_route_manager_linux-test-route-manager.obj: test-route-manager.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_route_manager_linux_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_route_manager_linux-test-route-manager.obj `if test -f 'test-route-manager.c'; then $(CYGPATH_W) 'test-route-manager.c'; else $(CYGPATH_W) '$(srcdir)/test-route-manager.c'; fi` +test_systemd-test-systemd.o: test-systemd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_systemd_CFLAGS) $(CFLAGS) -MT test_systemd-test-systemd.o -MD -MP -MF $(DEPDIR)/test_systemd-test-systemd.Tpo -c -o test_systemd-test-systemd.o `test -f 'test-systemd.c' || echo '$(srcdir)/'`test-systemd.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_systemd-test-systemd.Tpo $(DEPDIR)/test_systemd-test-systemd.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='test-systemd.c' object='test_systemd-test-systemd.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) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_systemd_CFLAGS) $(CFLAGS) -c -o test_systemd-test-systemd.o `test -f 'test-systemd.c' || echo '$(srcdir)/'`test-systemd.c + +test_systemd-test-systemd.obj: test-systemd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_systemd_CFLAGS) $(CFLAGS) -MT test_systemd-test-systemd.obj -MD -MP -MF $(DEPDIR)/test_systemd-test-systemd.Tpo -c -o test_systemd-test-systemd.obj `if test -f 'test-systemd.c'; then $(CYGPATH_W) 'test-systemd.c'; else $(CYGPATH_W) '$(srcdir)/test-systemd.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_systemd-test-systemd.Tpo $(DEPDIR)/test_systemd-test-systemd.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='test-systemd.c' object='test_systemd-test-systemd.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) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_systemd_CFLAGS) $(CFLAGS) -c -o test_systemd-test-systemd.obj `if test -f 'test-systemd.c'; then $(CYGPATH_W) 'test-systemd.c'; else $(CYGPATH_W) '$(srcdir)/test-systemd.c'; fi` + test_utils-test-utils.o: test-utils.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_utils_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_utils-test-utils.o -MD -MP -MF $(DEPDIR)/test_utils-test-utils.Tpo -c -o test_utils-test-utils.o `test -f 'test-utils.c' || echo '$(srcdir)/'`test-utils.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_utils-test-utils.Tpo $(DEPDIR)/test_utils-test-utils.Po @@ -1368,6 +1409,13 @@ test-general-with-expect.log: test-general-with-expect$(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-systemd.log: test-systemd$(EXEEXT) + @p='test-systemd$(EXEEXT)'; \ + b='test-systemd'; \ + $(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-wired-defname.log: test-wired-defname$(EXEEXT) @p='test-wired-defname$(EXEEXT)'; \ b='test-wired-defname'; \ diff --git a/src/tests/config/nm-test-device.c b/src/tests/config/nm-test-device.c index 681f4966..04ccaec2 100644 --- a/src/tests/config/nm-test-device.c +++ b/src/tests/config/nm-test-device.c @@ -18,7 +18,7 @@ * Copyright 2013 Red Hat, Inc. */ -#include "config.h" +#include "nm-default.h" #include <string.h> diff --git a/src/tests/config/test-config.c b/src/tests/config/test-config.c index e8de86c8..19306df7 100644 --- a/src/tests/config/test-config.c +++ b/src/tests/config/test-config.c @@ -18,13 +18,11 @@ * */ -#include "config.h" +#include "nm-default.h" #include <unistd.h> - #include "nm-config.h" -#include "nm-default.h" #include "nm-test-device.h" #include "nm-fake-platform.h" #include "nm-bus-manager.h" diff --git a/src/tests/test-dcb.c b/src/tests/test-dcb.c index 35f1ed0f..e8e1ec86 100644 --- a/src/tests/test-dcb.c +++ b/src/tests/test-dcb.c @@ -18,11 +18,10 @@ * */ -#include "config.h" +#include "nm-default.h" #include <string.h> -#include "nm-default.h" #include "nm-dcb.h" #include "nm-test-utils.h" diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index c6abdccf..43595c8d 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -18,7 +18,7 @@ * */ -#include "config.h" +#include "nm-default.h" #include <string.h> #include <errno.h> @@ -27,7 +27,6 @@ #include <sys/types.h> #include <sys/wait.h> -#include "nm-default.h" #include "NetworkManagerUtils.h" #include "nm-multi-index.h" @@ -225,33 +224,33 @@ test_nm_utils_kill_child (void) int err; GLogLevelFlags fatal_mask; char *argv_watchdog[] = { - "sh", + "bash", "-c", "sleep 4; " "kill -KILL 0; #watchdog for #" TEST_TOKEN, NULL, }; char *argv1[] = { - "sh", + "bash", "-c", "trap \"sleep 0.3; exit 10\" EXIT; " "sleep 100000; exit $? #" TEST_TOKEN, NULL, }; char *argv2[] = { - "sh", + "bash", "-c", "exit 47; #" TEST_TOKEN, NULL, }; char *argv3[] = { - "sh", + "bash", "-c", "trap \"exit 47\" TERM; while true; do :; done; #" TEST_TOKEN, NULL, }; char *argv4[] = { - "sh", + "bash", "-c", "trap \"while true; do :; done\" TERM; while true; do :; done; #" TEST_TOKEN, NULL, @@ -855,6 +854,49 @@ test_nm_multi_index (void) /*******************************************/ +static void +test_nm_utils_new_vlan_name (void) +{ + guint i, j; + const char *parent_names[] = { + "a", + "a2", + "a23", + "a23456789", + "a2345678901", + "a23456789012", + "a234567890123", + "a2345678901234", + "a23456789012345", + "a234567890123456", + "a2345678901234567", + }; + + for (i = 0; i < G_N_ELEMENTS (parent_names); i++) { + for (j = 0; j < 10; j++) { + gs_free char *ifname = NULL; + gs_free char *vlan_id_s = NULL; + guint vlan_id; + + /* Create a random VLAN id between 0 and 4094 */ + vlan_id = nmtst_get_rand_int () % 4095; + + vlan_id_s = g_strdup_printf (".%d", vlan_id); + + ifname = nm_utils_new_vlan_name (parent_names[i], vlan_id); + g_assert (ifname && ifname[0]); + g_assert_cmpint (strlen (ifname), ==, MIN (15, strlen (parent_names[i]) + strlen (vlan_id_s))); + g_assert (g_str_has_suffix (ifname, vlan_id_s)); + g_assert (ifname[strlen (ifname) - strlen (vlan_id_s)] == '.'); + g_assert (strncmp (ifname, parent_names[i], strlen (ifname) - strlen (vlan_id_s)) == 0); + if (!g_str_has_prefix (ifname, parent_names[i])) + g_assert_cmpint (strlen (ifname), ==, 15); + } + } +} + +/*******************************************/ + NMTST_DEFINE (); int @@ -867,6 +909,7 @@ main (int argc, char **argv) g_test_add_func ("/general/nm_utils_array_remove_at_indexes", test_nm_utils_array_remove_at_indexes); g_test_add_func ("/general/nm_ethernet_address_is_valid", test_nm_ethernet_address_is_valid); g_test_add_func ("/general/nm_multi_index", test_nm_multi_index); + g_test_add_func ("/general/nm_utils_new_vlan_name", test_nm_utils_new_vlan_name); return g_test_run (); } diff --git a/src/tests/test-general.c b/src/tests/test-general.c index da68c9a9..b8a51f2a 100644 --- a/src/tests/test-general.c +++ b/src/tests/test-general.c @@ -18,12 +18,11 @@ * */ -#include "config.h" +#include "nm-default.h" #include <string.h> #include <errno.h> -#include "nm-default.h" #include "NetworkManagerUtils.h" #include "nm-core-internal.h" @@ -205,7 +204,7 @@ test_connection_match_basic (void) copy = nm_simple_connection_new_clone (orig); connections = g_slist_append (connections, copy); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == copy); /* Now change a material property like IPv4 method and ensure matching fails */ @@ -214,7 +213,7 @@ test_connection_match_basic (void) g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == NULL); g_slist_free (connections); @@ -250,7 +249,7 @@ test_connection_match_ip6_method (void) NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == copy); g_slist_free (connections); @@ -284,7 +283,7 @@ test_connection_match_ip6_method_ignore (void) NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == copy); g_slist_free (connections); @@ -318,7 +317,7 @@ test_connection_match_ip6_method_ignore_auto (void) NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == copy); g_slist_free (connections); @@ -326,7 +325,6 @@ test_connection_match_ip6_method_ignore_auto (void) g_object_unref (copy); } - static void test_connection_match_ip4_method (void) { @@ -355,11 +353,11 @@ test_connection_match_ip4_method (void) NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); - matched = nm_utils_match_connection (connections, orig, FALSE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, FALSE, 0, 0, NULL, NULL); g_assert (matched == copy); /* Ensure when carrier=true matching fails */ - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == NULL); g_slist_free (connections); @@ -393,7 +391,7 @@ test_connection_match_interface_name (void) NM_SETTING_CONNECTION_INTERFACE_NAME, NULL, NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == copy); g_slist_free (connections); @@ -430,7 +428,7 @@ test_connection_match_wired (void) NM_SETTING_WIRED_S390_NETTYPE, "qeth", NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == copy); g_slist_free (connections); @@ -462,7 +460,7 @@ test_connection_match_wired2 (void) * the connections match. It can happen if assuming VLAN devices. */ nm_connection_remove_setting (orig, NM_TYPE_SETTING_WIRED); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == copy); g_slist_free (connections); @@ -487,7 +485,7 @@ test_connection_match_cloned_mac (void) NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23", NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == fuzzy); exact = nm_simple_connection_new_clone (orig); @@ -498,14 +496,14 @@ test_connection_match_cloned_mac (void) NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23", NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == exact); g_object_set (G_OBJECT (s_wired), NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:24", NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched == fuzzy); g_slist_free (connections); @@ -565,7 +563,7 @@ test_connection_no_match_ip4_addr (void) nm_setting_ip_config_add_address (s_ip4, nm_addr); nm_ip_address_unref (nm_addr); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched != copy); g_slist_free (connections); @@ -611,7 +609,7 @@ test_connection_no_match_vlan (void) NM_SETTING_VLAN_FLAGS, 0, NULL); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched != copy); /* Check that the connections do not match if VLAN priorities differ */ @@ -621,7 +619,7 @@ test_connection_no_match_vlan (void) g_object_set (G_OBJECT (s_vlan_copy), NM_SETTING_VLAN_FLAGS, 0, NULL); nm_setting_vlan_add_priority_str (s_vlan_copy, NM_VLAN_INGRESS_MAP, "4:2"); - matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL); + matched = nm_utils_match_connection (connections, orig, TRUE, 0, 0, NULL, NULL); g_assert (matched != copy); g_slist_free (connections); @@ -629,6 +627,118 @@ test_connection_no_match_vlan (void) g_object_unref (copy); } +static void +test_connection_match_ip4_routes1 (void) +{ + gs_unref_object NMConnection *orig = NULL, *copy = NULL; + NMConnection *matched; + gs_free_slist GSList *connections = NULL; + NMSettingIPConfig *s_ip4; + + orig = _match_connection_new (); + + s_ip4 = nm_connection_get_setting_ip4_config (orig); + g_assert (s_ip4); + g_object_set (G_OBJECT (s_ip4), + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NULL); + + nmtst_setting_ip_config_add_address (s_ip4, "10.0.0.1", 8); + + /* Clone connection */ + copy = nm_simple_connection_new_clone (orig); + connections = g_slist_append (connections, copy); + + /* Set routes on original connection */ + nmtst_setting_ip_config_add_route (s_ip4, "172.25.16.0", 24, "10.0.0.2", -1); + nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20); + + /* Set single route on cloned connection */ + s_ip4 = nm_connection_get_setting_ip4_config (copy); + g_assert (s_ip4); + nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20); + + /* Try to match the connections */ + matched = nm_utils_match_connection (connections, orig, FALSE, 100, 0, NULL, NULL); + g_assert (matched == NULL); +} + +static void +test_connection_match_ip4_routes2 (void) +{ + gs_unref_object NMConnection *orig = NULL, *copy = NULL; + NMConnection *matched; + gs_free_slist GSList *connections = NULL; + NMSettingIPConfig *s_ip4; + + orig = _match_connection_new (); + + s_ip4 = nm_connection_get_setting_ip4_config (orig); + g_assert (s_ip4); + g_object_set (G_OBJECT (s_ip4), + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NULL); + + nmtst_setting_ip_config_add_address (s_ip4, "10.0.0.1", 8); + + /* Clone connection */ + copy = nm_simple_connection_new_clone (orig); + connections = g_slist_append (connections, copy); + + /* Set routes on original connection */ + nmtst_setting_ip_config_add_route (s_ip4, "172.25.16.0", 24, "10.0.0.2", -1); + nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20); + + /* Set routes on cloned connection, changing order and using explicit metrics */ + s_ip4 = nm_connection_get_setting_ip4_config (copy); + g_assert (s_ip4); + nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20); + nmtst_setting_ip_config_add_route (s_ip4, "172.25.16.0", 24, "10.0.0.2", 100); + + /* Try to match the connections using different default metrics */ + matched = nm_utils_match_connection (connections, orig, FALSE, 100, 0, NULL, NULL); + g_assert (matched == copy); + matched = nm_utils_match_connection (connections, orig, FALSE, 500, 0, NULL, NULL); + g_assert (matched == NULL); +} + +static void +test_connection_match_ip6_routes (void) +{ + gs_unref_object NMConnection *orig = NULL, *copy = NULL; + NMConnection *matched; + gs_free_slist GSList *connections = NULL; + NMSettingIPConfig *s_ip6; + + orig = _match_connection_new (); + + s_ip6 = nm_connection_get_setting_ip6_config (orig); + g_assert (s_ip6); + g_object_set (G_OBJECT (s_ip6), + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NULL); + + nmtst_setting_ip_config_add_address (s_ip6, "fd01::15", 64); + + /* Clone connection */ + copy = nm_simple_connection_new_clone (orig); + connections = g_slist_append (connections, copy); + + /* Set routes on original connection */ + nmtst_setting_ip_config_add_route (s_ip6, "2001:db8:a:b:0:0:0:0", 64, "fd01::16", -1); + + /* Set routes on cloned connection */ + s_ip6 = nm_connection_get_setting_ip6_config (copy); + g_assert (s_ip6); + nmtst_setting_ip_config_add_route (s_ip6, "2001:db8:a:b:0:0:0:0", 64, "fd01::16", 50); + + /* Try to match the connections */ + matched = nm_utils_match_connection (connections, orig, FALSE, 0, 100, NULL, NULL); + g_assert (matched == NULL); + matched = nm_utils_match_connection (connections, orig, FALSE, 0, 50, NULL, NULL); + g_assert (matched == copy); +} + static NMConnection * _create_connection_autoconnect (const char *id, gboolean autoconnect, int autoconnect_priority) { @@ -1010,8 +1120,8 @@ test_nm_utils_strbuf_append (void) #define STR_ORIG "abcdefghijklmnopqrstuvwxyz" int buf_len; int rep; - char buf[STRLEN (BUF_ORIG) + 1]; - char str[STRLEN (BUF_ORIG) + 1]; + char buf[NM_STRLEN (BUF_ORIG) + 1]; + char str[NM_STRLEN (BUF_ORIG) + 1]; for (buf_len = 0; buf_len < 10; buf_len++) { for (rep = 0; rep < 50; rep++) { @@ -1136,6 +1246,9 @@ main (int argc, char **argv) g_test_add_func ("/general/connection-match/cloned_mac", test_connection_match_cloned_mac); g_test_add_func ("/general/connection-match/no-match-ip4-addr", test_connection_no_match_ip4_addr); g_test_add_func ("/general/connection-match/no-match-vlan", test_connection_no_match_vlan); + g_test_add_func ("/general/connection-match/routes/ip4/1", test_connection_match_ip4_routes1); + g_test_add_func ("/general/connection-match/routes/ip4/2", test_connection_match_ip4_routes2); + g_test_add_func ("/general/connection-match/routes/ip6", test_connection_match_ip6_routes); g_test_add_func ("/general/connection-sort/autoconnect-priority", test_connection_sort_autoconnect_priority); diff --git a/src/tests/test-ip4-config.c b/src/tests/test-ip4-config.c index 16cd3d1e..2b743c8c 100644 --- a/src/tests/test-ip4-config.c +++ b/src/tests/test-ip4-config.c @@ -18,12 +18,11 @@ * */ -#include "config.h" +#include "nm-default.h" #include <string.h> #include <arpa/inet.h> -#include "nm-default.h" #include "nm-ip4-config.h" #include "nm-platform.h" diff --git a/src/tests/test-ip6-config.c b/src/tests/test-ip6-config.c index 2639a1f0..5a2bb589 100644 --- a/src/tests/test-ip6-config.c +++ b/src/tests/test-ip6-config.c @@ -18,12 +18,11 @@ * */ -#include "config.h" +#include "nm-default.h" #include <string.h> #include <arpa/inet.h> -#include "nm-default.h" #include "nm-ip6-config.h" #include "nm-platform.h" diff --git a/src/tests/test-resolvconf-capture.c b/src/tests/test-resolvconf-capture.c index db7006ba..31b6e177 100644 --- a/src/tests/test-resolvconf-capture.c +++ b/src/tests/test-resolvconf-capture.c @@ -18,12 +18,11 @@ * */ -#include "config.h" +#include "nm-default.h" #include <string.h> #include <arpa/inet.h> -#include "nm-default.h" #include "NetworkManagerUtils.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c index 347c122c..742f4ee5 100644 --- a/src/tests/test-route-manager.c +++ b/src/tests/test-route-manager.c @@ -18,12 +18,11 @@ * */ -#include "config.h" +#include "nm-default.h" #include <arpa/inet.h> #include <linux/rtnetlink.h> -#include "nm-default.h" #include "test-common.h" #include "nm-platform.h" diff --git a/src/tests/test-systemd.c b/src/tests/test-systemd.c new file mode 100644 index 00000000..84ad95ba --- /dev/null +++ b/src/tests/test-systemd.c @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * 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) 2016 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "sd-dhcp-client.h" + +#include "nm-test-utils.h" + +/*****************************************************************************/ + +static void +test_dhcp_create (void) +{ + sd_dhcp_client *client4 = NULL; + int r; + + r = sd_dhcp_client_new (&client4); + g_assert (r == 0); + g_assert (client4); + + sd_dhcp_client_unref (client4); +} + +/*****************************************************************************/ + +NMTST_DEFINE (); + +int +main (int argc, char **argv) +{ + nmtst_init_assert_logging (&argc, &argv, "INFO", "ALL"); + + g_test_add_func ("/systemd/dhcp/create", test_dhcp_create); + + return g_test_run (); +} diff --git a/src/tests/test-utils.c b/src/tests/test-utils.c index 79a7e680..c8c82aef 100644 --- a/src/tests/test-utils.c +++ b/src/tests/test-utils.c @@ -18,13 +18,13 @@ * */ -#include "config.h" +#include "nm-default.h" #include <string.h> #include <errno.h> #include <arpa/inet.h> -#include "NetworkManagerUtils.c" +#include "nm-core-utils.c" #include "nm-test-utils.h" diff --git a/src/tests/test-wired-defname.c b/src/tests/test-wired-defname.c index 989345d8..6edd5ff2 100644 --- a/src/tests/test-wired-defname.c +++ b/src/tests/test-wired-defname.c @@ -18,12 +18,10 @@ * */ -#include "config.h" - - -#include <nm-simple-connection.h> -#include <nm-setting-connection.h> #include "nm-default.h" + +#include "nm-simple-connection.h" +#include "nm-setting-connection.h" #include "nm-device-ethernet-utils.h" #include "nm-test-utils.h" |