summary refs log tree commit diff
path: root/libnm-core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-core/tests')
-rw-r--r--libnm-core/tests/Makefile.am2
-rw-r--r--libnm-core/tests/Makefile.in25
-rw-r--r--libnm-core/tests/test-setting-bond.c198
3 files changed, 221 insertions, 4 deletions
diff --git a/libnm-core/tests/Makefile.am b/libnm-core/tests/Makefile.am
index 92c816fd..1926c86f 100644
--- a/libnm-core/tests/Makefile.am
+++ b/libnm-core/tests/Makefile.am
@@ -17,7 +17,6 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/libnm-core \
 	-I$(top_builddir)/libnm-core \
 	-DNETWORKMANAGER_COMPILATION \
-	-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
 	$(GLIB_CFLAGS) \
 	-DTEST_CERT_DIR=\"$(certsdir)\"
 
@@ -28,6 +27,7 @@ noinst_PROGRAMS =		\
 	test-keyfile		\
 	test-secrets		\
 	test-setting-8021x	\
+	test-setting-bond	\
 	test-setting-dcb	\
 	test-settings-defaults
 
diff --git a/libnm-core/tests/Makefile.in b/libnm-core/tests/Makefile.in
index 43892d75..356ce8df 100644
--- a/libnm-core/tests/Makefile.in
+++ b/libnm-core/tests/Makefile.in
@@ -92,6 +92,7 @@ host_triplet = @host@
 @ENABLE_TESTS_TRUE@	test-crypto$(EXEEXT) test-general$(EXEEXT) \
 @ENABLE_TESTS_TRUE@	test-keyfile$(EXEEXT) test-secrets$(EXEEXT) \
 @ENABLE_TESTS_TRUE@	test-setting-8021x$(EXEEXT) \
+@ENABLE_TESTS_TRUE@	test-setting-bond$(EXEEXT) \
 @ENABLE_TESTS_TRUE@	test-setting-dcb$(EXEEXT) \
 @ENABLE_TESTS_TRUE@	test-settings-defaults$(EXEEXT)
 subdir = libnm-core/tests
@@ -161,6 +162,12 @@ test_setting_8021x_LDADD = $(LDADD)
 @ENABLE_TESTS_TRUE@test_setting_8021x_DEPENDENCIES =  \
 @ENABLE_TESTS_TRUE@	$(top_builddir)/libnm-core/libnm-core.la \
 @ENABLE_TESTS_TRUE@	$(am__DEPENDENCIES_1)
+test_setting_bond_SOURCES = test-setting-bond.c
+test_setting_bond_OBJECTS = test-setting-bond.$(OBJEXT)
+test_setting_bond_LDADD = $(LDADD)
+@ENABLE_TESTS_TRUE@test_setting_bond_DEPENDENCIES =  \
+@ENABLE_TESTS_TRUE@	$(top_builddir)/libnm-core/libnm-core.la \
+@ENABLE_TESTS_TRUE@	$(am__DEPENDENCIES_1)
 test_setting_dcb_SOURCES = test-setting-dcb.c
 test_setting_dcb_OBJECTS = test-setting-dcb.$(OBJEXT)
 test_setting_dcb_LDADD = $(LDADD)
@@ -209,10 +216,11 @@ am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
 SOURCES = test-compare.c test-crypto.c $(test_general_SOURCES) \
 	test-keyfile.c test-secrets.c test-setting-8021x.c \
-	test-setting-dcb.c test-settings-defaults.c
+	test-setting-bond.c test-setting-dcb.c \
+	test-settings-defaults.c
 DIST_SOURCES = test-compare.c test-crypto.c \
 	$(am__test_general_SOURCES_DIST) test-keyfile.c test-secrets.c \
-	test-setting-8021x.c test-setting-dcb.c \
+	test-setting-8021x.c test-setting-bond.c test-setting-dcb.c \
 	test-settings-defaults.c
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
@@ -720,7 +728,6 @@ BUILT_SOURCES = $(GLIB_GENERATED)
 @ENABLE_TESTS_TRUE@	-I$(top_srcdir)/libnm-core \
 @ENABLE_TESTS_TRUE@	-I$(top_builddir)/libnm-core \
 @ENABLE_TESTS_TRUE@	-DNETWORKMANAGER_COMPILATION \
-@ENABLE_TESTS_TRUE@	-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
 @ENABLE_TESTS_TRUE@	$(GLIB_CFLAGS) \
 @ENABLE_TESTS_TRUE@	-DTEST_CERT_DIR=\"$(certsdir)\"
 
@@ -831,6 +838,10 @@ test-setting-8021x$(EXEEXT): $(test_setting_8021x_OBJECTS) $(test_setting_8021x_
 	@rm -f test-setting-8021x$(EXEEXT)
 	$(AM_V_CCLD)$(LINK) $(test_setting_8021x_OBJECTS) $(test_setting_8021x_LDADD) $(LIBS)
 
+test-setting-bond$(EXEEXT): $(test_setting_bond_OBJECTS) $(test_setting_bond_DEPENDENCIES) $(EXTRA_test_setting_bond_DEPENDENCIES) 
+	@rm -f test-setting-bond$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(test_setting_bond_OBJECTS) $(test_setting_bond_LDADD) $(LIBS)
+
 test-setting-dcb$(EXEEXT): $(test_setting_dcb_OBJECTS) $(test_setting_dcb_DEPENDENCIES) $(EXTRA_test_setting_dcb_DEPENDENCIES) 
 	@rm -f test-setting-dcb$(EXEEXT)
 	$(AM_V_CCLD)$(LINK) $(test_setting_dcb_OBJECTS) $(test_setting_dcb_LDADD) $(LIBS)
@@ -852,6 +863,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-keyfile.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-secrets.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-setting-8021x.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-setting-bond.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-setting-dcb.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-settings-defaults.Po@am__quote@
 
@@ -1117,6 +1129,13 @@ test-setting-8021x.log: test-setting-8021x$(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-setting-bond.log: test-setting-bond$(EXEEXT)
+	@p='test-setting-bond$(EXEEXT)'; \
+	b='test-setting-bond'; \
+	$(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-setting-dcb.log: test-setting-dcb$(EXEEXT)
 	@p='test-setting-dcb$(EXEEXT)'; \
 	b='test-setting-dcb'; \
diff --git a/libnm-core/tests/test-setting-bond.c b/libnm-core/tests/test-setting-bond.c
new file mode 100644
index 00000000..a6afa1c8
--- /dev/null
+++ b/libnm-core/tests/test-setting-bond.c
@@ -0,0 +1,198 @@
+/* -*- 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 2016 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include "nm-utils.h"
+#include "nm-setting-bond.h"
+#include "nm-connection.h"
+#include "nm-simple-connection.h"
+#include "nm-setting-connection.h"
+#include "nm-errors.h"
+
+#include "nm-test-utils.h"
+
+static void
+create_bond_connection (NMConnection **con, NMSettingBond **s_bond)
+{
+	NMSettingConnection *s_con;
+
+	g_assert (con);
+	g_assert (s_bond);
+
+	*con = nmtst_create_minimal_connection ("bond",
+	                                        NULL,
+	                                        NM_SETTING_BOND_SETTING_NAME,
+	                                        &s_con);
+	g_assert (*con);
+	g_assert (s_con);
+
+	g_object_set (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, "bond0", NULL);
+
+	*s_bond = (NMSettingBond *) nm_setting_bond_new ();
+	g_assert (*s_bond);
+
+	nm_connection_add_setting (*con, NM_SETTING (*s_bond));
+}
+
+#define test_verify_options(exp, ...) \
+	G_STMT_START { \
+		const char *__opts[] = { __VA_ARGS__ , NULL }; \
+		\
+		_test_verify_options (__opts, exp); \
+	} G_STMT_END
+
+static void
+_test_verify_options (const char **options, gboolean expected_result)
+{
+	gs_unref_object NMConnection *con = NULL;
+	NMSettingBond *s_bond;
+	GError *error = NULL;
+	gboolean success;
+	const char **option;
+
+	create_bond_connection (&con, &s_bond);
+
+	for (option = options; option[0] && option[1]; option += 2)
+		g_assert (nm_setting_bond_add_option (s_bond, option[0], option[1]));
+
+	if (expected_result) {
+		nmtst_assert_connection_verifies_and_normalizable (con);
+		nmtst_connection_normalize (con);
+		success = nm_setting_verify ((NMSetting *) s_bond, con, &error);
+		nmtst_assert_success (success, error);
+	} else {
+		nmtst_assert_connection_unnormalizable (con,
+		                                        NM_CONNECTION_ERROR,
+		                                        NM_CONNECTION_ERROR_INVALID_PROPERTY);
+	}
+}
+
+static void
+test_verify (void)
+{
+	test_verify_options (TRUE,
+	                     "mode", "3",
+	                     "arp_interval", "0");
+	test_verify_options (FALSE,
+	                     /* arp_interval not supported in balance-alb mode */
+	                     "mode", "balance-alb",
+	                     "arp_interval", "1",
+	                     "arp_ip_target", "1.2.3.4");
+	test_verify_options (FALSE,
+	                     /* arp_ip_target requires arp_interval */
+	                     "mode", "balance-rr",
+	                     "arp_ip_target", "1.2.3.4");
+	test_verify_options (TRUE,
+	                     "mode", "balance-rr",
+	                     "arp_interval", "1",
+	                     "arp_ip_target", "1.2.3.4");
+	test_verify_options (FALSE,
+	                     /* num_grat_arp, num_unsol_na cannot be different */
+	                     "mode", "balance-rr",
+	                     "num_grat_arp", "3",
+	                     "num_unsol_na", "4");
+	test_verify_options (TRUE,
+	                     "mode", "balance-rr",
+	                     "num_grat_arp", "5",
+	                     "num_unsol_na", "5");
+	test_verify_options (TRUE,
+	                     "mode", "active-backup",
+	                     "primary", "eth0");
+	test_verify_options (FALSE,
+	                     /* primary requires mode=active-backup */
+	                     "mode", "802.3ad",
+	                     "primary", "eth0");
+	test_verify_options (TRUE,
+	                     "mode", "802.3ad",
+	                     "lacp_rate", "fast");
+	test_verify_options (FALSE,
+	                     /* lacp_rate=fast requires mode=802.3ad */
+	                     "mode", "balance-rr",
+	                     "lacp_rate", "fast");
+	test_verify_options (TRUE,
+	                     "mode", "802.3ad",
+	                     "ad_actor_system", "ae:00:11:33:44:55");
+}
+
+static void
+test_compare_options (gboolean exp_res, const char **opts1, const char **opts2)
+{
+	gs_unref_object NMSettingBond *s_bond1 = NULL, *s_bond2 = NULL;
+	const char **p;
+
+	s_bond1 = (NMSettingBond *) nm_setting_bond_new ();
+	g_assert (s_bond1);
+	s_bond2 = (NMSettingBond *) nm_setting_bond_new ();
+	g_assert (s_bond2);
+
+	for (p = opts1; p[0] && p[1]; p += 2)
+		g_assert (nm_setting_bond_add_option (s_bond1, p[0], p[1]));
+
+	for (p = opts2; p[0] && p[1]; p += 2)
+		g_assert (nm_setting_bond_add_option (s_bond2, p[0], p[1]));
+
+	g_assert_cmpint (nm_setting_compare ((NMSetting *) s_bond1,
+	                                     (NMSetting *) s_bond2,
+	                                     NM_SETTING_COMPARE_FLAG_EXACT),
+	                 ==,
+	                 exp_res);
+}
+
+static void
+test_compare (void)
+{
+	test_compare_options (TRUE,
+	                      ((const char *[]){ "mode", "balance-rr", "miimon", "1", NULL }),
+	                      ((const char *[]){ "mode", "balance-rr", "miimon", "1", NULL }));
+	test_compare_options (FALSE,
+	                      ((const char *[]){ "mode", "balance-rr", "miimon", "1", NULL }),
+	                      ((const char *[]){ "mode", "balance-rr", "miimon", "2", NULL }));
+
+	/* ignore default values */
+	test_compare_options (TRUE,
+	                      ((const char *[]){ "miimon", "1", NULL }),
+	                      ((const char *[]){ "miimon", "1", "updelay", "0", NULL }));
+
+	/* special handling of num_grat_arp, num_unsol_na */
+	test_compare_options (FALSE,
+	                      ((const char *[]){ "num_grat_arp", "2", NULL }),
+	                      ((const char *[]){ "num_grat_arp", "1", NULL }));
+	test_compare_options (TRUE,
+	                      ((const char *[]){ "num_grat_arp", "3", NULL }),
+	                      ((const char *[]){ "num_unsol_na", "3", NULL }));
+	test_compare_options (TRUE,
+	                      ((const char *[]){ "num_grat_arp", "4", NULL }),
+	                      ((const char *[]){ "num_unsol_na", "4", "num_grat_arp", "4", NULL }));
+}
+
+#define TPATH "/libnm/settings/bond/"
+
+NMTST_DEFINE ();
+
+int
+main (int argc, char **argv)
+{
+	nmtst_init (&argc, &argv, TRUE);
+
+	g_test_add_func (TPATH "verify", test_verify);
+	g_test_add_func (TPATH "compare", test_compare);
+
+	return g_test_run ();
+}