summary refs log tree commit diff
path: root/src/core/tests
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2023-02-10 11:50:34 +0100
committerMichael Biebl <biebl@debian.org>2023-02-10 11:50:34 +0100
commit1372848511cb896b80b51ed1a3e9606bd9816631 (patch)
tree674792b9385bdef935988894b45f06b2af39f88c /src/core/tests
parent40ec077ea305994c1fc2130add6787ca0c73e2c6 (diff)
New upstream version 1.42.0 upstream/1.42.0
Diffstat (limited to 'src/core/tests')
-rw-r--r--src/core/tests/config/global-dns-good.conf13
-rw-r--r--src/core/tests/config/global-dns-options.conf5
-rw-r--r--src/core/tests/config/nm-test-device.h3
-rw-r--r--src/core/tests/config/test-config.c22
-rw-r--r--src/core/tests/test-core-with-expect.c28
-rw-r--r--src/core/tests/test-core.c31
-rw-r--r--src/core/tests/test-l3cfg.c37
-rw-r--r--src/core/tests/test-systemd.c16
8 files changed, 87 insertions, 68 deletions
diff --git a/src/core/tests/config/global-dns-good.conf b/src/core/tests/config/global-dns-good.conf
new file mode 100644
index 00000000..6265a611
--- /dev/null
+++ b/src/core/tests/config/global-dns-good.conf
@@ -0,0 +1,13 @@
+# Good configuration, since there is a default domain section
+
+[global-dns]
+searches=foo.com
+options=timeout:5
+
+[global-dns-domain-*]
+servers=4.5.6.7
+options=myoption1
+
+[global-dns-domain-test.com]
+servers=1.2.3.4
+options=myoption2
diff --git a/src/core/tests/config/global-dns-options.conf b/src/core/tests/config/global-dns-options.conf
new file mode 100644
index 00000000..0be17735
--- /dev/null
+++ b/src/core/tests/config/global-dns-options.conf
@@ -0,0 +1,5 @@
+# Good configuration, since there is no domain section
+
+[global-dns]
+searches=foo.com
+options=timeout:5
diff --git a/src/core/tests/config/nm-test-device.h b/src/core/tests/config/nm-test-device.h
index 638177a0..48a53bf4 100644
--- a/src/core/tests/config/nm-test-device.h
+++ b/src/core/tests/config/nm-test-device.h
@@ -9,7 +9,8 @@
 #include "devices/nm-device.h"
 
 #define NM_TYPE_TEST_DEVICE (nm_test_device_get_type())
-#define NM_TEST_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_TEST_DEVICE, NMTestDevice))
+#define NM_TEST_DEVICE(obj) \
+    (_NM_G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_TEST_DEVICE, NMTestDevice))
 #define NM_TEST_DEVICE_CLASS(klass) \
     (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_TEST_DEVICE, NMTestDeviceClass))
 #define NM_IS_TEST_DEVICE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_TEST_DEVICE))
diff --git a/src/core/tests/config/test-config.c b/src/core/tests/config/test-config.c
index 17a66b06..054b9003 100644
--- a/src/core/tests/config/test-config.c
+++ b/src/core/tests/config/test-config.c
@@ -370,7 +370,21 @@ test_config_global_dns(void)
 
     g_object_unref(config);
 
-    /* Check that a file without a default domain section gives a NULL configuration */
+    /* Check that a file with a default domain section gives a good configuration */
+    config =
+        setup_config(NULL, TEST_DIR "/global-dns-good.conf", "", NULL, "/no/such/dir", "", NULL);
+    dns = nm_config_data_get_global_dns_config(nm_config_get_data_orig(config));
+    g_assert(dns);
+    g_object_unref(config);
+
+    /* Check that a file with options but no domains gives a good configuration */
+    config =
+        setup_config(NULL, TEST_DIR "/global-dns-options.conf", "", NULL, "/no/such/dir", "", NULL);
+    dns = nm_config_data_get_global_dns_config(nm_config_get_data_orig(config));
+    g_assert(dns);
+    g_object_unref(config);
+
+    /* Check that a file with a domain domain, but without a default one gives a NULL configuration */
     config =
         setup_config(NULL, TEST_DIR "/global-dns-invalid.conf", "", NULL, "/no/such/dir", "", NULL);
     dns = nm_config_data_get_global_dns_config(nm_config_get_data_orig(config));
@@ -1103,9 +1117,9 @@ test_config_set_values(void)
     const char               *CONFIG_USER               = BUILD_DIR "/test-set-values-user.conf";
     const char               *CONFIG_INTERN             = BUILD_DIR "/test-set-values-intern.conf";
     const char               *atomic_section_prefixes[] = {
-                      "atomic-prefix-1.",
-                      "atomic-prefix-2.",
-                      NULL,
+        "atomic-prefix-1.",
+        "atomic-prefix-2.",
+        NULL,
     };
 
     g_assert(g_file_set_contents(CONFIG_USER, "", 0, NULL));
diff --git a/src/core/tests/test-core-with-expect.c b/src/core/tests/test-core-with-expect.c
index de510c76..b05144ac 100644
--- a/src/core/tests/test-core-with-expect.c
+++ b/src/core/tests/test-core-with-expect.c
@@ -227,11 +227,11 @@ do_test_nm_utils_kill_child(void)
 {
     GLogLevelFlags fatal_mask;
     char          *argv_watchdog[] = {
-                 "bash",
-                 "-c",
-                 "sleep 4; "
-                          "kill -KILL 0; #watchdog for #" TEST_TOKEN,
-                 NULL,
+        "bash",
+        "-c",
+        "sleep 4; "
+                 "kill -KILL 0; #watchdog for #" TEST_TOKEN,
+        NULL,
     };
     char *argv1[] = {
         "bash",
@@ -282,7 +282,7 @@ do_test_nm_utils_kill_child(void)
     pid4a   = test_nm_utils_kill_child_spawn(argv4, TRUE);
 
     /* give processes time to start (and potentially block signals) ... */
-    g_usleep(G_USEC_PER_SEC / 10);
+    g_usleep(G_USEC_PER_SEC / 5);
 
     fatal_mask = g_log_set_always_fatal(G_LOG_FATAL_MASK);
 
@@ -338,12 +338,12 @@ do_test_nm_utils_kill_child(void)
         "(No child process*, 10) after sending no signal (0)");
     test_nm_utils_kill_child_sync_do("test-s-3-2", pid3s, 0, 0, FALSE, NULL);
 
-    NMTST_EXPECT_NM_DEBUG("kill child process 'test-s-4' (*): waiting up to 1 milliseconds for "
+    NMTST_EXPECT_NM_DEBUG("kill child process 'test-s-4' (*): waiting up to 50 milliseconds for "
                           "process to terminate normally after sending SIGTERM (15)...");
     NMTST_EXPECT_NM_DEBUG("kill child process 'test-s-4' (*): sending SIGKILL...");
     NMTST_EXPECT_NM_DEBUG("kill child process 'test-s-4' (*): after sending SIGTERM (15) and "
                           "SIGKILL, process * exited by signal 9 (* usec elapsed)");
-    test_nm_utils_kill_child_sync_do("test-s-4", pid4s, SIGTERM, 1, TRUE, &expected_signal_KILL);
+    test_nm_utils_kill_child_sync_do("test-s-4", pid4s, SIGTERM, 50, TRUE, &expected_signal_KILL);
 
     NMTST_EXPECT_NM_DEBUG("kill child process 'test-a-1-1' (*): wait for process to terminate "
                           "after sending SIGTERM (15) (send SIGKILL in 3000 milliseconds)...");
@@ -528,27 +528,27 @@ test_nm_utils_array_remove_at_indexes(void)
                 _remove_at_indexes_init_random_idx(idx, i_len, i_idx_len);
                 g_array_set_size(array, i_len);
                 for (i = 0; i < i_len; i++)
-                    g_array_index(array, gssize, i) = i;
+                    nm_g_array_index(array, gssize, i) = i;
 
-                nm_utils_array_remove_at_indexes(array, &g_array_index(idx, guint, 0), i_idx_len);
+                nm_utils_array_remove_at_indexes(array, nm_g_array_first_p(idx, guint), i_idx_len);
 
                 g_hash_table_remove_all(unique);
                 /* ensure that all the indexes are still unique */
                 for (i = 0; i < array->len; i++)
-                    g_hash_table_add(unique, GUINT_TO_POINTER(g_array_index(array, gssize, i)));
+                    g_hash_table_add(unique, GUINT_TO_POINTER(nm_g_array_index(array, gssize, i)));
                 g_assert_cmpint(g_hash_table_size(unique), ==, array->len);
 
                 for (i = 0; i < idx->len; i++)
-                    g_hash_table_add(unique, GUINT_TO_POINTER(g_array_index(idx, guint, i)));
+                    g_hash_table_add(unique, GUINT_TO_POINTER(nm_g_array_index(idx, guint, i)));
                 g_assert_cmpint(g_hash_table_size(unique), ==, i_len);
 
                 /* ensure proper sort order in array */
                 for (i = 0; i < array->len; i++) {
-                    gssize i1 = g_array_index(array, gssize, i);
+                    gssize i1 = nm_g_array_index(array, gssize, i);
 
                     g_assert(i1 >= 0 && i1 < i_len);
                     if (i > 0) {
-                        gsize i0 = g_array_index(array, gssize, i - 1);
+                        gsize i0 = nm_g_array_index(array, gssize, i - 1);
                         g_assert_cmpint(i0, <, i1);
                     }
                 }
diff --git a/src/core/tests/test-core.c b/src/core/tests/test-core.c
index c260788e..887803bf 100644
--- a/src/core/tests/test-core.c
+++ b/src/core/tests/test-core.c
@@ -40,7 +40,7 @@ test_config_h(void)
 
 /*****************************************************************************/
 
-/* Reference implementation for nm_utils_ip6_address_clear_host_address.
+/* Reference implementation for nm_ip6_addr_clear_host_address.
  * Taken originally from set_address_masked(), src/ndisc/nm-lndp-ndisc.c
  **/
 static void
@@ -95,14 +95,14 @@ test_nm_utils_ip6_address_clear_host_address(void)
             _randomize_in6_addr(&addr1, r);
             _randomize_in6_addr(&addr2, r);
             addr1 = addr_src;
-            nm_utils_ip6_address_clear_host_address(&addr2, &addr1, plen);
+            nm_ip6_addr_clear_host_address(&addr2, &addr1, plen);
             g_assert_cmpint(memcmp(&addr1, &addr_src, sizeof(struct in6_addr)), ==, 0);
             g_assert_cmpint(memcmp(&addr2, &addr_ref, sizeof(struct in6_addr)), ==, 0);
 
             /* test for self assignment/inplace update. */
             _randomize_in6_addr(&addr1, r);
             addr1 = addr_src;
-            nm_utils_ip6_address_clear_host_address(&addr1, &addr1, plen);
+            nm_ip6_addr_clear_host_address(&addr1, &addr1, plen);
             g_assert_cmpint(memcmp(&addr1, &addr_ref, sizeof(struct in6_addr)), ==, 0);
         }
     }
@@ -152,14 +152,14 @@ test_logging_error(void)
 static void
 _test_same_prefix(const char *a1, const char *a2, guint8 plen)
 {
-    struct in6_addr a = *nmtst_inet6_from_string(a1);
-    struct in6_addr b = *nmtst_inet6_from_string(a2);
+    struct in6_addr a = nmtst_inet6_from_string(a1);
+    struct in6_addr b = nmtst_inet6_from_string(a2);
 
-    g_assert(nm_utils_ip6_address_same_prefix(&a, &b, plen));
+    g_assert(nm_ip6_addr_same_prefix(&a, &b, plen));
 }
 
 static void
-test_nm_utils_ip6_address_same_prefix(void)
+test_nm_ip_addr_same_prefix(void)
 {
     guint       n, i;
     const guint N = 100;
@@ -202,7 +202,7 @@ again_plen:
         } else
             b = a;
 
-        result = nm_utils_ip6_address_same_prefix(&a.val, &b.val, plen);
+        result = nm_ip6_addr_same_prefix(&a.val, &b.val, plen);
         g_assert(result == is_same);
         g_assert(NM_IN_SET(result, TRUE, FALSE));
     }
@@ -214,12 +214,12 @@ again_plen:
         plen = nmtst_get_rand_uint32() % 129;
 
         memset(addrmask.ptr, 0xFF, sizeof(addrmask));
-        nm_utils_ip6_address_clear_host_address(&addrmask.val, &addrmask.val, plen);
+        nm_ip6_addr_clear_host_address(&addrmask.val, &addrmask.val, plen);
 
         for (i = 0; i < sizeof(a); i++)
             b.ptr[i] = (a.ptr[i] & addrmask.ptr[i]) | (b.ptr[i] & ~addrmask.ptr[i]);
 
-        g_assert(nm_utils_ip6_address_same_prefix(&a.val, &b.val, plen) == TRUE);
+        g_assert(nm_ip6_addr_same_prefix(&a.val, &b.val, plen) == TRUE);
     }
 
     /* test#3 */
@@ -234,10 +234,10 @@ again_plen:
             continue;
 
         memset(addrmask.ptr, 0xFF, sizeof(addrmask));
-        nm_utils_ip6_address_clear_host_address(&addrmask.val, &addrmask.val, plen);
+        nm_ip6_addr_clear_host_address(&addrmask.val, &addrmask.val, plen);
 
         memset(addrmask_bit.ptr, 0xFF, sizeof(addrmask_bit));
-        nm_utils_ip6_address_clear_host_address(&addrmask_bit.val, &addrmask_bit.val, plen - 1);
+        nm_ip6_addr_clear_host_address(&addrmask_bit.val, &addrmask_bit.val, plen - 1);
 
         for (i = 0; i < sizeof(a); i++)
             b.ptr[i] = (a.ptr[i] & addrmask.ptr[i]) | (b.ptr[i] & ~addrmask.ptr[i]);
@@ -254,7 +254,7 @@ again_plen:
         }
         g_assert(reached);
 
-        g_assert(nm_utils_ip6_address_same_prefix(&a.val, &b.val, plen) == FALSE);
+        g_assert(nm_ip6_addr_same_prefix(&a.val, &b.val, plen) == FALSE);
     }
 
     /* test#4 */
@@ -2594,10 +2594,9 @@ main(int argc, char **argv)
 
     g_test_add_func("/general/nm_strbuf_append", test_nm_utils_strbuf_append);
 
-    g_test_add_func("/general/nm_utils_ip6_address_clear_host_address",
+    g_test_add_func("/general/nm_ip6_addr_clear_host_address",
                     test_nm_utils_ip6_address_clear_host_address);
-    g_test_add_func("/general/nm_utils_ip6_address_same_prefix",
-                    test_nm_utils_ip6_address_same_prefix);
+    g_test_add_func("/general/nm_ip6_addr_same_prefix", test_nm_ip_addr_same_prefix);
     g_test_add_func("/general/nm_utils_log_connection_diff", test_nm_utils_log_connection_diff);
 
     g_test_add_func("/general/nm_utils_sysctl_ip_conf_path", test_nm_utils_sysctl_ip_conf_path);
diff --git a/src/core/tests/test-l3cfg.c b/src/core/tests/test-l3cfg.c
index a9ac4004..962b2eec 100644
--- a/src/core/tests/test-l3cfg.c
+++ b/src/core/tests/test-l3cfg.c
@@ -2,7 +2,7 @@
 
 #include "src/core/nm-default-daemon.h"
 
-#include <linux/if_addr.h>
+#include "nm-compat-headers/linux/if_addr.h"
 
 #include "nm-l3cfg.h"
 #include "nm-l3-ipv4ll.h"
@@ -339,6 +339,10 @@ test_l3cfg(gconstpointer test_data)
 
     _LOGD("test start (/l3cfg/%d)", TEST_IDX);
 
+    /* FIXME: https://bugzilla.redhat.com/show_bug.cgi?id=2165141 */
+    g_test_skip("Skip: this test is currently known to fail (rhbz#2165141)");
+    return;
+
     if (nmtst_test_quick()) {
         gs_free char *msg =
             g_strdup_printf("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n",
@@ -418,7 +422,7 @@ test_l3cfg(gconstpointer test_data)
 
         nm_l3_config_data_add_address_6(
             l3cd,
-            NM_PLATFORM_IP6_ADDRESS_INIT(.address = *nmtst_inet6_from_string("1:2:3:4::45"),
+            NM_PLATFORM_IP6_ADDRESS_INIT(.address = nmtst_inet6_from_string("1:2:3:4::45"),
                                          .plen    = 64, ));
 
         if (nmtst_get_rand_one_case_in(2))
@@ -572,7 +576,7 @@ _test_l3_ipv4ll_signal_notify(NML3Cfg                    *l3cfg,
                               const NML3ConfigNotifyData *notify_data,
                               TestL3IPv4LLData           *tdata)
 {
-    char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN];
+    char sbuf_addr[NM_INET_ADDRSTRLEN];
 
     g_assert(NM_IS_L3CFG(l3cfg));
     g_assert(tdata);
@@ -593,9 +597,9 @@ _test_l3_ipv4ll_signal_notify(NML3Cfg                    *l3cfg,
             if (tdata->f->test_idx == 2 && nmtst_get_rand_bool()) {
                 tdata->addr_commit++;
                 tdata->addr_commit_addr = nm_l3_ipv4ll_get_addr(tdata->l3ipv4ll);
-                g_assert(nm_utils_ip4_address_is_link_local(tdata->addr_commit_addr));
+                g_assert(nm_ip4_addr_is_link_local(tdata->addr_commit_addr));
                 _LOGT("add address %s that passed ACD",
-                      _nm_utils_inet4_ntop(tdata->addr_commit_addr, sbuf_addr));
+                      nm_inet4_ntop(tdata->addr_commit_addr, sbuf_addr));
                 if (!nm_l3cfg_add_config(nm_l3_ipv4ll_get_l3cfg(tdata->l3ipv4ll),
                                          TEST_L3_IPV4LL_TAG(tdata, 1),
                                          nmtst_get_rand_bool(),
@@ -630,9 +634,9 @@ _test_l3_ipv4ll_signal_notify(NML3Cfg                    *l3cfg,
             if (tdata->addr_commit > 0) {
                 g_assert_cmpint(tdata->addr_commit, ==, 1);
                 tdata->addr_commit--;
-                g_assert(nm_utils_ip4_address_is_link_local(tdata->addr_commit_addr));
+                g_assert(nm_ip4_addr_is_link_local(tdata->addr_commit_addr));
                 _LOGT("remove address %s that previously passed ACD",
-                      _nm_utils_inet4_ntop(tdata->addr_commit_addr, sbuf_addr));
+                      nm_inet4_ntop(tdata->addr_commit_addr, sbuf_addr));
                 if (!nm_l3cfg_remove_config_all(nm_l3_ipv4ll_get_l3cfg(tdata->l3ipv4ll),
                                                 TEST_L3_IPV4LL_TAG(tdata, 1)))
                     g_assert_not_reached();
@@ -663,7 +667,7 @@ test_l3_ipv4ll(gconstpointer test_data)
     gint64                                                       start_time_msec;
     gint64                                                       total_poll_time_msec;
     nm_auto_remove_l3ipv4ll_registration NML3IPv4LLRegistration *l3ipv4ll_reg = NULL;
-    char sbuf_addr[NM_UTILS_INET_ADDRSTRLEN];
+    char                                                         sbuf_addr[NM_INET_ADDRSTRLEN];
 
     _LOGD("test start (/l3-ipv4ll/%d)", TEST_IDX);
 
@@ -733,12 +737,12 @@ test_l3_ipv4ll(gconstpointer test_data)
     if (tdata->f->test_idx == 2 && nmtst_get_rand_one_case_in(3)) {
         in_addr_t a = nm_l3_ipv4ll_get_addr(l3ipv4ll);
 
-        g_assert(nm_utils_ip4_address_is_link_local(a));
+        g_assert(nm_ip4_addr_is_link_local(a));
         _test_l3_ipv4ll_maybe_add_addr_4(tdata,
                                          tdata->f->ifindex1,
                                          2,
                                          &tdata->add_conflict_done,
-                                         _nm_utils_inet4_ntop(a, sbuf_addr));
+                                         nm_inet4_ntop(a, sbuf_addr));
         g_assert_cmpint(tdata->f->hwaddr1.len, ==, sizeof(NMEtherAddr));
         acd_defender_2 =
             nmtstp_acd_defender_new(tdata->f->ifindex1, a, &tdata->f->hwaddr1.ether_addr);
@@ -768,12 +772,11 @@ test_l3_ipv4ll(gconstpointer test_data)
 
         if (tdata->addr_commit == 1 && !tdata->add_conflict_checked) {
             tdata->add_conflict_checked = TRUE;
-            _test_l3_ipv4ll_maybe_add_addr_4(
-                tdata,
-                tdata->f->ifindex1,
-                2,
-                &tdata->add_conflict_done,
-                _nm_utils_inet4_ntop(tdata->addr_commit_addr, sbuf_addr));
+            _test_l3_ipv4ll_maybe_add_addr_4(tdata,
+                                             tdata->f->ifindex1,
+                                             2,
+                                             &tdata->add_conflict_done,
+                                             nm_inet4_ntop(tdata->addr_commit_addr, sbuf_addr));
             if (tdata->add_conflict_done)
                 total_poll_time_msec += L3IPV4LL_ACD_TIMEOUT_MSEC / 2;
             g_assert_cmpint(tdata->f->hwaddr1.len, ==, sizeof(NMEtherAddr));
@@ -986,7 +989,7 @@ test_l3_ipv6ll(gconstpointer test_data)
         nmtstp_ip6_address_add(tdata->f->platform,
                                -1,
                                tdata->f->ifindex1,
-                               *nmtst_inet6_from_string(_LLADDR_TEST1),
+                               nmtst_inet6_from_string(_LLADDR_TEST1),
                                64,
                                in6addr_any,
                                NM_PLATFORM_LIFETIME_PERMANENT,
diff --git a/src/core/tests/test-systemd.c b/src/core/tests/test-systemd.c
index cf31ec33..1b0b7f65 100644
--- a/src/core/tests/test-systemd.c
+++ b/src/core/tests/test-systemd.c
@@ -12,21 +12,6 @@
 
 /*****************************************************************************/
 
-static void
-test_lldp_create(void)
-{
-    sd_lldp_rx *lldp = NULL;
-    int         r;
-
-    r = sd_lldp_rx_new(&lldp);
-    g_assert(r == 0);
-    g_assert(lldp);
-
-    sd_lldp_rx_unref(lldp);
-}
-
-/*****************************************************************************/
-
 typedef struct {
     GMainLoop       *mainloop;
     sd_event_source *event_source;
@@ -105,7 +90,6 @@ main(int argc, char **argv)
 {
     nmtst_init(&argc, &argv, TRUE);
 
-    g_test_add_func("/systemd/lldp/create", test_lldp_create);
     g_test_add_func("/systemd/sd-event", test_sd_event);
 
     return g_test_run();