diff options
Diffstat (limited to 'src/nm-initrd-generator/tests')
| -rw-r--r-- | src/nm-initrd-generator/tests/test-cmdline-reader.c | 100 |
1 files changed, 74 insertions, 26 deletions
diff --git a/src/nm-initrd-generator/tests/test-cmdline-reader.c b/src/nm-initrd-generator/tests/test-cmdline-reader.c index 33b83497..a0100764 100644 --- a/src/nm-initrd-generator/tests/test-cmdline-reader.c +++ b/src/nm-initrd-generator/tests/test-cmdline-reader.c @@ -23,7 +23,12 @@ /*****************************************************************************/ -#define _parse(ARGV, out_hostname, out_carrier_timeout_sec) \ +#define _parse(ARGV, \ + out_hostname, \ + out_carrier_timeout_sec, \ + _out_global_dns_servers, \ + _out_dns_backend, \ + _out_dns_resolve_mode) \ ({ \ const char *const *const _ARGV = (ARGV); \ char **const _out_hostname = (out_hostname); \ @@ -34,26 +39,31 @@ TEST_INITRD_DIR "/sysfs", \ _ARGV, \ _out_hostname, \ - _out_carrier_timeout_sec); \ - \ + _out_carrier_timeout_sec, \ + _out_global_dns_servers, \ + _out_dns_backend, \ + _out_dns_resolve_mode); \ g_assert(_connections); \ \ _connections; \ }) -#define _parse_cons(ARGV) \ - ({ \ - GHashTable *_con_connections; \ - gs_free char *_con_hostname = NULL; \ - gint64 _con_carrier_timeout_sec = 0; \ - \ - _con_connections = _parse((ARGV), \ - nmtst_get_rand_bool() ? &_con_hostname : NULL, \ - nmtst_get_rand_bool() ? &_con_carrier_timeout_sec : NULL); \ - g_assert_cmpstr(_con_hostname, ==, NULL); \ - g_assert_cmpint(_con_carrier_timeout_sec, ==, 0); \ - \ - _con_connections; \ +#define _parse_cons(ARGV) \ + ({ \ + GHashTable *_con_connections; \ + gs_free char *_con_hostname = NULL; \ + gint64 _con_carrier_timeout_sec = 0; \ + \ + _con_connections = _parse((ARGV), \ + nmtst_get_rand_bool() ? &_con_hostname : NULL, \ + nmtst_get_rand_bool() ? &_con_carrier_timeout_sec : NULL, \ + NULL, \ + NULL, \ + NULL); \ + g_assert_cmpstr(_con_hostname, ==, NULL); \ + g_assert_cmpint(_con_carrier_timeout_sec, ==, 0); \ + \ + _con_connections; \ }) #define _parse_con(ARGV, connection_name) \ @@ -154,7 +164,7 @@ test_dhcp_with_hostname(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 1); g_assert_cmpstr(hostname, ==, "host1"); g_assert_cmpint(carrier_timeout_sec, ==, 0); @@ -424,7 +434,7 @@ test_if_ip4_manual(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 2); g_assert_cmpstr(hostname, ==, "hostname1.example.com"); g_assert_cmpint(carrier_timeout_sec, ==, 0); @@ -505,7 +515,7 @@ test_if_ip4_auto(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 1); g_assert_cmpstr(hostname, ==, "myhostname"); g_assert_cmpint(carrier_timeout_sec, ==, 0); @@ -596,7 +606,7 @@ test_if_ip6_manual(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 1); g_assert_cmpstr(hostname, ==, "hostname0.example.com"); g_assert_cmpint(carrier_timeout_sec, ==, 0); @@ -684,7 +694,7 @@ test_if_mac_ifname(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 1); g_assert_cmpstr(hostname, ==, "hostname0"); g_assert_cmpint(carrier_timeout_sec, ==, 0); @@ -1840,7 +1850,7 @@ test_rd_znet(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 2); g_assert_cmpstr(hostname, ==, "foo.example.com"); g_assert_cmpint(carrier_timeout_sec, ==, 0); @@ -1927,7 +1937,7 @@ test_rd_znet_legacy(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 2); g_assert_cmpstr(hostname, ==, "foo.example.com"); g_assert_cmpint(carrier_timeout_sec, ==, 0); @@ -2006,7 +2016,7 @@ test_rd_znet_ifnames(void) gint64 carrier_timeout_sec = 0; const char *const *v_subchannels; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 2); connection = g_hash_table_lookup(connections, "zeth0"); @@ -2281,7 +2291,7 @@ test_nameserver(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 3); g_assert_cmpstr(hostname, ==, "foo.example.com"); g_assert_cmpint(carrier_timeout_sec, ==, 0); @@ -2460,12 +2470,49 @@ test_carrier_timeout(void) gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; - connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + connections = _parse(ARGV, &hostname, &carrier_timeout_sec, NULL, NULL, NULL); g_assert_cmpint(g_hash_table_size(connections), ==, 0); g_assert_cmpstr(hostname, ==, NULL); g_assert_cmpint(carrier_timeout_sec, ==, 20); } +static void +test_global_dns(void) +{ + gs_unref_hashtable GHashTable *connections = NULL; + const char *const *ARGV = NM_MAKE_STRV("rd.net.dns=dns+tls://8.8.8.8", + "rd.net.dns=1.1.1.1", + "rd.net.dns=foobar", + "rd.net.dns=dns+tls://[fd01::1]:35#name", + "rd.net.dns-backend=dnsconfd", + "rd.net.dns-resolve-mode=exclusive"); + gs_free char *hostname = NULL; + gs_strfreev char **global_dns_servers = NULL; + gs_free char *dns_backend = NULL; + gs_free char *dns_resolve_mode = NULL; + gint64 carrier_timeout_sec = 0; + + NMTST_EXPECT_NM_WARN("cmdline-reader: rd.net.dns: invalid server 'foobar'"); + connections = _parse(ARGV, + &hostname, + &carrier_timeout_sec, + &global_dns_servers, + &dns_backend, + &dns_resolve_mode); + g_test_assert_expected_messages(); + + g_assert_cmpint(g_hash_table_size(connections), ==, 0); + g_assert_cmpstr(hostname, ==, NULL); + g_assert_cmpint(carrier_timeout_sec, ==, 0); + g_assert(global_dns_servers != NULL); + g_assert_cmpstr(global_dns_servers[0], ==, "dns+tls://8.8.8.8"); + g_assert_cmpstr(global_dns_servers[1], ==, "1.1.1.1"); + g_assert_cmpstr(global_dns_servers[2], ==, "dns+tls://[fd01::1]:35#name"); + g_assert_cmpstr(global_dns_servers[3], ==, NULL); + g_assert_cmpstr(dns_backend, ==, "dnsconfd"); + g_assert_cmpstr(dns_resolve_mode, ==, "exclusive"); +} + #define _ethtool_check_inval(arg) \ G_STMT_START \ { \ @@ -2686,6 +2733,7 @@ main(int argc, char **argv) g_test_add_func("/initrd/cmdline/carrier_timeout", test_carrier_timeout); g_test_add_func("/initrd/cmdline/rd_ethtool", test_rd_ethtool); g_test_add_func("/initrd/cmdline/plain_equal_char", test_plain_equal_char); + g_test_add_func("/initrd/cmdline/global_dns", test_global_dns); return g_test_run(); } |