about summary refs log tree commit diff
path: root/src/initrd/tests/test-cmdline-reader.c
diff options
context:
space:
mode:
authorSebastien Bacher <seb128@ubuntu.com>2020-01-07 16:43:07 +0100
committerSebastien Bacher <seb128@ubuntu.com>2020-01-07 16:43:07 +0100
commita524db35ac5c2099671d16318524e277e88631be (patch)
tree54b29c42a317b9a13c3049ff85b14f7dce734cf6 /src/initrd/tests/test-cmdline-reader.c
parent6917e28d2d16138d6d497dc96efafe573b4b0979 (diff)
parent724bcc5c7be3aed3646ed2b2989c34d438217176 (diff)
Merge branch 'upstream/latest' of https://salsa.debian.org/utopia-team/network-manager into upstream
Diffstat (limited to 'src/initrd/tests/test-cmdline-reader.c')
-rw-r--r--src/initrd/tests/test-cmdline-reader.c270
1 files changed, 222 insertions, 48 deletions
diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c
index a8a6e825..1d4bb9a6 100644
--- a/src/initrd/tests/test-cmdline-reader.c
+++ b/src/initrd/tests/test-cmdline-reader.c
@@ -1,21 +1,6 @@
-/* NetworkManager initrd configuration generator
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- * Copyright 2018 Red Hat, Inc.
+// SPDX-License-Identifier: LGPL-2.1+
+/*
+ * Copyright (C) 2018 Red Hat, Inc.
  */
 
 #include "nm-default.h"
@@ -283,8 +268,7 @@ test_multiple (void)
 {
 	gs_unref_hashtable GHashTable *connections = NULL;
 	const char *const*ARGV = NM_MAKE_STRV ("ip=192.0.2.2:::::eth0",
-	                                       "ip=[2001:db8::2]:::::eth0",
-	                                       "BOOTIF=00:53:AB:cd:02:03");
+	                                       "ip=[2001:db8::2]:::::eth0");
 	NMConnection *connection;
 	NMSettingWired *s_wired;
 	NMSettingIPConfig *s_ip4;
@@ -302,7 +286,6 @@ test_multiple (void)
 
 	s_wired = nm_connection_get_setting_wired (connection);
 	g_assert (s_wired);
-	g_assert_cmpstr (nm_setting_wired_get_mac_address (s_wired), ==, "00:53:AB:CD:02:03");
 
 	s_ip4 = nm_connection_get_setting_ip4_config (connection);
 	g_assert (s_ip4);
@@ -324,12 +307,45 @@ test_multiple (void)
 }
 
 static void
+test_bootdev (void)
+{
+	gs_unref_hashtable GHashTable *connections = NULL;
+	const char *const*ARGV = NM_MAKE_STRV ("vlan=vlan2:ens5", "bootdev=ens3");
+	NMConnection *connection;
+	NMSettingConnection *s_con;
+
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
+	g_assert (connections);
+	g_assert_cmpint (g_hash_table_size (connections), ==, 2);
+
+	connection = g_hash_table_lookup (connections, "ens3");
+	g_assert (connection);
+	nmtst_assert_connection_verifies_without_normalization (connection);
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_assert (s_con);
+	g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME);
+	g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "ens3");
+	g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "ens3");
+
+	connection = g_hash_table_lookup (connections, "vlan2");
+	g_assert (connection);
+	nmtst_assert_connection_verifies_without_normalization (connection);
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_assert (s_con);
+	g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_VLAN_SETTING_NAME);
+	g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "vlan2");
+	g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "vlan2");
+}
+
+static void
 test_some_more (void)
 {
 	gs_unref_hashtable GHashTable *connections = NULL;
 	const char *const*ARGV = NM_MAKE_STRV ("bootdev=eth1", "hail", "nameserver=[2001:DB8:3::53]",
 	                                       "satan", "nameserver=192.0.2.53", "worship",
-	                                       "BOOTIF=01-00-53-AB-cd-02-03", "doom", "rd.peerdns=0",
+	                                       "doom", "rd.peerdns=0",
 	                                       "rd.route=[2001:DB8:3::/48]:[2001:DB8:2::1]:ens10");
 	NMConnection *connection;
 	NMSettingConnection *s_con;
@@ -355,7 +371,6 @@ test_some_more (void)
 
 	s_wired = nm_connection_get_setting_wired (connection);
 	g_assert (s_wired);
-	g_assert_cmpstr (nm_setting_wired_get_mac_address (s_wired), ==, "00:53:AB:CD:02:03");
 
 	s_ip4 = nm_connection_get_setting_ip4_config (connection);
 	g_assert (s_ip4);
@@ -406,17 +421,6 @@ test_some_more (void)
 }
 
 static void
-test_no_bootif (void)
-{
-	gs_unref_hashtable GHashTable *connections = NULL;
-	const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=01-00-53-AB-cd-02-03", "rd.bootif=0");
-
-	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
-	g_assert (connections);
-	g_assert_cmpint (g_hash_table_size (connections), ==, 0);
-}
-
-static void
 test_bond (void)
 {
 	gs_unref_hashtable GHashTable *connections = NULL;
@@ -651,12 +655,12 @@ test_bridge_default (void)
 	g_assert (connections);
 	g_assert_cmpint (g_hash_table_size (connections), ==, 2);
 
-	connection = g_hash_table_lookup (connections, "bridge0");
+	connection = g_hash_table_lookup (connections, "br0");
 
 	g_assert (connection);
 	nmtst_assert_connection_verifies_without_normalization (connection);
 	g_assert_cmpstr (nm_connection_get_connection_type (connection), ==, NM_SETTING_BRIDGE_SETTING_NAME);
-	g_assert_cmpstr (nm_connection_get_id (connection), ==, "bridge0");
+	g_assert_cmpstr (nm_connection_get_id (connection), ==, "br0");
 	master_uuid = nm_connection_get_uuid (connection);
 	g_assert (master_uuid);
 
@@ -801,9 +805,10 @@ test_rd_znet (void)
 {
 	gs_unref_hashtable GHashTable *connections = NULL;
 	const char *const*const ARGV = NM_MAKE_STRV ("ip=10.11.12.13::10.11.12.1:24:foo.example.com:enc800:none",
-	                                             "rd.znet=ctc,0.0.0800,0.0.0801,layer2=0,portno=1");
-	GHashTableIter h_iter;
+	                                             "rd.znet=qeth,0.0.0800,0.0.0801,0.0.0802,layer2=0,portno=1",
+	                                             "rd.znet=ctc,0.0.0600,0.0.0601,layer2=0,portno=0");
 	NMConnection *connection;
+	NMSettingConnection *s_con;
 	NMSettingWired *s_wired;
 	const char *const*v_subchannels;
 	const NMUtilsNamedValue s390_options[] = {
@@ -814,15 +819,17 @@ test_rd_znet (void)
 
 	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
 	g_assert (connections);
-	g_assert_cmpint (g_hash_table_size (connections), ==, 1);
-
-	g_hash_table_iter_init (&h_iter, connections);
-	if (!g_hash_table_iter_next (&h_iter, NULL, (gpointer *) &connection))
-		g_assert_not_reached ();
-	if (g_hash_table_iter_next (&h_iter, NULL, NULL))
-		g_assert_not_reached ();
+	g_assert_cmpint (g_hash_table_size (connections), ==, 2);
 
+	connection = g_hash_table_lookup (connections, "enc800");
 	g_assert (NM_IS_CONNECTION (connection));
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_assert (NM_IS_SETTING_CONNECTION (s_con));
+	g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME);
+	g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "enc800");
+	g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "enc800");
+
 	s_wired = nm_connection_get_setting_wired (connection);
 	g_assert (NM_IS_SETTING_WIRED (s_wired));
 
@@ -830,7 +837,8 @@ test_rd_znet (void)
 	g_assert (v_subchannels);
 	g_assert_cmpstr (v_subchannels[0], ==, "0.0.0800");
 	g_assert_cmpstr (v_subchannels[1], ==, "0.0.0801");
-	g_assert_cmpstr (v_subchannels[2], ==, NULL);
+	g_assert_cmpstr (v_subchannels[2], ==, "0.0.0802");
+	g_assert_cmpstr (v_subchannels[3], ==, NULL);
 
 	g_assert_cmpint (nm_setting_wired_get_num_s390_options (s_wired), ==, G_N_ELEMENTS (s390_options));
 	for (i_s390_options_keys = 0; i_s390_options_keys < G_N_ELEMENTS (s390_options); i_s390_options_keys++) {
@@ -853,6 +861,168 @@ test_rd_znet (void)
 	}
 
 	nmtst_assert_connection_verifies_without_normalization (connection);
+
+	connection = g_hash_table_lookup (connections, "slc600");
+	g_assert (NM_IS_CONNECTION (connection));
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_assert (NM_IS_SETTING_CONNECTION (s_con));
+	g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME);
+	g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "slc600");
+	g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "slc600");
+
+	s_wired = nm_connection_get_setting_wired (connection);
+	g_assert (NM_IS_SETTING_WIRED (s_wired));
+
+	v_subchannels = nm_setting_wired_get_s390_subchannels (s_wired);
+	g_assert (v_subchannels);
+	g_assert_cmpstr (v_subchannels[0], ==, "0.0.0600");
+	g_assert_cmpstr (v_subchannels[1], ==, "0.0.0601");
+	g_assert_cmpstr (v_subchannels[2], ==, NULL);
+
+	nmtst_assert_connection_verifies_without_normalization (connection);
+}
+
+static void
+test_rd_znet_legacy (void)
+{
+	gs_unref_hashtable GHashTable *connections = NULL;
+	const char *const*const ARGV = NM_MAKE_STRV ("ip=10.11.12.13::10.11.12.1:24:foo.example.com:eth0:none",
+	                                             "rd.znet=qeth,0.0.0800,0.0.0801,0.0.0802,layer2=0,portno=1",
+	                                             "rd.znet=ctc,0.0.0600,0.0.0601,layer2=0,portno=0",
+	                                             "net.ifnames=0");
+	NMConnection *connection;
+	NMSettingConnection *s_con;
+
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
+	g_assert (connections);
+	g_assert_cmpint (g_hash_table_size (connections), ==, 2);
+
+	connection = g_hash_table_lookup (connections, "eth0");
+	g_assert (NM_IS_CONNECTION (connection));
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_assert (NM_IS_SETTING_CONNECTION (s_con));
+	g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME);
+	g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "eth0");
+	g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "eth0");
+
+	nmtst_assert_connection_verifies_without_normalization (connection);
+
+	connection = g_hash_table_lookup (connections, "ctc0");
+	g_assert (NM_IS_CONNECTION (connection));
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_assert (NM_IS_SETTING_CONNECTION (s_con));
+	g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME);
+	g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "ctc0");
+	g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "ctc0");
+
+	nmtst_assert_connection_verifies_without_normalization (connection);
+}
+
+static void
+test_bootif (void)
+{
+	gs_unref_hashtable GHashTable *connections = NULL;
+	const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=00:53:AB:cd:02:03",
+	                                       "ip=dhcp");
+	NMConnection *connection;
+	NMSettingWired *s_wired;
+	NMSettingIPConfig *s_ip4;
+	NMSettingIPConfig *s_ip6;
+
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
+	g_assert (connections);
+	g_assert_cmpint (g_hash_table_size (connections), ==, 1);
+
+	connection = g_hash_table_lookup (connections, "default_connection");
+	g_assert (connection);
+	nmtst_assert_connection_verifies_without_normalization (connection);
+	g_assert_cmpstr (nm_connection_get_id (connection), ==, "Wired Connection");
+
+	s_wired = nm_connection_get_setting_wired (connection);
+	g_assert_cmpstr (nm_setting_wired_get_mac_address (s_wired), ==, "00:53:AB:CD:02:03");
+	g_assert (s_wired);
+
+	s_ip4 = nm_connection_get_setting_ip4_config (connection);
+	g_assert (s_ip4);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip4));
+	g_assert (!nm_setting_ip_config_get_may_fail (s_ip4));
+
+	s_ip6 = nm_connection_get_setting_ip6_config (connection);
+	g_assert (s_ip6);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DISABLED);
+	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
+}
+
+static void
+test_bootif_hwtype (void)
+{
+	gs_unref_hashtable GHashTable *connections = NULL;
+	const char *const*ARGV = NM_MAKE_STRV ("ip=eth0:dhcp",
+	                                       "BOOTIF=01-00-53-AB-cd-02-03");
+	NMConnection *connection;
+	NMSettingWired *s_wired;
+	NMSettingIPConfig *s_ip4;
+	NMSettingIPConfig *s_ip6;
+
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
+	g_assert (connections);
+	g_assert_cmpint (g_hash_table_size (connections), ==, 2);
+
+	connection = g_hash_table_lookup (connections, "eth0");
+	g_assert (connection);
+	nmtst_assert_connection_verifies_without_normalization (connection);
+	g_assert_cmpstr (nm_connection_get_id (connection), ==, "eth0");
+
+	s_wired = nm_connection_get_setting_wired (connection);
+	g_assert (!nm_setting_wired_get_mac_address (s_wired));
+	g_assert (s_wired);
+
+	s_ip4 = nm_connection_get_setting_ip4_config (connection);
+	g_assert (s_ip4);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip4));
+	g_assert (!nm_setting_ip_config_get_may_fail (s_ip4));
+
+	s_ip6 = nm_connection_get_setting_ip6_config (connection);
+	g_assert (s_ip6);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DISABLED);
+	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
+
+	connection = g_hash_table_lookup (connections, "bootif_connection");
+	g_assert (connection);
+	nmtst_assert_connection_verifies_without_normalization (connection);
+	g_assert_cmpstr (nm_connection_get_id (connection), ==, "BOOTIF Connection");
+
+	s_wired = nm_connection_get_setting_wired (connection);
+	g_assert_cmpstr (nm_setting_wired_get_mac_address (s_wired), ==, "00:53:AB:CD:02:03");
+	g_assert (s_wired);
+
+	s_ip4 = nm_connection_get_setting_ip4_config (connection);
+	g_assert (s_ip4);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip4));
+	g_assert (nm_setting_ip_config_get_may_fail (s_ip4));
+
+	s_ip6 = nm_connection_get_setting_ip6_config (connection);
+	g_assert (s_ip6);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
+	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
+	g_assert (nm_setting_ip_config_get_may_fail (s_ip6));
+}
+
+static void
+test_bootif_off (void)
+{
+	gs_unref_hashtable GHashTable *connections = NULL;
+	const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=01-00-53-AB-cd-02-03", "rd.bootif=0");
+
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
+	g_assert (connections);
+	g_assert_cmpint (g_hash_table_size (connections), ==, 0);
 }
 
 NMTST_DEFINE ();
@@ -869,7 +1039,7 @@ int main (int argc, char **argv)
 	g_test_add_func ("/initrd/cmdline/if_ip6_manual", test_if_ip6_manual);
 	g_test_add_func ("/initrd/cmdline/multiple", test_multiple);
 	g_test_add_func ("/initrd/cmdline/some_more", test_some_more);
-	g_test_add_func ("/initrd/cmdline/no_bootif", test_no_bootif);
+	g_test_add_func ("/initrd/cmdline/bootdev", test_bootdev);
 	g_test_add_func ("/initrd/cmdline/bond", test_bond);
 	g_test_add_func ("/initrd/cmdline/bond/default", test_bond_default);
 	g_test_add_func ("/initrd/cmdline/team", test_team);
@@ -877,7 +1047,11 @@ int main (int argc, char **argv)
 	g_test_add_func ("/initrd/cmdline/bridge/default", test_bridge_default);
 	g_test_add_func ("/initrd/cmdline/ibft", test_ibft);
 	g_test_add_func ("/initrd/cmdline/ignore_extra", test_ignore_extra);
-	g_test_add_func ("/initrd/cmdline/rd_zdnet", test_rd_znet);
+	g_test_add_func ("/initrd/cmdline/rd_znet", test_rd_znet);
+	g_test_add_func ("/initrd/cmdline/rd_znet/legacy", test_rd_znet_legacy);
+	g_test_add_func ("/initrd/cmdline/bootif", test_bootif);
+	g_test_add_func ("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype);
+	g_test_add_func ("/initrd/cmdline/bootif/off", test_bootif_off);
 
 	return g_test_run ();
 }