diff options
Diffstat (limited to 'src/initrd/tests/test-cmdline-reader.c')
-rw-r--r-- | src/initrd/tests/test-cmdline-reader.c | 153 |
1 files changed, 103 insertions, 50 deletions
diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c index 84f01b8a5f..5352f2cffe 100644 --- a/src/initrd/tests/test-cmdline-reader.c +++ b/src/initrd/tests/test-cmdline-reader.c @@ -25,14 +25,14 @@ static void test_auto (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "ip=auto", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("ip=auto"); NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 1); @@ -77,13 +77,13 @@ static void test_if_auto_with_mtu (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "ip=eth0:auto:1666", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("ip=eth0:auto:1666"); NMConnection *connection; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 1); @@ -112,12 +112,12 @@ static void test_if_dhcp6 (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "ip=eth1:dhcp6", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("ip=eth1:dhcp6"); NMConnection *connection; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + 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, "eth1"); @@ -141,13 +141,13 @@ static void test_if_auto_with_mtu_and_mac (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "ip=eth2:auto6:2048:00:53:ef:12:34:56", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("ip=eth2:auto6:2048:00:53:ef:12:34:56"); NMConnection *connection; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 1); @@ -177,16 +177,15 @@ static void test_if_ip4_manual (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ - "ip=192.0.2.2::192.0.2.1:255.255.255.0:" - "hostname0.example.com:eth3::192.0.2.53", - "ip=203.0.113.2::203.0.113.1:26:" - "hostname1.example.com:eth4", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("ip=192.0.2.2::192.0.2.1:255.255.255.0:" + "hostname0.example.com:eth3::192.0.2.53", + "ip=203.0.113.2::203.0.113.1:26:" + "hostname1.example.com:eth4"); NMConnection *connection; NMSettingIPConfig *s_ip4; NMIPAddress *ip_addr; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 2); @@ -234,16 +233,13 @@ static void test_if_ip6_manual (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ - "ip=[2001:0db8::02]/64::[2001:0db8::01]::" - "hostname0.example.com:eth4::[2001:0db8::53]", - NULL - }); + const char *const*ARGV = NM_MAKE_STRV ("ip=[2001:0db8::02]/64::[2001:0db8::01]::" + "hostname0.example.com:eth4::[2001:0db8::53]"); NMConnection *connection; NMSettingIPConfig *s_ip6; NMIPAddress *ip_addr; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 1); @@ -272,17 +268,16 @@ static void test_multiple (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "ip=192.0.2.2:::::eth0", - "ip=[2001:db8::2]:::::eth0", - "BOOTIF=00:53:AB:cd:02:03", - 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"); NMConnection *connection; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMIPAddress *ip_addr; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 1); @@ -318,11 +313,10 @@ static void test_some_more (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "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", - "rd.route=[2001:DB8:3::/48]:[2001:DB8:2::1]:ens10", - 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", + "rd.route=[2001:DB8:3::/48]:[2001:DB8:2::1]:ens10"); NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; @@ -330,7 +324,7 @@ test_some_more (void) NMSettingIPConfig *s_ip6; NMIPRoute *ip_route; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 2); @@ -401,9 +395,9 @@ static void test_no_bootif (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "BOOTIF=01-00-53-AB-cd-02-03", "rd.bootif=0", 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); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 0); } @@ -412,10 +406,9 @@ static void test_bond (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "rd.route=192.0.2.53::bong0", - "bond=bong0:eth0,eth1:mode=balance-rr", - "nameserver=203.0.113.53", - NULL }); + const char *const*ARGV = NM_MAKE_STRV ("rd.route=192.0.2.53::bong0", + "bond=bong0:eth0,eth1:mode=balance-rr", + "nameserver=203.0.113.53"); NMConnection *connection; NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; @@ -424,7 +417,7 @@ test_bond (void) NMIPRoute *ip_route; const char *master_uuid; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 3); @@ -495,7 +488,7 @@ static void test_bond_default (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "bond", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("bond"); NMConnection *connection; NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; @@ -503,7 +496,7 @@ test_bond_default (void) NMSettingBond *s_bond; const char *master_uuid; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 2); @@ -555,7 +548,7 @@ static void test_bridge (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "bridge=bridge0:eth0,eth1", "rd.route=192.0.2.53::bridge0", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("bridge=bridge0:eth0,eth1", "rd.route=192.0.2.53::bridge0"); NMConnection *connection; NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; @@ -564,7 +557,7 @@ test_bridge (void) NMIPRoute *ip_route; const char *master_uuid; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 3); @@ -632,7 +625,7 @@ static void test_bridge_default (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "bridge", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("bridge"); NMConnection *connection; NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; @@ -640,7 +633,7 @@ test_bridge_default (void) NMSettingBridge *s_bridge; const char *master_uuid; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 2); @@ -690,7 +683,7 @@ static void test_team (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "team=team0:eth0,eth1", "ip=team0:dhcp6", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("team=team0:eth0,eth1", "ip=team0:dhcp6"); NMConnection *connection; NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; @@ -698,7 +691,7 @@ test_team (void) NMSettingTeam *s_team; const char *master_uuid; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 3); @@ -760,10 +753,10 @@ static void test_ibft (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "ip=ibft", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("ip=ibft"); NMConnection *connection; - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV); g_assert (connections); g_assert_cmpint (g_hash_table_size (connections), ==, 2); @@ -782,13 +775,72 @@ static void test_ignore_extra (void) { gs_unref_hashtable GHashTable *connections = NULL; - gs_strfreev char **argv = g_strdupv ((char *[]){ "blabla", "extra", "lalala", NULL }); + const char *const*ARGV = NM_MAKE_STRV ("blabla", "extra", "lalala"); - connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", argv); + 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_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; + NMConnection *connection; + NMSettingWired *s_wired; + const char *const*v_subchannels; + const NMUtilsNamedValue s390_options[] = { + { .name = "layer2", .value_str = "0" }, + { .name = "portno", .value_str = "1" }, + }; + int i_s390_options_keys; + + 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 (NM_IS_CONNECTION (connection)); + 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.0800"); + g_assert_cmpstr (v_subchannels[1], ==, "0.0.0801"); + g_assert_cmpstr (v_subchannels[2], ==, 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++) { + const NMUtilsNamedValue *s390_option = &s390_options[i_s390_options_keys]; + const char *k; + const char *v; + const char *v2; + + g_assert (s390_option->name); + g_assert (s390_option->value_str); + v = nm_setting_wired_get_s390_option_by_key (s_wired, s390_option->name); + g_assert (v); + g_assert_cmpstr (v, ==, s390_option->value_str); + + if (!nm_setting_wired_get_s390_option (s_wired, i_s390_options_keys, &k, &v2)) + g_assert_not_reached (); + g_assert_cmpstr (k, ==, s390_option->name); + g_assert (v == v2); + g_assert_cmpstr (v2, ==, s390_option->value_str); + } + + nmtst_assert_connection_verifies_without_normalization (connection); +} + NMTST_DEFINE (); int main (int argc, char **argv) @@ -811,6 +863,7 @@ 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); return g_test_run (); } |