summary refs log tree commit diff
path: root/src/core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/tests')
-rw-r--r--src/core/tests/config/test-config.c100
-rw-r--r--src/core/tests/meson.build14
-rw-r--r--src/core/tests/test-core-with-expect.c7
-rw-r--r--src/core/tests/test-core.c30
-rw-r--r--src/core/tests/test-ip4-config.c2
-rw-r--r--src/core/tests/test-ip6-config.c2
-rw-r--r--src/core/tests/test-l3cfg.c12
-rw-r--r--src/core/tests/test-systemd.c130
8 files changed, 128 insertions, 169 deletions
diff --git a/src/core/tests/config/test-config.c b/src/core/tests/config/test-config.c
index 3bb14815..6794fbf6 100644
--- a/src/core/tests/config/test-config.c
+++ b/src/core/tests/config/test-config.c
@@ -151,6 +151,7 @@ test_config_simple(void)
     gs_unref_object NMConfig *config  = NULL;
     gs_strfreev char **       plugins = NULL;
     char *                    value;
+    const char *              cvalue;
     gs_unref_object NMDevice *dev50 = nm_test_device_new("00:00:00:00:00:50");
     gs_unref_object NMDevice *dev51 = nm_test_device_new("00:00:00:00:00:51");
     gs_unref_object NMDevice *dev52 = nm_test_device_new("00:00:00:00:00:52");
@@ -206,59 +207,50 @@ test_config_simple(void)
     g_assert_cmpstr(value, ==, "51");
     g_free(value);
 
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ipv6.route-metric",
-                                                  NULL);
-    g_assert_cmpstr(value, ==, NULL);
-    g_free(value);
-
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ipv4.route-metric",
-                                                  NULL);
-    g_assert_cmpstr(value, ==, "50");
-    g_free(value);
-
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ipv4.route-metric",
-                                                  dev50);
-    g_assert_cmpstr(value, ==, "50");
-    g_free(value);
-
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ipv4.route-metric",
-                                                  dev51);
-    g_assert_cmpstr(value, ==, "51");
-    g_free(value);
-
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ipv4.route-metric",
-                                                  dev52);
-    g_assert_cmpstr(value, ==, "52");
-    g_free(value);
-
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ethernet.mtu",
-                                                  dev51);
-    g_assert_cmpstr(value, ==, "9000");
-    g_free(value);
-
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ethernet.mtu",
-                                                  dev50);
-    g_assert_cmpstr(value, ==, "1400");
-    g_free(value);
-
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ipv4.dns-priority",
-                                                  dev51);
-    g_assert_cmpstr(value, ==, NULL);
-    g_free(value);
-
-    value = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
-                                                  "ipv4.dns-priority",
-                                                  dev50);
-    g_assert_cmpstr(value, ==, "60");
-    g_free(value);
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ipv6.route-metric",
+                                                   NULL);
+    g_assert_cmpstr(cvalue, ==, NULL);
+
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ipv4.route-metric",
+                                                   NULL);
+    g_assert_cmpstr(cvalue, ==, "50");
+
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ipv4.route-metric",
+                                                   dev50);
+    g_assert_cmpstr(cvalue, ==, "50");
+
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ipv4.route-metric",
+                                                   dev51);
+    g_assert_cmpstr(cvalue, ==, "51");
+
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ipv4.route-metric",
+                                                   dev52);
+    g_assert_cmpstr(cvalue, ==, "52");
+
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ethernet.mtu",
+                                                   dev51);
+    g_assert_cmpstr(cvalue, ==, "9000");
+
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ethernet.mtu",
+                                                   dev50);
+    g_assert_cmpstr(cvalue, ==, "1400");
+
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ipv4.dns-priority",
+                                                   dev51);
+    g_assert_cmpstr(cvalue, ==, NULL);
+
+    cvalue = nm_config_data_get_connection_default(nm_config_get_data_orig(config),
+                                                   "ipv4.dns-priority",
+                                                   dev50);
+    g_assert_cmpstr(cvalue, ==, "60");
 }
 
 static void
@@ -616,7 +608,7 @@ test_config_confdir(void)
 #define ASSERT_GET_CONN_DEFAULT(xconfig, xname, xvalue)                             \
     G_STMT_START                                                                    \
     {                                                                               \
-        gs_free char *_value =                                                      \
+        const char *_value =                                                        \
             nm_config_data_get_connection_default(nm_config_get_data_orig(xconfig), \
                                                   (xname),                          \
                                                   NULL);                            \
diff --git a/src/core/tests/meson.build b/src/core/tests/meson.build
index 994563c4..99fa0ae9 100644
--- a/src/core/tests/meson.build
+++ b/src/core/tests/meson.build
@@ -37,11 +37,17 @@ exe = executable(
     src_inc,
   ],
   dependencies: [
-    libnm_systemd_core_dep,
-    libnm_systemd_shared_dep,
+    libnm_systemd_shared_dep_inc,
+    libnm_systemd_core_dep_inc,
+    glib_dep,
   ],
-  c_args: [
-    '-DG_LOG_DOMAIN="test"',
+  link_with: [
+    libnm_systemd_shared,
+    libnm_systemd_core,
+    libnm_glib_aux,
+    libnm_log_null,
+    libnm_std_aux,
+    libc_siphash,
   ],
 )
 
diff --git a/src/core/tests/test-core-with-expect.c b/src/core/tests/test-core-with-expect.c
index 022cf8f3..01784863 100644
--- a/src/core/tests/test-core-with-expect.c
+++ b/src/core/tests/test-core-with-expect.c
@@ -11,6 +11,7 @@
 #include <fcntl.h>
 
 #include "NetworkManagerUtils.h"
+#include "libnm-platform/nm-platform-utils.h"
 
 #include "nm-test-utils-core.h"
 
@@ -586,7 +587,7 @@ test_nm_ethernet_address_is_valid(void)
 /*****************************************************************************/
 
 static void
-test_nm_utils_new_vlan_name(void)
+test_nmp_utils_new_vlan_name(void)
 {
     guint       i, j;
     const char *parent_names[] = {
@@ -614,7 +615,7 @@ test_nm_utils_new_vlan_name(void)
 
             vlan_id_s = g_strdup_printf(".%d", vlan_id);
 
-            ifname = nm_utils_new_vlan_name(parent_names[i], vlan_id);
+            ifname = nmp_utils_new_vlan_name(parent_names[i], vlan_id);
             g_assert(ifname && ifname[0]);
             g_assert_cmpint(strlen(ifname),
                             ==,
@@ -643,7 +644,7 @@ main(int argc, char **argv)
     g_test_add_func("/general/nm_utils_array_remove_at_indexes",
                     test_nm_utils_array_remove_at_indexes);
     g_test_add_func("/general/nm_ethernet_address_is_valid", test_nm_ethernet_address_is_valid);
-    g_test_add_func("/general/nm_utils_new_vlan_name", test_nm_utils_new_vlan_name);
+    g_test_add_func("/general/nmp_utils_new_vlan_name", test_nmp_utils_new_vlan_name);
 
     return g_test_run();
 }
diff --git a/src/core/tests/test-core.c b/src/core/tests/test-core.c
index 8698c406..f28c4178 100644
--- a/src/core/tests/test-core.c
+++ b/src/core/tests/test-core.c
@@ -11,16 +11,36 @@
 /* need math.h for isinf() and INFINITY. No need to link with -lm */
 #include <math.h>
 
+#include "libnm-glib-aux/nm-uuid.h"
 #include "NetworkManagerUtils.h"
-#include "nm-core-internal.h"
+#include "libnm-core-intern/nm-core-internal.h"
 #include "nm-core-utils.h"
-#include "systemd/nm-sd-utils-core.h"
+#include "libnm-systemd-core/nm-sd-utils-core.h"
 
 #include "dns/nm-dns-manager.h"
 #include "nm-connectivity.h"
 
 #include "nm-test-utils-core.h"
 
+/*****************************************************************************/
+
+static void
+test_config_h(void)
+{
+#define ABSOLUTE_PATH(path)                  \
+    G_STMT_START                             \
+    {                                        \
+        g_assert_cmpstr("" path "", !=, ""); \
+        g_assert("" path ""[0] == '/');      \
+    }                                        \
+    G_STMT_END
+
+    ABSOLUTE_PATH(IPTABLES_PATH);
+    ABSOLUTE_PATH(NFT_PATH);
+}
+
+/*****************************************************************************/
+
 /* Reference implementation for nm_utils_ip6_address_clear_host_address.
  * Taken originally from set_address_masked(), src/ndisc/nm-lndp-ndisc.c
  **/
@@ -867,7 +887,7 @@ test_connection_no_match_vlan(void)
     /* Check that the connections do not match if VLAN flags differ */
     s_vlan_orig = nm_connection_get_setting_vlan(orig);
     g_assert(s_vlan_orig);
-    g_object_set(G_OBJECT(s_vlan_orig), NM_SETTING_VLAN_FLAGS, NM_VLAN_FLAG_REORDER_HEADERS, NULL);
+    g_object_set(G_OBJECT(s_vlan_orig), NM_SETTING_VLAN_FLAGS, _NM_VLAN_FLAG_REORDER_HEADERS, NULL);
 
     s_vlan_copy = nm_connection_get_setting_vlan(copy);
     g_assert(s_vlan_copy);
@@ -2231,7 +2251,7 @@ test_utils_file_is_in_path(void)
     g_assert(!nm_utils_file_is_in_path("//b///a/", "/b//"));
     g_assert(!nm_utils_file_is_in_path("//b///a/", "/b/a/"));
     g_assert(!nm_utils_file_is_in_path("//b///a", "/b/a/"));
-    g_assert(nm_utils_file_is_in_path("//b///a/.", "/b/a/"));
+    g_assert(!nm_utils_file_is_in_path("//b///a/.", "/b/a/"));
     g_assert(nm_utils_file_is_in_path("//b///a/..", "/b/a/"));
 }
 
@@ -2569,6 +2589,8 @@ main(int argc, char **argv)
 {
     nmtst_init_with_logging(&argc, &argv, NULL, "ALL");
 
+    g_test_add_func("/general/test_config_h", test_config_h);
+
     g_test_add_func("/general/test_logging_domains", test_logging_domains);
     g_test_add_func("/general/test_logging_error", test_logging_error);
 
diff --git a/src/core/tests/test-ip4-config.c b/src/core/tests/test-ip4-config.c
index 27b1d611..3a095d4a 100644
--- a/src/core/tests/test-ip4-config.c
+++ b/src/core/tests/test-ip4-config.c
@@ -8,7 +8,7 @@
 #include <arpa/inet.h>
 
 #include "nm-ip4-config.h"
-#include "platform/nm-platform.h"
+#include "libnm-platform/nm-platform.h"
 
 #include "nm-test-utils-core.h"
 
diff --git a/src/core/tests/test-ip6-config.c b/src/core/tests/test-ip6-config.c
index 3b48fb7f..ddf4c789 100644
--- a/src/core/tests/test-ip6-config.c
+++ b/src/core/tests/test-ip6-config.c
@@ -10,7 +10,7 @@
 
 #include "nm-ip6-config.h"
 
-#include "platform/nm-platform.h"
+#include "libnm-platform/nm-platform.h"
 #include "nm-test-utils-core.h"
 
 static NMIP6Config *
diff --git a/src/core/tests/test-l3cfg.c b/src/core/tests/test-l3cfg.c
index 43132c6d..ba065c09 100644
--- a/src/core/tests/test-l3cfg.c
+++ b/src/core/tests/test-l3cfg.c
@@ -5,7 +5,7 @@
 #include "nm-l3cfg.h"
 #include "nm-l3-ipv4ll.h"
 #include "nm-netns.h"
-#include "platform/nm-platform.h"
+#include "libnm-platform/nm-platform.h"
 
 #include "platform/tests/test-common.h"
 
@@ -82,8 +82,8 @@ _test_fixture_1_setup(TestFixture1 *f, int test_idx)
     f->hwaddr0 = l0->l_address;
     f->hwaddr1 = l1->l_address;
 
-    g_assert(nm_platform_link_set_up(f->platform, f->ifindex0, NULL));
-    g_assert(nm_platform_link_set_up(f->platform, f->ifindex1, NULL));
+    g_assert(nm_platform_link_change_flags(f->platform, f->ifindex0, IFF_UP, TRUE) >= 0);
+    g_assert(nm_platform_link_change_flags(f->platform, f->ifindex1, IFF_UP, TRUE) >= 0);
 
     return f;
 }
@@ -187,6 +187,12 @@ _test_l3cfg_signal_notify(NML3Cfg *                   l3cfg,
             nm_assert(NM_IS_L3_CONFIG_DATA(ti->l3cd));
             nm_assert(ti->tag);
         }
+    } else if (notify_data->notify_type == NM_L3_CONFIG_NOTIFY_TYPE_L3CD_CHANGED) {
+        g_assert(!notify_data->l3cd_changed.l3cd_old
+                 || NM_IS_L3_CONFIG_DATA(notify_data->l3cd_changed.l3cd_old));
+        g_assert(!notify_data->l3cd_changed.l3cd_new
+                 || NM_IS_L3_CONFIG_DATA(notify_data->l3cd_changed.l3cd_new));
+        return;
     }
 
     switch (tdata->notify_type) {
diff --git a/src/core/tests/test-systemd.c b/src/core/tests/test-systemd.c
index fa510366..12d2b911 100644
--- a/src/core/tests/test-systemd.c
+++ b/src/core/tests/test-systemd.c
@@ -3,68 +3,12 @@
  * Copyright (C) 2016 Red Hat, Inc.
  */
 
-#include "src/core/systemd/nm-default-systemd.h"
+#include "libnm-systemd-core/nm-default-systemd-core.h"
 
-#include "systemd/nm-sd.h"
-#include "systemd/nm-sd-utils-shared.h"
+#include "libnm-systemd-core/nm-sd.h"
+#include "libnm-systemd-shared/nm-sd-utils-shared.h"
 
-#include "nm-test-utils-core.h"
-
-/*****************************************************************************
- * Stub implementations of libNetworkManagerBase symbols
- *****************************************************************************/
-
-gboolean
-nm_utils_get_testing_initialized(void)
-{
-    return TRUE;
-}
-
-void
-_nm_utils_set_testing(NMUtilsTestFlags flags)
-{
-    g_assert_not_reached();
-}
-
-gint32
-nm_utils_get_monotonic_timestamp_sec(void)
-{
-    return 1;
-}
-
-NMLogDomain _nm_logging_enabled_state[_LOGL_N_REAL];
-
-gboolean
-_nm_log_enabled_impl(gboolean mt_require_locking, NMLogLevel level, NMLogDomain domain)
-{
-    return FALSE;
-}
-
-void
-_nm_log_impl(const char *file,
-             guint       line,
-             const char *func,
-             gboolean    mt_require_locking,
-             NMLogLevel  level,
-             NMLogDomain domain,
-             int         error,
-             const char *ifname,
-             const char *con_uuid,
-             const char *fmt,
-             ...)
-{}
-
-gboolean
-nm_logging_setup(const char *level, const char *domains, char **bad_domains, GError **error)
-{
-    return TRUE;
-}
-
-const char *
-nm_strerror_native(int errsv)
-{
-    return g_strerror(errsv);
-}
+#include "libnm-glib-aux/nm-test-utils.h"
 
 /*****************************************************************************/
 
@@ -178,46 +122,34 @@ test_sd_event(void)
 static void
 test_path_equal(void)
 {
-#define _path_equal_check1(path, kill_dots, expected)                                  \
-    G_STMT_START                                                                       \
-    {                                                                                  \
-        const gboolean _kill_dots = (kill_dots);                                       \
-        const char *   _path0     = (path);                                            \
-        const char *   _expected  = (expected);                                        \
-        gs_free char * _path      = g_strdup(_path0);                                  \
-        const char *   _path_result;                                                   \
-                                                                                       \
-        if (!_kill_dots && !nm_sd_utils_path_equal(_path0, _expected))                 \
-            g_error("Paths \"%s\" and \"%s\" don't compare equal", _path0, _expected); \
-                                                                                       \
-        _path_result = nm_sd_utils_path_simplify(_path, _kill_dots);                   \
-        g_assert(_path_result == _path);                                               \
-        g_assert_cmpstr(_path, ==, _expected);                                         \
-    }                                                                                  \
-    G_STMT_END
-
-#define _path_equal_check(path, expected_no_kill_dots, expected_kill_dots)           \
-    G_STMT_START                                                                     \
-    {                                                                                \
-        _path_equal_check1(path, FALSE, expected_no_kill_dots);                      \
-        _path_equal_check1(path, TRUE, expected_kill_dots ?: expected_no_kill_dots); \
-    }                                                                                \
+#define _path_equal_check(path, expected)                \
+    G_STMT_START                                         \
+    {                                                    \
+        const char *  _path0    = (path);                \
+        const char *  _expected = (expected);            \
+        gs_free char *_path     = g_strdup(_path0);      \
+        const char *  _path_result;                      \
+                                                         \
+        _path_result = nm_sd_utils_path_simplify(_path); \
+        g_assert(_path_result == _path);                 \
+        g_assert_cmpstr(_path, ==, _expected);           \
+    }                                                    \
     G_STMT_END
 
-    _path_equal_check("", "", NULL);
-    _path_equal_check(".", ".", NULL);
-    _path_equal_check("..", "..", NULL);
-    _path_equal_check("/..", "/..", NULL);
-    _path_equal_check("//..", "/..", NULL);
-    _path_equal_check("/.", "/.", "/");
-    _path_equal_check("./", ".", ".");
-    _path_equal_check("./.", "./.", ".");
-    _path_equal_check(".///.", "./.", ".");
-    _path_equal_check(".///./", "./.", ".");
-    _path_equal_check(".////", ".", ".");
-    _path_equal_check("//..//foo/", "/../foo", NULL);
-    _path_equal_check("///foo//./bar/.", "/foo/./bar/.", "/foo/bar");
-    _path_equal_check(".//./foo//./bar/.", "././foo/./bar/.", "foo/bar");
+    _path_equal_check("", "");
+    _path_equal_check(".", ".");
+    _path_equal_check("..", "..");
+    _path_equal_check("/..", "/..");
+    _path_equal_check("//..", "/..");
+    _path_equal_check("/.", "/");
+    _path_equal_check("./", ".");
+    _path_equal_check("./.", ".");
+    _path_equal_check(".///.", ".");
+    _path_equal_check(".///./", ".");
+    _path_equal_check(".////", ".");
+    _path_equal_check("//..//foo/", "/../foo");
+    _path_equal_check("///foo//./bar/.", "/foo/bar");
+    _path_equal_check(".//./foo//./bar/.", "foo/bar");
 }
 
 /*****************************************************************************/
@@ -327,7 +259,7 @@ NMTST_DEFINE();
 int
 main(int argc, char **argv)
 {
-    nmtst_init_assert_logging(&argc, &argv, "INFO", "ALL");
+    nmtst_init(&argc, &argv, TRUE);
 
     g_test_add_func("/systemd/dhcp/create", test_dhcp_create);
     g_test_add_func("/systemd/lldp/create", test_lldp_create);