summary refs log tree commit diff
path: root/src/tests
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2015-11-24 00:06:32 +0100
committerMichael Biebl <biebl@debian.org>2015-11-24 00:06:32 +0100
commita6ece1a2aa19a6268335c87d4fdef20123dd04a5 (patch)
tree87f1961faacdfafb1c4fee5f2feb6bcb5c06813b /src/tests
parent81836c2d44802b4cca833d7775dd627e0797a7e2 (diff)
Imported Upstream version 1.0.8 upstream/1.0.8
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile.am1
-rw-r--r--src/tests/Makefile.in2
-rw-r--r--src/tests/config/Makefile.am1
-rw-r--r--src/tests/config/Makefile.in2
-rw-r--r--src/tests/config/test-config.c87
-rw-r--r--src/tests/test-general-with-expect.c25
-rw-r--r--src/tests/test-general.c78
7 files changed, 185 insertions, 11 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 83632bd1..eebdb248 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -2,6 +2,7 @@ SUBDIRS = config
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
 	-I$(top_srcdir)/libnm-core \
 	-I$(top_builddir)/libnm-core \
 	-I$(top_srcdir)/src/platform \
diff --git a/src/tests/Makefile.in b/src/tests/Makefile.in
index f84c5536..a4527284 100644
--- a/src/tests/Makefile.in
+++ b/src/tests/Makefile.in
@@ -609,6 +609,7 @@ LOG_DRIVER = @LOG_DRIVER@
 LTLIBICONV = @LTLIBICONV@
 LTLIBINTL = @LTLIBINTL@
 LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
 MANIFEST_TOOL = @MANIFEST_TOOL@
@@ -752,6 +753,7 @@ with_valgrind = @with_valgrind@
 SUBDIRS = config
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
 	-I$(top_srcdir)/libnm-core \
 	-I$(top_builddir)/libnm-core \
 	-I$(top_srcdir)/src/platform \
diff --git a/src/tests/config/Makefile.am b/src/tests/config/Makefile.am
index 42c6b9a1..a5e068e4 100644
--- a/src/tests/config/Makefile.am
+++ b/src/tests/config/Makefile.am
@@ -1,5 +1,6 @@
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
 	-I$(top_srcdir)/libnm-core \
 	-I$(top_builddir)/libnm-core \
 	-I$(top_srcdir)/src/ \
diff --git a/src/tests/config/Makefile.in b/src/tests/config/Makefile.in
index 6d1dd4bc..20bbe60a 100644
--- a/src/tests/config/Makefile.in
+++ b/src/tests/config/Makefile.in
@@ -510,6 +510,7 @@ LOG_DRIVER = @LOG_DRIVER@
 LTLIBICONV = @LTLIBICONV@
 LTLIBINTL = @LTLIBINTL@
 LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
 MANIFEST_TOOL = @MANIFEST_TOOL@
@@ -652,6 +653,7 @@ with_resolvconf = @with_resolvconf@
 with_valgrind = @with_valgrind@
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
 	-I$(top_srcdir)/libnm-core \
 	-I$(top_builddir)/libnm-core \
 	-I$(top_srcdir)/src/ \
diff --git a/src/tests/config/test-config.c b/src/tests/config/test-config.c
index 8b8028e6..6dad8216 100644
--- a/src/tests/config/test-config.c
+++ b/src/tests/config/test-config.c
@@ -380,7 +380,7 @@ test_config_confdir (void)
 	g_assert_cmpstr (value, ==, "VAL5");
 	g_free (value);
 
-	nm_config_data_log (nm_config_get_data_orig (config), ">>> TEST: ");
+	nm_config_data_log (nm_config_get_data_orig (config), ">>> TEST: ", " ", NULL);
 
 	g_object_unref (config);
 }
@@ -396,6 +396,89 @@ test_config_confdir_parse_error (void)
 	g_clear_error (&error);
 }
 
+/*****************************************************************************/
+
+static void
+_test_signal_config_changed_cb (NMConfig *config,
+                                NMConfigData *config_data,
+                                NMConfigChangeFlags changes,
+                                NMConfigData *old_data,
+                                gpointer user_data)
+{
+	const NMConfigChangeFlags *expected = user_data;
+
+	g_assert (changes);
+	g_assert_cmpint (changes, ==, *expected);
+	g_assert (NM_IS_CONFIG (config));
+	g_assert (NM_IS_CONFIG_DATA (config_data));
+
+	g_assert (config_data == old_data);
+	g_assert (config_data == nm_config_get_data (config));
+}
+
+static void
+_test_signal_config_changed_cb2 (NMConfig *config,
+                                 NMConfigData *config_data,
+                                 NMConfigChangeFlags changes,
+                                 NMConfigData *old_data,
+                                 gpointer user_data)
+{
+	const NMConfigChangeFlags *expected = user_data;
+
+	g_assert (changes);
+	g_assert_cmpint (changes, ==, *expected);
+}
+
+static void
+test_config_signal (void)
+{
+	gs_unref_object NMConfig *config = NULL;
+	NMConfigChangeFlags expected;
+	gs_unref_object NMConfigData *config_data_orig = NULL;
+
+	config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "/no/such/dir", NULL);
+
+	config_data_orig = g_object_ref (nm_config_get_data_orig (config));
+
+	g_signal_connect (G_OBJECT (config),
+	                  NM_CONFIG_SIGNAL_CONFIG_CHANGED,
+	                  G_CALLBACK (_test_signal_config_changed_cb),
+	                  &expected);
+
+	expected = NM_CONFIG_CHANGE_SIGUSR1;
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*config: signal SIGUSR1");
+	nm_config_reload (config, SIGUSR1);
+
+	expected = NM_CONFIG_CHANGE_SIGUSR2;
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*config: signal SIGUSR2");
+	nm_config_reload (config, SIGUSR2);
+
+	expected = NM_CONFIG_CHANGE_SIGHUP;
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*config: signal SIGHUP (no changes from disk)*");
+	nm_config_reload (config, SIGHUP);
+
+
+	/* test with subscribing two signals...
+	 *
+	 * This test exposes glib bug https://bugzilla.redhat.com/show_bug.cgi?id=1260577
+	 * for which we however have a workaround in 'nm-config.c' */
+	g_signal_connect (G_OBJECT (config),
+	                  NM_CONFIG_SIGNAL_CONFIG_CHANGED,
+	                  G_CALLBACK (_test_signal_config_changed_cb2),
+	                  &expected);
+	expected = NM_CONFIG_CHANGE_SIGUSR2;
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*config: signal SIGUSR2");
+	nm_config_reload (config, SIGUSR2);
+	g_signal_handlers_disconnect_by_func (config, _test_signal_config_changed_cb2, &expected);
+
+
+	g_signal_handlers_disconnect_by_func (config, _test_signal_config_changed_cb, &expected);
+
+	g_assert (config_data_orig == nm_config_get_data (config));
+}
+
+/*****************************************************************************/
+
 NMTST_DEFINE ();
 
 int
@@ -419,6 +502,8 @@ main (int argc, char **argv)
 	g_test_add_func ("/config/confdir", test_config_confdir);
 	g_test_add_func ("/config/confdir-parse-error", test_config_confdir_parse_error);
 
+	g_test_add_func ("/config/signal", test_config_signal);
+
 	/* This one has to come last, because it leaves its values in
 	 * nm-config.c's global variables, and there's no way to reset
 	 * those to NULL.
diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c
index fe76e3fa..21fb0681 100644
--- a/src/tests/test-general-with-expect.c
+++ b/src/tests/test-general-with-expect.c
@@ -23,6 +23,7 @@
 #include <glib.h>
 #include <string.h>
 #include <errno.h>
+#include <time.h>
 #include <netinet/ether.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -33,6 +34,10 @@
 
 #include "nm-test-utils.h"
 
+#ifndef CLOCK_BOOTTIME
+#define CLOCK_BOOTTIME 7
+#endif
+
 /*******************************************/
 
 static void
@@ -284,9 +289,9 @@ test_nm_utils_kill_child (void)
 
 	fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
 
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-1-1' (*): waiting up to 500 milliseconds for process to terminate normally after sending SIGTERM (15)...");
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-1-1' (*): waiting up to 3000 milliseconds for process to terminate normally after sending SIGTERM (15)...");
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-1-1' (*): after sending SIGTERM (15), process * exited by signal 15 (* usec elapsed)");
-	test_nm_utils_kill_child_sync_do ("test-s-1-1", pid1s_1, SIGTERM, 1000 / 2, TRUE,  &expected_signal_TERM);
+	test_nm_utils_kill_child_sync_do ("test-s-1-1", pid1s_1, SIGTERM, 3000, TRUE,  &expected_signal_TERM);
 
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-1-2' (*): waiting for process to terminate after sending SIGKILL (9)...");
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-1-2' (*): after sending SIGKILL (9), process * exited by signal 9 (* usec elapsed)");
@@ -298,16 +303,16 @@ test_nm_utils_kill_child (void)
 	test_nm_utils_kill_child_sync_do ("test-s-1-3", pid1s_3, 0, 1, TRUE,  &expected_signal_KILL);
 
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-2' (*): process * already terminated normally with status 47");
-	test_nm_utils_kill_child_sync_do ("test-s-2", pid2s, SIGTERM, 1000 / 2, TRUE,  &expected_exit_47);
+	test_nm_utils_kill_child_sync_do ("test-s-2", pid2s, SIGTERM, 3000, TRUE,  &expected_exit_47);
 
 	/* send invalid signal. */
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*kill child process 'test-s-3-0' (*): failed to send Unexpected signal: Invalid argument (22)");
 	test_nm_utils_kill_child_sync_do ("test-s-3-0", pid3s, -1, 0, FALSE, NULL);
 
 	/* really kill pid3s */
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-3-1' (*): waiting up to 500 milliseconds for process to terminate normally after sending SIGTERM (15)...");
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-3-1' (*): waiting up to 3000 milliseconds for process to terminate normally after sending SIGTERM (15)...");
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-3-1' (*): after sending SIGTERM (15), process * exited normally with status 47 (* usec elapsed)");
-	test_nm_utils_kill_child_sync_do ("test-s-3-1", pid3s, SIGTERM, 1000 / 2, TRUE,  &expected_exit_47);
+	test_nm_utils_kill_child_sync_do ("test-s-3-1", pid3s, SIGTERM, 3000, TRUE,  &expected_exit_47);
 
 	/* pid3s should not be a valid process, hence the call should fail. Note, that there
 	 * is a race here. */
@@ -320,9 +325,9 @@ test_nm_utils_kill_child (void)
 	test_nm_utils_kill_child_sync_do ("test-s-4", pid4s, SIGTERM, 1, TRUE, &expected_signal_KILL);
 
 
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-1-1' (*): wait for process to terminate after sending SIGTERM (15) (send SIGKILL in 500 milliseconds)...");
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-1-1' (*): wait for process to terminate after sending SIGTERM (15) (send SIGKILL in 3000 milliseconds)...");
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-1-1' (*): terminated by signal 15 (* usec elapsed)");
-	test_nm_utils_kill_child_async_do ("test-a-1-1", pid1a_1, SIGTERM, 1000 / 2, TRUE, &expected_signal_TERM);
+	test_nm_utils_kill_child_async_do ("test-a-1-1", pid1a_1, SIGTERM, 3000, TRUE, &expected_signal_TERM);
 
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-1-2' (*): wait for process to terminate after sending SIGKILL (9)...");
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-1-2' (*): terminated by signal 9 (* usec elapsed)");
@@ -335,16 +340,16 @@ test_nm_utils_kill_child (void)
 
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-2' (*): process * already terminated normally with status 47");
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-2' (*): invoke callback: terminated normally with status 47");
-	test_nm_utils_kill_child_async_do ("test-a-2", pid2a, SIGTERM, 1000 / 2, TRUE, &expected_exit_47);
+	test_nm_utils_kill_child_async_do ("test-a-2", pid2a, SIGTERM, 3000, TRUE, &expected_exit_47);
 
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*kill child process 'test-a-3-0' (*): unexpected error sending Unexpected signal: Invalid argument (22)");
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-3-0' (*): invoke callback: killing child failed");
 	/* coverity[negative_returns] */
 	test_nm_utils_kill_child_async_do ("test-a-3-0", pid3a, -1, 1000 / 2, FALSE, NULL);
 
-	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-3-1' (*): wait for process to terminate after sending SIGTERM (15) (send SIGKILL in 500 milliseconds)...");
+	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-3-1' (*): wait for process to terminate after sending SIGTERM (15) (send SIGKILL in 3000 milliseconds)...");
 	g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-3-1' (*): terminated normally with status 47 (* usec elapsed)");
-	test_nm_utils_kill_child_async_do ("test-a-3-1", pid3a, SIGTERM, 1000 / 2, TRUE, &expected_exit_47);
+	test_nm_utils_kill_child_async_do ("test-a-3-1", pid3a, SIGTERM, 3000, TRUE, &expected_exit_47);
 
 	/* pid3a should not be a valid process, hence the call should fail. Note, that there
 	 * is a race here. */
diff --git a/src/tests/test-general.c b/src/tests/test-general.c
index de65d50f..094a4a65 100644
--- a/src/tests/test-general.c
+++ b/src/tests/test-general.c
@@ -440,6 +440,82 @@ test_connection_match_wired (void)
 }
 
 static void
+test_connection_match_wired2 (void)
+{
+	NMConnection *orig, *copy, *matched;
+	GSList *connections = NULL;
+	NMSettingWired *s_wired;
+	const char *mac = "52:54:00:ab:db:23";
+
+	orig = _match_connection_new ();
+	s_wired = nm_connection_get_setting_wired (orig);
+	g_assert (s_wired);
+	g_object_set (G_OBJECT (s_wired),
+	              NM_SETTING_WIRED_PORT, "tp",           /* port is not compared */
+	              NM_SETTING_WIRED_MAC_ADDRESS, mac,     /* we allow MAC address just in one connection */
+	              NULL);
+
+	copy = nm_simple_connection_new_clone (orig);
+	connections = g_slist_append (connections, copy);
+
+	/* Check that if the generated connection do not have wired setting
+	 * and s390 properties in the existing connection's setting are default,
+	 * 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);
+	g_assert (matched == copy);
+
+	g_slist_free (connections);
+	g_object_unref (orig);
+	g_object_unref (copy);
+}
+
+static void
+test_connection_match_cloned_mac (void)
+{
+	NMConnection *orig, *exact, *fuzzy, *matched;
+	GSList *connections = NULL;
+	NMSettingWired *s_wired;
+
+	orig = _match_connection_new ();
+
+	fuzzy = nm_simple_connection_new_clone (orig);
+	connections = g_slist_append (connections, fuzzy);
+	s_wired = nm_connection_get_setting_wired (orig);
+	g_assert (s_wired);
+	g_object_set (G_OBJECT (s_wired),
+	              NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
+	              NULL);
+
+	matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
+	g_assert (matched == fuzzy);
+
+	exact = nm_simple_connection_new_clone (orig);
+	connections = g_slist_append (connections, exact);
+	s_wired = nm_connection_get_setting_wired (exact);
+	g_assert (s_wired);
+	g_object_set (G_OBJECT (s_wired),
+	              NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
+	              NULL);
+
+	matched = nm_utils_match_connection (connections, orig, TRUE, 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);
+	g_assert (matched == fuzzy);
+
+	g_slist_free (connections);
+	g_object_unref (orig);
+	g_object_unref (fuzzy);
+	g_object_unref (exact);
+}
+
+static void
 test_connection_no_match_ip4_addr (void)
 {
 	NMConnection *orig, *copy, *matched;
@@ -747,6 +823,8 @@ main (int argc, char **argv)
 	g_test_add_func ("/general/connection-match/ip4-method", test_connection_match_ip4_method);
 	g_test_add_func ("/general/connection-match/con-interface-name", test_connection_match_interface_name);
 	g_test_add_func ("/general/connection-match/wired", test_connection_match_wired);
+	g_test_add_func ("/general/connection-match/wired2", test_connection_match_wired2);
+	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-sort/autoconnect-priority", test_connection_sort_autoconnect_priority);