From 45951bca506dbbcce2d495257b18da3c630b85ac Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 20 Dec 2015 21:38:32 +0100 Subject: [PATCH 01/20] build: separate compilation macro for libnm-util and libnm-glib Set different defines for building libnm and legacy libnm-glib. --- include/nm-default.h | 5 +++-- libnm-glib/Makefile.am | 2 +- libnm-util/Makefile.am | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/nm-default.h b/include/nm-default.h index 70069a92e8..045ad8db88 100644 --- a/include/nm-default.h +++ b/include/nm-default.h @@ -28,6 +28,7 @@ #define NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON 0x0002 #define NM_NETWORKMANAGER_COMPILATION_LIB 0x0004 #define NM_NETWORKMANAGER_COMPILATION_SYSTEMD 0x0008 +#define NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY 0x0010 #ifndef NETWORKMANAGER_COMPILATION /* For convenience, we don't require our Makefile.am to define @@ -46,7 +47,7 @@ /*****************************************************************************/ -#if (NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) || ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) #include @@ -54,7 +55,7 @@ #include -#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ +#endif /* NM_NETWORKMANAGER_COMPILATION_LIB || NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */ /*****************************************************************************/ diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am index 53d5669e85..7a815ee445 100644 --- a/libnm-glib/Makefile.am +++ b/libnm-glib/Makefile.am @@ -8,7 +8,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -DG_LOG_DOMAIN=\""libnm-glib"\" \ - -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(DBUS_CFLAGS) \ $(GLIB_CFLAGS) diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am index 29c83f09a1..4c08b9405a 100644 --- a/libnm-util/Makefile.am +++ b/libnm-util/Makefile.am @@ -8,7 +8,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/include \ -DG_LOG_DOMAIN=\""libnm-util"\" \ -DLOCALEDIR=\"$(datadir)/locale\" \ - -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ From 70713ee19770b3a0eac663bbc545be44d348ee0c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 20 Dec 2015 16:43:01 +0100 Subject: [PATCH 02/20] libnm/tests: unify common test code for libnm and libnm-glib Unify the common test code to drive the D-Bus stub service test-networkmanager-service.py. They will be merged in the next commit. --- libnm-glib/tests/Makefile.am | 1 + libnm-glib/tests/common.c | 119 ++++++++++++++++++++++++++++++++++- libnm-glib/tests/common.h | 18 ++++++ libnm/tests/Makefile.am | 2 +- libnm/tests/common.c | 4 ++ libnm/tests/common.h | 4 ++ 6 files changed, 146 insertions(+), 2 deletions(-) diff --git a/libnm-glib/tests/Makefile.am b/libnm-glib/tests/Makefile.am index aeaaa6b67c..931e243c0e 100644 --- a/libnm-glib/tests/Makefile.am +++ b/libnm-glib/tests/Makefile.am @@ -6,6 +6,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -I$(top_srcdir)/libnm-glib \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DTEST_NM_SERVICE=\"$(abs_top_srcdir)/tools/test-networkmanager-service.py\" \ $(GLIB_CFLAGS) \ diff --git a/libnm-glib/tests/common.c b/libnm-glib/tests/common.c index 9e3b002cfc..9b71afb391 100644 --- a/libnm-glib/tests/common.c +++ b/libnm-glib/tests/common.c @@ -20,11 +20,11 @@ #include "config.h" -#include #include #include "nm-default.h" #include "NetworkManager.h" +#include "nm-dbus-compat.h" #include "common.h" @@ -119,3 +119,120 @@ nm_test_service_cleanup (NMTestServiceInfo *info) memset (info, 0, sizeof (*info)); g_free (info); } + +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) + +typedef struct { + GMainLoop *loop; + const char *ifname; + char *path; + NMDevice *device; +} AddDeviceInfo; + +static void +device_added_cb (NMClient *client, + NMDevice *device, + gpointer user_data) +{ + AddDeviceInfo *info = user_data; + + g_assert (device); + g_assert_cmpstr (nm_object_get_path (NM_OBJECT (device)), ==, info->path); + g_assert_cmpstr (nm_device_get_iface (device), ==, info->ifname); + + info->device = device; + g_main_loop_quit (info->loop); +} + +static gboolean +timeout (gpointer user_data) +{ + g_assert_not_reached (); + return G_SOURCE_REMOVE; +} + +static GVariant * +call_add_wired_device (GDBusProxy *proxy, const char *ifname, const char *hwaddr, + const char **subchannels, GError **error) +{ + const char *empty[] = { NULL }; + + if (!hwaddr) + hwaddr = "/"; + if (!subchannels) + subchannels = empty; + + return g_dbus_proxy_call_sync (proxy, + "AddWiredDevice", + g_variant_new ("(ss^as)", ifname, hwaddr, subchannels), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 3000, + NULL, + error); +} + +static GVariant * +call_add_device (GDBusProxy *proxy, const char *method, const char *ifname, GError **error) +{ + return g_dbus_proxy_call_sync (proxy, + method, + g_variant_new ("(s)", ifname), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 3000, + NULL, + error); +} + +static NMDevice * +add_device_common (NMTestServiceInfo *sinfo, NMClient *client, + const char *method, const char *ifname, + const char *hwaddr, const char **subchannels) +{ + AddDeviceInfo info; + GError *error = NULL; + GVariant *ret; + guint timeout_id; + + if (g_strcmp0 (method, "AddWiredDevice") == 0) + ret = call_add_wired_device (sinfo->proxy, ifname, hwaddr, subchannels, &error); + else + ret = call_add_device (sinfo->proxy, method, ifname, &error); + + g_assert_no_error (error); + g_assert (ret); + g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); + g_variant_get (ret, "(o)", &info.path); + g_variant_unref (ret); + + /* Wait for libnm to find the device */ + info.ifname = ifname; + info.loop = g_main_loop_new (NULL, FALSE); + g_signal_connect (client, "device-added", + G_CALLBACK (device_added_cb), &info); + timeout_id = g_timeout_add_seconds (5, timeout, NULL); + g_main_loop_run (info.loop); + + g_source_remove (timeout_id); + g_signal_handlers_disconnect_by_func (client, device_added_cb, &info); + g_free (info.path); + g_main_loop_unref (info.loop); + + return info.device; +} + +NMDevice * +nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client, + const char *method, const char *ifname) +{ + return add_device_common (sinfo, client, method, ifname, NULL, NULL); +} + +NMDevice * +nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, NMClient *client, + const char *ifname, const char *hwaddr, + const char **subchannels) +{ + return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels); +} + +#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ diff --git a/libnm-glib/tests/common.h b/libnm-glib/tests/common.h index 5ffd955c49..7ac61bb392 100644 --- a/libnm-glib/tests/common.h +++ b/libnm-glib/tests/common.h @@ -18,6 +18,8 @@ * Copyright 2014 Red Hat, Inc. */ +#include + #include "nm-default.h" typedef struct { @@ -29,3 +31,19 @@ typedef struct { NMTestServiceInfo *nm_test_service_init (void); void nm_test_service_cleanup (NMTestServiceInfo *info); + +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) + +NMDevice *nm_test_service_add_device (NMTestServiceInfo *info, + NMClient *client, + const char *method, + const char *ifname); + +NMDevice * nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, + NMClient *client, + const char *ifname, + const char *hwaddr, + const char **subchannels); + +#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ + diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index 0acbae8fe3..0c3bfda0cf 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -7,7 +7,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/libnm \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ - -DNETWORKMANAGER_COMPILATION \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DTEST_NM_SERVICE=\"$(abs_top_srcdir)/tools/test-networkmanager-service.py\" \ $(GLIB_CFLAGS) diff --git a/libnm/tests/common.c b/libnm/tests/common.c index 5b3f74eb27..9b71afb391 100644 --- a/libnm/tests/common.c +++ b/libnm/tests/common.c @@ -120,6 +120,8 @@ nm_test_service_cleanup (NMTestServiceInfo *info) g_free (info); } +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) + typedef struct { GMainLoop *loop; const char *ifname; @@ -232,3 +234,5 @@ nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, NMClient *client, { return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels); } + +#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ diff --git a/libnm/tests/common.h b/libnm/tests/common.h index 501ea16c4e..7ac61bb392 100644 --- a/libnm/tests/common.h +++ b/libnm/tests/common.h @@ -32,6 +32,8 @@ typedef struct { NMTestServiceInfo *nm_test_service_init (void); void nm_test_service_cleanup (NMTestServiceInfo *info); +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) + NMDevice *nm_test_service_add_device (NMTestServiceInfo *info, NMClient *client, const char *method, @@ -43,3 +45,5 @@ NMDevice * nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, const char *hwaddr, const char **subchannels); +#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ + From fa3093e16721b1617b6e5fcb2cd36c5eff13e2eb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 20 Dec 2015 21:59:13 +0100 Subject: [PATCH 03/20] libnm/tests: move common testing code to nm-test-libnm-utils The unit tests for libnm and libnm-glib use a NetworkManager stub service written in Python (test-networkmanager-service.py). As they share the same server, it makes sense to also share the same utility code to drive the stub. Move the common code to include/. Note that contrary to "nm-test-utils.h", "nm-test-libnm-utils.h" is not a header-only file. Instead its implementation is in "nm-test-utils-impl.c". The reason for that this split is, if we later have yet another non-header-only test-utility, then all the implementations are in "nm-test-utils-impl.c", requiring the tests to link only one object file. --- .../common.h => include/nm-test-libnm-utils.h | 2 + .../common.c => include/nm-test-utils-impl.c | 4 +- libnm-glib/tests/Makefile.am | 8 +- libnm-glib/tests/test-nm-client.c | 2 +- .../tests/test-remote-settings-client.c | 2 +- libnm/tests/Makefile.am | 12 +- libnm/tests/common.c | 238 ------------------ libnm/tests/common.h | 49 ---- libnm/tests/test-nm-client.c | 2 +- libnm/tests/test-remote-settings-client.c | 2 +- libnm/tests/test-secret-agent.c | 2 +- 11 files changed, 19 insertions(+), 304 deletions(-) rename libnm-glib/tests/common.h => include/nm-test-libnm-utils.h (98%) rename libnm-glib/tests/common.c => include/nm-test-utils-impl.c (99%) delete mode 100644 libnm/tests/common.c delete mode 100644 libnm/tests/common.h diff --git a/libnm-glib/tests/common.h b/include/nm-test-libnm-utils.h similarity index 98% rename from libnm-glib/tests/common.h rename to include/nm-test-libnm-utils.h index 7ac61bb392..b3dfd45a56 100644 --- a/libnm-glib/tests/common.h +++ b/include/nm-test-libnm-utils.h @@ -22,6 +22,8 @@ #include "nm-default.h" +#include "nm-test-utils.h" + typedef struct { GDBusConnection *bus; GDBusProxy *proxy; diff --git a/libnm-glib/tests/common.c b/include/nm-test-utils-impl.c similarity index 99% rename from libnm-glib/tests/common.c rename to include/nm-test-utils-impl.c index 9b71afb391..6c4ed83916 100644 --- a/libnm-glib/tests/common.c +++ b/include/nm-test-utils-impl.c @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2010 - 2014 Red Hat, Inc. + * Copyright 2010 - 2015 Red Hat, Inc. * */ @@ -26,7 +26,7 @@ #include "NetworkManager.h" #include "nm-dbus-compat.h" -#include "common.h" +#include "nm-test-libnm-utils.h" static gboolean name_exists (GDBusConnection *c, const char *name) diff --git a/libnm-glib/tests/Makefile.am b/libnm-glib/tests/Makefile.am index 931e243c0e..9afbf6f566 100644 --- a/libnm-glib/tests/Makefile.am +++ b/libnm-glib/tests/Makefile.am @@ -24,8 +24,8 @@ TESTS = test-nm-client test-remote-settings-client ####### NMClient and non-settings tests ####### test_nm_client_SOURCES = \ - common.c \ - common.h \ + $(top_builddir)/include/nm-test-utils-impl.c \ + $(top_builddir)/include/nm-test-libnm-utils.h \ test-nm-client.c test_nm_client_LDADD = \ @@ -37,8 +37,8 @@ test_nm_client_LDADD = \ ####### remote settings client test ####### test_remote_settings_client_SOURCES = \ - common.c \ - common.h \ + $(top_builddir)/include/nm-test-utils-impl.c \ + $(top_builddir)/include/nm-test-libnm-utils.h \ test-remote-settings-client.c test_remote_settings_client_LDADD = \ diff --git a/libnm-glib/tests/test-nm-client.c b/libnm-glib/tests/test-nm-client.c index 2c721f94df..417eca79f9 100644 --- a/libnm-glib/tests/test-nm-client.c +++ b/libnm-glib/tests/test-nm-client.c @@ -36,7 +36,7 @@ #include "nm-test-utils.h" -#include "common.h" +#include "nm-test-libnm-utils.h" static GMainLoop *loop = NULL; static NMTestServiceInfo *sinfo; diff --git a/libnm-glib/tests/test-remote-settings-client.c b/libnm-glib/tests/test-remote-settings-client.c index 831c1beef5..99d326f43b 100644 --- a/libnm-glib/tests/test-remote-settings-client.c +++ b/libnm-glib/tests/test-remote-settings-client.c @@ -35,7 +35,7 @@ #include "nm-default.h" #include "nm-remote-settings.h" -#include "common.h" +#include "nm-test-libnm-utils.h" #include "nm-test-utils.h" diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index 0c3bfda0cf..99a4b8a66e 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -26,18 +26,18 @@ endif TESTS = test-nm-client test-remote-settings-client test-secret-agent test_nm_client_SOURCES = \ - common.c \ - common.h \ + $(top_builddir)/include/nm-test-utils-impl.c \ + $(top_builddir)/include/nm-test-libnm-utils.h \ test-nm-client.c test_remote_settings_client_SOURCES = \ - common.c \ - common.h \ + $(top_builddir)/include/nm-test-utils-impl.c \ + $(top_builddir)/include/nm-test-libnm-utils.h \ test-remote-settings-client.c test_secret_agent_SOURCES = \ - common.c \ - common.h \ + $(top_builddir)/include/nm-test-utils-impl.c \ + $(top_builddir)/include/nm-test-libnm-utils.h \ test-secret-agent.c endif diff --git a/libnm/tests/common.c b/libnm/tests/common.c deleted file mode 100644 index 9b71afb391..0000000000 --- a/libnm/tests/common.c +++ /dev/null @@ -1,238 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2010 - 2014 Red Hat, Inc. - * - */ - -#include "config.h" - -#include - -#include "nm-default.h" -#include "NetworkManager.h" -#include "nm-dbus-compat.h" - -#include "common.h" - -static gboolean -name_exists (GDBusConnection *c, const char *name) -{ - GVariant *reply; - gboolean exists = FALSE; - - reply = g_dbus_connection_call_sync (c, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "GetNameOwner", - g_variant_new ("(s)", name), - NULL, - G_DBUS_CALL_FLAGS_NO_AUTO_START, - -1, - NULL, - NULL); - if (reply != NULL) { - exists = TRUE; - g_variant_unref (reply); - } - - return exists; -} - -NMTestServiceInfo * -nm_test_service_init (void) -{ - NMTestServiceInfo *info; - const char *args[2] = { TEST_NM_SERVICE, NULL }; - GError *error = NULL; - int i; - - info = g_malloc0 (sizeof (*info)); - - info->bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - g_assert_no_error (error); - - /* Spawn the test service. info->keepalive_fd will be a pipe to the service's - * stdin; if it closes, the service will exit immediately. We use this to - * make sure the service exits if the test program crashes. - */ - g_spawn_async_with_pipes (NULL, (char **) args, NULL, 0, NULL, NULL, - &info->pid, &info->keepalive_fd, NULL, NULL, &error); - g_assert_no_error (error); - - /* Wait until the service is registered on the bus */ - for (i = 1000; i > 0; i--) { - if (name_exists (info->bus, "org.freedesktop.NetworkManager")) - break; - g_usleep (G_USEC_PER_SEC / 50); - } - g_assert (i > 0); - - /* Grab a proxy to our fake NM service to trigger tests */ - info->proxy = g_dbus_proxy_new_sync (info->bus, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | - G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, - NM_DBUS_SERVICE, - NM_DBUS_PATH, - "org.freedesktop.NetworkManager.LibnmGlibTest", - NULL, &error); - g_assert_no_error (error); - - return info; -} - -void -nm_test_service_cleanup (NMTestServiceInfo *info) -{ - int i; - - g_object_unref (info->proxy); - kill (info->pid, SIGTERM); - - /* Wait until the bus notices the service is gone */ - for (i = 100; i > 0; i--) { - if (!name_exists (info->bus, "org.freedesktop.NetworkManager")) - break; - g_usleep (G_USEC_PER_SEC / 50); - } - g_assert (i > 0); - - g_object_unref (info->bus); - close (info->keepalive_fd); - - memset (info, 0, sizeof (*info)); - g_free (info); -} - -#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) - -typedef struct { - GMainLoop *loop; - const char *ifname; - char *path; - NMDevice *device; -} AddDeviceInfo; - -static void -device_added_cb (NMClient *client, - NMDevice *device, - gpointer user_data) -{ - AddDeviceInfo *info = user_data; - - g_assert (device); - g_assert_cmpstr (nm_object_get_path (NM_OBJECT (device)), ==, info->path); - g_assert_cmpstr (nm_device_get_iface (device), ==, info->ifname); - - info->device = device; - g_main_loop_quit (info->loop); -} - -static gboolean -timeout (gpointer user_data) -{ - g_assert_not_reached (); - return G_SOURCE_REMOVE; -} - -static GVariant * -call_add_wired_device (GDBusProxy *proxy, const char *ifname, const char *hwaddr, - const char **subchannels, GError **error) -{ - const char *empty[] = { NULL }; - - if (!hwaddr) - hwaddr = "/"; - if (!subchannels) - subchannels = empty; - - return g_dbus_proxy_call_sync (proxy, - "AddWiredDevice", - g_variant_new ("(ss^as)", ifname, hwaddr, subchannels), - G_DBUS_CALL_FLAGS_NO_AUTO_START, - 3000, - NULL, - error); -} - -static GVariant * -call_add_device (GDBusProxy *proxy, const char *method, const char *ifname, GError **error) -{ - return g_dbus_proxy_call_sync (proxy, - method, - g_variant_new ("(s)", ifname), - G_DBUS_CALL_FLAGS_NO_AUTO_START, - 3000, - NULL, - error); -} - -static NMDevice * -add_device_common (NMTestServiceInfo *sinfo, NMClient *client, - const char *method, const char *ifname, - const char *hwaddr, const char **subchannels) -{ - AddDeviceInfo info; - GError *error = NULL; - GVariant *ret; - guint timeout_id; - - if (g_strcmp0 (method, "AddWiredDevice") == 0) - ret = call_add_wired_device (sinfo->proxy, ifname, hwaddr, subchannels, &error); - else - ret = call_add_device (sinfo->proxy, method, ifname, &error); - - g_assert_no_error (error); - g_assert (ret); - g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); - g_variant_get (ret, "(o)", &info.path); - g_variant_unref (ret); - - /* Wait for libnm to find the device */ - info.ifname = ifname; - info.loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (client, "device-added", - G_CALLBACK (device_added_cb), &info); - timeout_id = g_timeout_add_seconds (5, timeout, NULL); - g_main_loop_run (info.loop); - - g_source_remove (timeout_id); - g_signal_handlers_disconnect_by_func (client, device_added_cb, &info); - g_free (info.path); - g_main_loop_unref (info.loop); - - return info.device; -} - -NMDevice * -nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client, - const char *method, const char *ifname) -{ - return add_device_common (sinfo, client, method, ifname, NULL, NULL); -} - -NMDevice * -nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, NMClient *client, - const char *ifname, const char *hwaddr, - const char **subchannels) -{ - return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels); -} - -#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ diff --git a/libnm/tests/common.h b/libnm/tests/common.h deleted file mode 100644 index 7ac61bb392..0000000000 --- a/libnm/tests/common.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * 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 2014 Red Hat, Inc. - */ - -#include - -#include "nm-default.h" - -typedef struct { - GDBusConnection *bus; - GDBusProxy *proxy; - GPid pid; - int keepalive_fd; -} NMTestServiceInfo; - -NMTestServiceInfo *nm_test_service_init (void); -void nm_test_service_cleanup (NMTestServiceInfo *info); - -#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) - -NMDevice *nm_test_service_add_device (NMTestServiceInfo *info, - NMClient *client, - const char *method, - const char *ifname); - -NMDevice * nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, - NMClient *client, - const char *ifname, - const char *hwaddr, - const char **subchannels); - -#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ - diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c index 9da5647147..f87add8842 100644 --- a/libnm/tests/test-nm-client.c +++ b/libnm/tests/test-nm-client.c @@ -27,7 +27,7 @@ #include #include "nm-default.h" -#include "common.h" +#include "nm-test-libnm-utils.h" #include "nm-test-utils.h" diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index 66fbf2bfbc..613287bca5 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -27,7 +27,7 @@ #include #include "nm-default.h" -#include "common.h" +#include "nm-test-libnm-utils.h" #include "nm-test-utils.h" diff --git a/libnm/tests/test-secret-agent.c b/libnm/tests/test-secret-agent.c index ed2e2dcb50..30650cace0 100644 --- a/libnm/tests/test-secret-agent.c +++ b/libnm/tests/test-secret-agent.c @@ -28,7 +28,7 @@ #include #include "nm-default.h" -#include "common.h" +#include "nm-test-libnm-utils.h" #include "nm-test-utils.h" From bc06dd9332f557fb1848b3c50a102e0d35ad9205 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 21 Dec 2015 10:22:33 +0100 Subject: [PATCH 04/20] libnm/tests: rename test functions to follow common pattern Like the test utility functions in nm-test-utils.h and platform's common.h, rename the helper functions to have a nmtst(c) prefix. --- include/nm-test-libnm-utils.h | 30 ++++---- include/nm-test-utils-impl.c | 32 ++++----- libnm-glib/tests/test-nm-client.c | 25 +++---- .../tests/test-remote-settings-client.c | 21 +++--- libnm/tests/test-nm-client.c | 71 +++++++++---------- libnm/tests/test-remote-settings-client.c | 11 +-- libnm/tests/test-secret-agent.c | 24 +++---- 7 files changed, 97 insertions(+), 117 deletions(-) diff --git a/include/nm-test-libnm-utils.h b/include/nm-test-libnm-utils.h index b3dfd45a56..667ba90db6 100644 --- a/include/nm-test-libnm-utils.h +++ b/include/nm-test-libnm-utils.h @@ -15,12 +15,10 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * Copyright 2014 Red Hat, Inc. + * Copyright 2014 - 2015 Red Hat, Inc. */ -#include - -#include "nm-default.h" +#include "NetworkManager.h" #include "nm-test-utils.h" @@ -29,23 +27,23 @@ typedef struct { GDBusProxy *proxy; GPid pid; int keepalive_fd; -} NMTestServiceInfo; +} NMTstcServiceInfo; -NMTestServiceInfo *nm_test_service_init (void); -void nm_test_service_cleanup (NMTestServiceInfo *info); +NMTstcServiceInfo *nmtstc_service_init (void); +void nmtstc_service_cleanup (NMTstcServiceInfo *info); #if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) -NMDevice *nm_test_service_add_device (NMTestServiceInfo *info, - NMClient *client, - const char *method, - const char *ifname); +NMDevice *nmtstc_service_add_device (NMTstcServiceInfo *info, + NMClient *client, + const char *method, + const char *ifname); -NMDevice * nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, - NMClient *client, - const char *ifname, - const char *hwaddr, - const char **subchannels); +NMDevice * nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, + NMClient *client, + const char *ifname, + const char *hwaddr, + const char **subchannels); #endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ diff --git a/include/nm-test-utils-impl.c b/include/nm-test-utils-impl.c index 6c4ed83916..dac07b90d4 100644 --- a/include/nm-test-utils-impl.c +++ b/include/nm-test-utils-impl.c @@ -53,10 +53,10 @@ name_exists (GDBusConnection *c, const char *name) return exists; } -NMTestServiceInfo * -nm_test_service_init (void) +NMTstcServiceInfo * +nmtstc_service_init (void) { - NMTestServiceInfo *info; + NMTstcServiceInfo *info; const char *args[2] = { TEST_NM_SERVICE, NULL }; GError *error = NULL; int i; @@ -98,7 +98,7 @@ nm_test_service_init (void) } void -nm_test_service_cleanup (NMTestServiceInfo *info) +nmtstc_service_cleanup (NMTstcServiceInfo *info) { int i; @@ -175,16 +175,16 @@ static GVariant * call_add_device (GDBusProxy *proxy, const char *method, const char *ifname, GError **error) { return g_dbus_proxy_call_sync (proxy, - method, - g_variant_new ("(s)", ifname), - G_DBUS_CALL_FLAGS_NO_AUTO_START, - 3000, - NULL, - error); + method, + g_variant_new ("(s)", ifname), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 3000, + NULL, + error); } static NMDevice * -add_device_common (NMTestServiceInfo *sinfo, NMClient *client, +add_device_common (NMTstcServiceInfo *sinfo, NMClient *client, const char *method, const char *ifname, const char *hwaddr, const char **subchannels) { @@ -221,16 +221,16 @@ add_device_common (NMTestServiceInfo *sinfo, NMClient *client, } NMDevice * -nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client, - const char *method, const char *ifname) +nmtstc_service_add_device (NMTstcServiceInfo *sinfo, NMClient *client, + const char *method, const char *ifname) { return add_device_common (sinfo, client, method, ifname, NULL, NULL); } NMDevice * -nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, NMClient *client, - const char *ifname, const char *hwaddr, - const char **subchannels) +nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, NMClient *client, + const char *ifname, const char *hwaddr, + const char **subchannels) { return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels); } diff --git a/libnm-glib/tests/test-nm-client.c b/libnm-glib/tests/test-nm-client.c index 417eca79f9..42248947b7 100644 --- a/libnm-glib/tests/test-nm-client.c +++ b/libnm-glib/tests/test-nm-client.c @@ -27,19 +27,16 @@ #include #include -#include #include "nm-default.h" #include "nm-client.h" #include "nm-device-wifi.h" #include "nm-device-ethernet.h" #include "nm-device-wimax.h" -#include "nm-test-utils.h" - #include "nm-test-libnm-utils.h" static GMainLoop *loop = NULL; -static NMTestServiceInfo *sinfo; +static NMTstcServiceInfo *sinfo; /*******************************************************************/ @@ -184,7 +181,7 @@ test_device_added (void) NMDevice *device; DeviceAddedInfo info = { loop, FALSE, FALSE, 0, 0 }; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = test_client_new (); devices = nm_client_get_devices (client); @@ -224,7 +221,7 @@ test_device_added (void) g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -341,7 +338,7 @@ test_wifi_ap_added_removed (void) GError *error = NULL; char *expected_path = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = test_client_new (); /*************************************/ @@ -447,7 +444,7 @@ test_wifi_ap_added_removed (void) g_free (expected_path); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -564,7 +561,7 @@ test_wimax_nsp_added_removed (void) GError *error = NULL; char *expected_path = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = test_client_new (); /*************************************/ @@ -670,7 +667,7 @@ test_wimax_nsp_added_removed (void) g_free (expected_path); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -749,7 +746,7 @@ test_devices_array (void) GError *error = NULL; GVariant *ret; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = test_client_new (); /*************************************/ @@ -833,7 +830,7 @@ test_devices_array (void) g_free (paths[2]); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -871,7 +868,7 @@ test_client_manager_running (void) g_clear_error (&error); /* Now start the test service. */ - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client2 = test_client_new (); /* client2 should know that NM is running, but the previously-created @@ -889,7 +886,7 @@ test_client_manager_running (void) g_source_remove (quit_id); /* And kill it */ - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); g_assert (nm_client_get_manager_running (client1)); diff --git a/libnm-glib/tests/test-remote-settings-client.c b/libnm-glib/tests/test-remote-settings-client.c index 99d326f43b..fbeb558e1e 100644 --- a/libnm-glib/tests/test-remote-settings-client.c +++ b/libnm-glib/tests/test-remote-settings-client.c @@ -27,19 +27,18 @@ #include #include -#include +#include "NetworkManager.h" -#include -#include -#include +#include "nm-setting-connection.h" +#include "nm-setting-wired.h" +#include "nm-utils.h" #include "nm-default.h" #include "nm-remote-settings.h" + #include "nm-test-libnm-utils.h" -#include "nm-test-utils.h" - -static NMTestServiceInfo *sinfo; +static NMTstcServiceInfo *sinfo; static NMRemoteSettings *settings = NULL; DBusGConnection *bus = NULL; NMRemoteConnection *remote = NULL; @@ -377,7 +376,7 @@ test_service_running (void) g_assert (running == TRUE); /* Now kill the test service. */ - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); settings2 = nm_remote_settings_new (bus); @@ -406,7 +405,7 @@ test_service_running (void) g_assert (running == FALSE); /* Now restart it */ - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); @@ -436,7 +435,7 @@ main (int argc, char **argv) bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); g_assert_no_error (error); - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); settings = nm_remote_settings_new (bus); g_assert (settings != NULL); @@ -452,7 +451,7 @@ main (int argc, char **argv) ret = g_test_run (); - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); g_object_unref (settings); dbus_g_connection_unref (bus); diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c index f87add8842..f2701ab33f 100644 --- a/libnm/tests/test-nm-client.c +++ b/libnm/tests/test-nm-client.c @@ -24,15 +24,10 @@ #include #include -#include - -#include "nm-default.h" #include "nm-test-libnm-utils.h" -#include "nm-test-utils.h" - static GMainLoop *loop = NULL; -static NMTestServiceInfo *sinfo; +static NMTstcServiceInfo *sinfo; /*******************************************************************/ @@ -74,7 +69,7 @@ test_device_added (void) gboolean notified = FALSE; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -87,7 +82,7 @@ test_device_added (void) ¬ified); /* Tell the test service to add a new device */ - nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); /* coverity[loop_condition] */ while (!notified) @@ -108,7 +103,7 @@ test_device_added (void) g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_SOFTWARE); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -166,7 +161,7 @@ test_device_added_signal_after_init (void) guint result = 0; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -184,7 +179,7 @@ test_device_added_signal_after_init (void) &result); /* Tell the test service to add a new device */ - nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); /* Ensure the 'device-added' signal doesn't show up before * the 'Devices' property change notification */ @@ -207,7 +202,7 @@ test_device_added_signal_after_init (void) g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -314,13 +309,13 @@ test_wifi_ap_added_removed (void) GError *error = NULL; char *expected_path = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); /*************************************/ /* Add the wifi device */ - wifi = (NMDeviceWifi *) nm_test_service_add_device (sinfo, client, "AddWifiDevice", "wlan0"); + wifi = (NMDeviceWifi *) nmtstc_service_add_device (sinfo, client, "AddWifiDevice", "wlan0"); g_assert (NM_IS_DEVICE_WIFI (wifi)); /*************************************/ @@ -406,7 +401,7 @@ test_wifi_ap_added_removed (void) g_free (expected_path); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -513,13 +508,13 @@ test_wimax_nsp_added_removed (void) GError *error = NULL; char *expected_path = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); /*************************************/ /* Add the wimax device */ - wimax = (NMDeviceWimax *) nm_test_service_add_device (sinfo, client, "AddWimaxDevice", "wmx0"); + wimax = (NMDeviceWimax *) nmtstc_service_add_device (sinfo, client, "AddWimaxDevice", "wmx0"); g_assert (NM_IS_DEVICE_WIMAX (wimax)); /*************************************/ @@ -605,7 +600,7 @@ test_wimax_nsp_added_removed (void) g_free (expected_path); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -689,7 +684,7 @@ test_devices_array (void) GError *error = NULL; GVariant *ret; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); /* Make sure that we test the async codepath in at least one test... */ nm_client_new_async (NULL, new_client_cb, &client); @@ -698,9 +693,9 @@ test_devices_array (void) /*************************************/ /* Add some devices */ - wlan0 = nm_test_service_add_device (sinfo, client,"AddWifiDevice", "wlan0"); - eth0 = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); - eth1 = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth1"); + wlan0 = nmtstc_service_add_device (sinfo, client,"AddWifiDevice", "wlan0"); + eth0 = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + eth1 = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth1"); /* Ensure the devices now exist */ devices = nm_client_get_devices (client); @@ -765,7 +760,7 @@ test_devices_array (void) g_assert (device == eth1); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -804,7 +799,7 @@ test_client_nm_running (void) g_clear_error (&error); /* Now start the test service. */ - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client2 = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -823,7 +818,7 @@ test_client_nm_running (void) g_source_remove (quit_id); /* And kill it */ - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); g_assert (nm_client_get_nm_running (client1)); @@ -937,12 +932,12 @@ test_active_connections (void) TestACInfo info = { loop, NULL, 0 }; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); /* Tell the test service to add a new device */ - device = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + device = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); conn = nmtst_create_minimal_connection ("test-ac", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); nm_client_add_and_activate_connection_async (client, conn, device, NULL, @@ -979,7 +974,7 @@ test_active_connections (void) assert_ac_and_device (client); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -1067,11 +1062,11 @@ test_activate_virtual (void) TestConnectionInfo conn_info = { loop, NULL }; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); - nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); conn = nmtst_create_minimal_connection ("test-ac", NULL, NM_SETTING_VLAN_SETTING_NAME, &s_con); g_object_set (s_con, @@ -1112,7 +1107,7 @@ test_activate_virtual (void) g_object_unref (info.ac); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -1140,11 +1135,11 @@ test_activate_failed (void) NMConnection *conn; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); - device = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + device = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); /* Note that test-networkmanager-service.py checks for this exact name */ conn = nmtst_create_minimal_connection ("object-creation-failed-test", NULL, @@ -1157,7 +1152,7 @@ test_activate_failed (void) g_object_unref (conn); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -1174,13 +1169,13 @@ test_device_connection_compatibility (void) const char *hw_addr1 = "52:54:00:ab:db:23"; const char *hw_addr2 = "52:54:00:ab:db:24"; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); /* Create two devices */ - device1 = nm_test_service_add_wired_device (sinfo, client, "eth0", hw_addr1, subchannels); - device2 = nm_test_service_add_wired_device (sinfo, client, "eth1", hw_addr2, NULL); + device1 = nmtstc_service_add_wired_device (sinfo, client, "eth0", hw_addr1, subchannels); + device2 = nmtstc_service_add_wired_device (sinfo, client, "eth1", hw_addr2, NULL); g_assert_cmpstr (nm_device_get_hw_address (device1), ==, hw_addr1); g_assert_cmpstr (nm_device_get_hw_address (device2), ==, hw_addr2); @@ -1228,7 +1223,7 @@ test_device_connection_compatibility (void) g_object_unref (conn); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index 613287bca5..1a3c7988a2 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -24,14 +24,9 @@ #include #include -#include - -#include "nm-default.h" #include "nm-test-libnm-utils.h" -#include "nm-test-utils.h" - -static NMTestServiceInfo *sinfo; +static NMTstcServiceInfo *sinfo; static NMClient *client = NULL; GDBusConnection *bus = NULL; NMRemoteConnection *remote = NULL; @@ -517,7 +512,7 @@ main (int argc, char **argv) bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); g_assert_no_error (error); - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -536,7 +531,7 @@ main (int argc, char **argv) ret = g_test_run (); - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); g_object_unref (client); g_object_unref (bus); diff --git a/libnm/tests/test-secret-agent.c b/libnm/tests/test-secret-agent.c index 30650cace0..f8aedd2368 100644 --- a/libnm/tests/test-secret-agent.c +++ b/libnm/tests/test-secret-agent.c @@ -24,14 +24,10 @@ #include #include -#include #include -#include "nm-default.h" #include "nm-test-libnm-utils.h" -#include "nm-test-utils.h" - /*******************************************************************/ enum { @@ -183,7 +179,7 @@ test_secret_agent_new (void) /*******************************************************************/ typedef struct { - NMTestServiceInfo *sinfo; + NMTstcServiceInfo *sinfo; NMClient *client; NMSecretAgentOld *agent; @@ -250,7 +246,7 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data) NMSetting *s_wsec; GError *error = NULL; - sadata->sinfo = nm_test_service_init (); + sadata->sinfo = nmtstc_service_init (); sadata->client = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -262,8 +258,8 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data) counter++; /* Create the device */ - sadata->device = nm_test_service_add_device (sadata->sinfo, sadata->client, - "AddWifiDevice", sadata->ifname); + sadata->device = nmtstc_service_add_device (sadata->sinfo, sadata->client, + "AddWifiDevice", sadata->ifname); /* Create the connection */ connection = nmtst_create_minimal_connection (sadata->con_id, NULL, NM_SETTING_WIRELESS_SETTING_NAME, &s_con); @@ -336,7 +332,7 @@ test_cleanup (TestSecretAgentData *sadata, gconstpointer test_data) g_object_unref (sadata->connection); g_object_unref (sadata->client); - nm_test_service_cleanup (sadata->sinfo); + nmtstc_service_cleanup (sadata->sinfo); g_source_remove (sadata->timeout_id); g_main_loop_unref (sadata->loop); @@ -583,12 +579,12 @@ registered_changed (GObject *object, GParamSpec *pspec, gpointer user_data) static void test_secret_agent_auto_register (void) { - NMTestServiceInfo *sinfo; + NMTstcServiceInfo *sinfo; NMSecretAgentOld *agent; GMainLoop *loop; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); loop = g_main_loop_new (NULL, FALSE); agent = test_secret_agent_new (); @@ -604,17 +600,17 @@ test_secret_agent_auto_register (void) g_assert (nm_secret_agent_old_get_registered (agent)); /* Shut down test service */ - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); g_main_loop_run (loop); g_assert (!nm_secret_agent_old_get_registered (agent)); /* Restart test service */ - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); g_main_loop_run (loop); g_assert (nm_secret_agent_old_get_registered (agent)); /* Shut down test service again */ - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); g_main_loop_run (loop); g_assert (!nm_secret_agent_old_get_registered (agent)); From db80ec05abdc09541896d80bdf71ccec58670109 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Dec 2015 12:18:22 +0100 Subject: [PATCH 05/20] build: rename directory "include" to "shared" Up to now, the "include" directory contained (only) header files that were used project-wide by libs, core, clients, et al. Since the directory now also contains a non-header file, the "include" name is misleading. Instead of adding yet another directory that is project-wide, with non-header-only content, rename the "include" directory to "shared". --- .gitignore | 2 +- Makefile.am | 4 ++-- callouts/Makefile.am | 4 ++-- callouts/tests/Makefile.am | 4 ++-- clients/Makefile.am | 4 ++-- clients/cli/Makefile.am | 4 ++-- clients/tui/Makefile.am | 4 ++-- clients/tui/newt/Makefile.am | 4 ++-- configure.ac | 4 ++-- contrib/fedora/rpm/build_clean.sh | 2 +- docs/libnm-glib/Makefile.am | 4 ++-- examples/C/glib/Makefile.am | 4 ++-- libnm-core/Makefile.am | 4 ++-- libnm-core/Makefile.libnm-core | 2 +- libnm-core/tests/Makefile.am | 4 ++-- libnm-glib/Makefile.am | 4 ++-- libnm-glib/tests/Makefile.am | 12 ++++++------ libnm-util/Makefile.am | 6 +++--- libnm-util/tests/Makefile.am | 4 ++-- libnm/Makefile.am | 6 +++--- libnm/tests/Makefile.am | 16 ++++++++-------- {include => shared}/Makefile.am | 0 {include => shared}/gsystem-local-alloc.h | 0 {include => shared}/nm-dbus-compat.h | 0 {include => shared}/nm-default.h | 0 {include => shared}/nm-glib.h | 0 {include => shared}/nm-macros-internal.h | 0 {include => shared}/nm-test-libnm-utils.h | 0 {include => shared}/nm-test-utils-impl.c | 0 {include => shared}/nm-test-utils.h | 0 {include => shared}/nm-version-macros.h.in | 0 src/Makefile.am | 8 ++++---- src/devices/adsl/Makefile.am | 4 ++-- src/devices/bluetooth/Makefile.am | 4 ++-- src/devices/team/Makefile.am | 4 ++-- src/devices/tests/Makefile.am | 4 ++-- src/devices/wifi/Makefile.am | 4 ++-- src/devices/wifi/tests/Makefile.am | 4 ++-- src/devices/wwan/Makefile.am | 4 ++-- src/dhcp-manager/Makefile.am | 4 ++-- src/dhcp-manager/tests/Makefile.am | 4 ++-- src/dnsmasq-manager/tests/Makefile.am | 4 ++-- src/platform/tests/Makefile.am | 4 ++-- src/ppp-manager/Makefile.am | 4 ++-- src/rdisc/tests/Makefile.am | 4 ++-- src/settings/plugins/ibft/Makefile.am | 4 ++-- src/settings/plugins/ibft/tests/Makefile.am | 4 ++-- src/settings/plugins/ifcfg-rh/Makefile.am | 4 ++-- src/settings/plugins/ifcfg-rh/tests/Makefile.am | 4 ++-- src/settings/plugins/ifnet/Makefile.am | 4 ++-- src/settings/plugins/ifnet/tests/Makefile.am | 4 ++-- src/settings/plugins/ifupdown/Makefile.am | 4 ++-- src/settings/plugins/ifupdown/tests/Makefile.am | 4 ++-- src/settings/plugins/keyfile/Makefile.am | 4 ++-- src/settings/plugins/keyfile/tests/Makefile.am | 4 ++-- src/supplicant-manager/tests/Makefile.am | 4 ++-- src/tests/Makefile.am | 4 ++-- src/tests/config/Makefile.am | 4 ++-- 58 files changed, 107 insertions(+), 107 deletions(-) rename {include => shared}/Makefile.am (100%) rename {include => shared}/gsystem-local-alloc.h (100%) rename {include => shared}/nm-dbus-compat.h (100%) rename {include => shared}/nm-default.h (100%) rename {include => shared}/nm-glib.h (100%) rename {include => shared}/nm-macros-internal.h (100%) rename {include => shared}/nm-test-libnm-utils.h (100%) rename {include => shared}/nm-test-utils-impl.c (100%) rename {include => shared}/nm-test-utils.h (100%) rename {include => shared}/nm-version-macros.h.in (100%) diff --git a/.gitignore b/.gitignore index 6629338305..d6c22aebed 100644 --- a/.gitignore +++ b/.gitignore @@ -137,7 +137,7 @@ test-*.trs /examples/C/qt/list-connections /examples/C/qt/change-ipv4-addresses -/include/nm-version-macros.h +/shared/nm-version-macros.h /introspection/all.xml /introspection/nmdbus-*.c diff --git a/Makefile.am b/Makefile.am index 00e703cc1c..a79bddca3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ include $(GLIB_MAKEFILE) SUBDIRS = \ . \ - include \ + shared \ introspection \ libnm-core \ libnm \ @@ -67,6 +67,6 @@ pkgconfig_DATA = NetworkManager.pc CLEANFILES = cscope.in.out cscope.out cscope.po.out cscope: - cscope -b -q -R -Iinclude -ssrc -slibnm-core -slibnm -slibnm-glib -slibnm-util -sclients; + cscope -b -q -R -sshared -ssrc -slibnm-core -slibnm -slibnm-glib -slibnm-util -sclients; .PHONY: cscope diff --git a/callouts/Makefile.am b/callouts/Makefile.am index 3708aebbdf..6440a4de02 100644 --- a/callouts/Makefile.am +++ b/callouts/Makefile.am @@ -1,8 +1,8 @@ SUBDIRS = . tests AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I${top_builddir}/include \ + -I${top_srcdir}/shared \ + -I${top_builddir}/shared \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ $(GLIB_CFLAGS) \ diff --git a/callouts/tests/Makefile.am b/callouts/tests/Makefile.am index 30b73b17ca..ee3f647d37 100644 --- a/callouts/tests/Makefile.am +++ b/callouts/tests/Makefile.am @@ -1,8 +1,8 @@ if ENABLE_TESTS AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/callouts \ diff --git a/clients/Makefile.am b/clients/Makefile.am index 8316dcc0ed..9c30eea1b2 100644 --- a/clients/Makefile.am +++ b/clients/Makefile.am @@ -1,8 +1,8 @@ SUBDIRS = cli tui AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm \ diff --git a/clients/cli/Makefile.am b/clients/cli/Makefile.am index 192920e6e5..dfcb1e961a 100644 --- a/clients/cli/Makefile.am +++ b/clients/cli/Makefile.am @@ -6,8 +6,8 @@ bin_PROGRAMS = \ AM_CPPFLAGS = \ -I${top_srcdir} \ -I${top_builddir} \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm \ diff --git a/clients/tui/Makefile.am b/clients/tui/Makefile.am index 305f08b25d..ba2bbcd135 100644 --- a/clients/tui/Makefile.am +++ b/clients/tui/Makefile.am @@ -4,8 +4,8 @@ SUBDIRS = newt . AM_CPPFLAGS= \ -I$(top_srcdir) \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/libnm \ diff --git a/clients/tui/newt/Makefile.am b/clients/tui/newt/Makefile.am index 9413e96087..e07f9beff6 100644 --- a/clients/tui/newt/Makefile.am +++ b/clients/tui/newt/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS= \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""nmtui"\" \ diff --git a/configure.ac b/configure.ac index c2c48d2c6d..63f2db1aa0 100644 --- a/configure.ac +++ b/configure.ac @@ -1007,8 +1007,8 @@ AM_CONDITIONAL(SETTING_DOCS_AVAILABLE, test "$build_setting_docs" = "yes" -o "$h AC_CONFIG_FILES([ Makefile -include/Makefile -include/nm-version-macros.h +shared/Makefile +shared/nm-version-macros.h src/Makefile src/tests/Makefile src/tests/config/Makefile diff --git a/contrib/fedora/rpm/build_clean.sh b/contrib/fedora/rpm/build_clean.sh index b57b7099e8..8b098681c3 100755 --- a/contrib/fedora/rpm/build_clean.sh +++ b/contrib/fedora/rpm/build_clean.sh @@ -76,7 +76,7 @@ fi ./autogen.sh --enable-gtk-doc || die "Error autogen.sh" if [[ $QUICK == 1 ]]; then - make -C include || die "Error make -C include" + make -C shared || die "Error make -C shared" make -C introspection || die "Error make -C introspection" make -C libnm-core || die "Error make -C libnm-core" make -C libnm || die "Error make -C libnm" diff --git a/docs/libnm-glib/Makefile.am b/docs/libnm-glib/Makefile.am index 2d78856103..c38e6e3431 100644 --- a/docs/libnm-glib/Makefile.am +++ b/docs/libnm-glib/Makefile.am @@ -53,8 +53,8 @@ extra_files = libnm-glib.png # CFLAGS and LDFLAGS for compiling scan program. Only needed # if $(DOC_MODULE).types is non-empty. GTKDOC_CFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -I$(top_srcdir)/libnm-glib \ diff --git a/examples/C/glib/Makefile.am b/examples/C/glib/Makefile.am index 4b03d87f5e..3e442c30b1 100644 --- a/examples/C/glib/Makefile.am +++ b/examples/C/glib/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm \ diff --git a/libnm-core/Makefile.am b/libnm-core/Makefile.am index 55ed2f6ab6..527a1c2482 100644 --- a/libnm-core/Makefile.am +++ b/libnm-core/Makefile.am @@ -3,8 +3,8 @@ include $(GLIB_MAKEFILE) SUBDIRS = . tests AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I${top_builddir}/include \ + -I${top_srcdir}/shared \ + -I${top_builddir}/shared \ -DG_LOG_DOMAIN=\""libnm"\" \ -DLOCALEDIR=\"$(datadir)/locale\" \ -DNMCONFDIR=\"$(nmconfdir)\" \ diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core index df219295c4..fe8cc8a603 100644 --- a/libnm-core/Makefile.libnm-core +++ b/libnm-core/Makefile.libnm-core @@ -6,7 +6,7 @@ core = $(top_srcdir)/libnm-core core_build = $(top_builddir)/libnm-core libnm_core_headers = \ - $(top_builddir)/include/nm-version-macros.h \ + $(top_builddir)/shared/nm-version-macros.h \ $(core_build)/nm-core-enum-types.h \ $(core)/nm-connection.h \ $(core)/nm-core-types.h \ diff --git a/libnm-core/tests/Makefile.am b/libnm-core/tests/Makefile.am index 9949241abe..92c816fd84 100644 --- a/libnm-core/tests/Makefile.am +++ b/libnm-core/tests/Makefile.am @@ -12,8 +12,8 @@ if ENABLE_TESTS certsdir = $(srcdir)/certs AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I${top_builddir}/include \ + -I${top_srcdir}/shared \ + -I${top_builddir}/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DNETWORKMANAGER_COMPILATION \ diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am index 7a815ee445..676b067116 100644 --- a/libnm-glib/Makefile.am +++ b/libnm-glib/Makefile.am @@ -3,8 +3,8 @@ include $(GLIB_MAKEFILE) SUBDIRS = . tests AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -DG_LOG_DOMAIN=\""libnm-glib"\" \ diff --git a/libnm-glib/tests/Makefile.am b/libnm-glib/tests/Makefile.am index 9afbf6f566..a1b25f62f4 100644 --- a/libnm-glib/tests/Makefile.am +++ b/libnm-glib/tests/Makefile.am @@ -1,8 +1,8 @@ if ENABLE_TESTS AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -I$(top_srcdir)/libnm-glib \ @@ -24,8 +24,8 @@ TESTS = test-nm-client test-remote-settings-client ####### NMClient and non-settings tests ####### test_nm_client_SOURCES = \ - $(top_builddir)/include/nm-test-utils-impl.c \ - $(top_builddir)/include/nm-test-libnm-utils.h \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-nm-client.c test_nm_client_LDADD = \ @@ -37,8 +37,8 @@ test_nm_client_LDADD = \ ####### remote settings client test ####### test_remote_settings_client_SOURCES = \ - $(top_builddir)/include/nm-test-utils-impl.c \ - $(top_builddir)/include/nm-test-libnm-utils.h \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-remote-settings-client.c test_remote_settings_client_LDADD = \ diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am index 4c08b9405a..6e63790817 100644 --- a/libnm-util/Makefile.am +++ b/libnm-util/Makefile.am @@ -4,8 +4,8 @@ SUBDIRS = . tests AM_CPPFLAGS = \ -I${top_srcdir} \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -DG_LOG_DOMAIN=\""libnm-util"\" \ -DLOCALEDIR=\"$(datadir)/locale\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY \ @@ -25,7 +25,7 @@ endif lib_LTLIBRARIES=libnm-util.la libnm_util_include_HEADERS = \ - $(top_builddir)/include/nm-version-macros.h \ + $(top_builddir)/shared/nm-version-macros.h \ NetworkManager.h \ NetworkManagerVPN.h \ nm-connection.h \ diff --git a/libnm-util/tests/Makefile.am b/libnm-util/tests/Makefile.am index e580a13486..eda212ed87 100644 --- a/libnm-util/tests/Makefile.am +++ b/libnm-util/tests/Makefile.am @@ -1,8 +1,8 @@ if ENABLE_TESTS AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ diff --git a/libnm/Makefile.am b/libnm/Makefile.am index 253e109e21..80cdccb066 100644 --- a/libnm/Makefile.am +++ b/libnm/Makefile.am @@ -3,8 +3,8 @@ include $(GLIB_MAKEFILE) SUBDIRS = . tests AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_builddir)/introspection \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ @@ -26,7 +26,7 @@ lib_LTLIBRARIES = libnm.la libnmincludedir = $(includedir)/libnm libnminclude_hfiles = \ - $(top_builddir)/include/nm-version-macros.h \ + $(top_builddir)/shared/nm-version-macros.h \ NetworkManager.h \ nm-access-point.h \ nm-active-connection.h \ diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index 99a4b8a66e..ddcf50be80 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -1,8 +1,8 @@ if ENABLE_TESTS AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm \ -I$(top_builddir)/libnm \ -I$(top_srcdir)/libnm-core \ @@ -26,18 +26,18 @@ endif TESTS = test-nm-client test-remote-settings-client test-secret-agent test_nm_client_SOURCES = \ - $(top_builddir)/include/nm-test-utils-impl.c \ - $(top_builddir)/include/nm-test-libnm-utils.h \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-nm-client.c test_remote_settings_client_SOURCES = \ - $(top_builddir)/include/nm-test-utils-impl.c \ - $(top_builddir)/include/nm-test-libnm-utils.h \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-remote-settings-client.c test_secret_agent_SOURCES = \ - $(top_builddir)/include/nm-test-utils-impl.c \ - $(top_builddir)/include/nm-test-libnm-utils.h \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-secret-agent.c endif diff --git a/include/Makefile.am b/shared/Makefile.am similarity index 100% rename from include/Makefile.am rename to shared/Makefile.am diff --git a/include/gsystem-local-alloc.h b/shared/gsystem-local-alloc.h similarity index 100% rename from include/gsystem-local-alloc.h rename to shared/gsystem-local-alloc.h diff --git a/include/nm-dbus-compat.h b/shared/nm-dbus-compat.h similarity index 100% rename from include/nm-dbus-compat.h rename to shared/nm-dbus-compat.h diff --git a/include/nm-default.h b/shared/nm-default.h similarity index 100% rename from include/nm-default.h rename to shared/nm-default.h diff --git a/include/nm-glib.h b/shared/nm-glib.h similarity index 100% rename from include/nm-glib.h rename to shared/nm-glib.h diff --git a/include/nm-macros-internal.h b/shared/nm-macros-internal.h similarity index 100% rename from include/nm-macros-internal.h rename to shared/nm-macros-internal.h diff --git a/include/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h similarity index 100% rename from include/nm-test-libnm-utils.h rename to shared/nm-test-libnm-utils.h diff --git a/include/nm-test-utils-impl.c b/shared/nm-test-utils-impl.c similarity index 100% rename from include/nm-test-utils-impl.c rename to shared/nm-test-utils-impl.c diff --git a/include/nm-test-utils.h b/shared/nm-test-utils.h similarity index 100% rename from include/nm-test-utils.h rename to shared/nm-test-utils.h diff --git a/include/nm-version-macros.h.in b/shared/nm-version-macros.h.in similarity index 100% rename from include/nm-version-macros.h.in rename to shared/nm-version-macros.h.in diff --git a/src/Makefile.am b/src/Makefile.am index e4b2cb090c..c37b058ac5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,8 +33,8 @@ SUBDIRS += \ endif AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_builddir)/introspection \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ @@ -173,8 +173,8 @@ libsystemd_nm_la_SOURCES = \ systemd/src/systemd/sd-ndisc.h libsystemd_nm_la_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ $(SYSTEMD_NM_CFLAGS_PATHS) \ diff --git a/src/devices/adsl/Makefile.am b/src/devices/adsl/Makefile.am index b082ffc4ff..e7034fa873 100644 --- a/src/devices/adsl/Makefile.am +++ b/src/devices/adsl/Makefile.am @@ -8,8 +8,8 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/devices \ -I${top_srcdir}/src/platform \ -I${top_builddir}/introspection \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-adsl"\" \ diff --git a/src/devices/bluetooth/Makefile.am b/src/devices/bluetooth/Makefile.am index 37217dfac6..2054ea0f59 100644 --- a/src/devices/bluetooth/Makefile.am +++ b/src/devices/bluetooth/Makefile.am @@ -10,8 +10,8 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/platform \ -I${top_srcdir}/src/devices/wwan \ -I${top_builddir}/introspection \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-bluetooth"\" \ diff --git a/src/devices/team/Makefile.am b/src/devices/team/Makefile.am index 3df138609d..a66458337c 100644 --- a/src/devices/team/Makefile.am +++ b/src/devices/team/Makefile.am @@ -8,8 +8,8 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/devices \ -I${top_srcdir}/src/platform \ -I${top_builddir}/introspection \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-team"\" \ diff --git a/src/devices/tests/Makefile.am b/src/devices/tests/Makefile.am index 4b1595e7b4..330377b0b8 100644 --- a/src/devices/tests/Makefile.am +++ b/src/devices/tests/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src/platform \ diff --git a/src/devices/wifi/Makefile.am b/src/devices/wifi/Makefile.am index df21597d38..b0919ef710 100644 --- a/src/devices/wifi/Makefile.am +++ b/src/devices/wifi/Makefile.am @@ -14,8 +14,8 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/platform \ -I${top_srcdir}/src/supplicant-manager \ -I${top_builddir}/introspection \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ diff --git a/src/devices/wifi/tests/Makefile.am b/src/devices/wifi/tests/Makefile.am index 2e25dc422a..dee8e799b2 100644 --- a/src/devices/wifi/tests/Makefile.am +++ b/src/devices/wifi/tests/Makefile.am @@ -1,7 +1,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/introspection \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I${top_srcdir}/src/platform \ diff --git a/src/devices/wwan/Makefile.am b/src/devices/wwan/Makefile.am index 1d2dcb680b..107f630b3f 100644 --- a/src/devices/wwan/Makefile.am +++ b/src/devices/wwan/Makefile.am @@ -9,8 +9,8 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/settings \ -I${top_srcdir}/src/platform \ -I${top_builddir}/introspection \ - -I${top_srcdir}/include \ - -I$(top_builddir)/include \ + -I${top_srcdir}/shared \ + -I$(top_builddir)/shared \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-wwan"\" \ diff --git a/src/dhcp-manager/Makefile.am b/src/dhcp-manager/Makefile.am index b07bbc671f..3199ab0451 100644 --- a/src/dhcp-manager/Makefile.am +++ b/src/dhcp-manager/Makefile.am @@ -4,8 +4,8 @@ nm_dhcp_helper_SOURCES = nm-dhcp-helper.c nm_dhcp_helper_CPPFLAGS = \ $(GLIB_CFLAGS) \ - -I$(top_srcdir)/include \ - -I${top_builddir}/include \ + -I$(top_srcdir)/shared \ + -I${top_builddir}/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""nm-dhcp-helper"\" \ diff --git a/src/dhcp-manager/tests/Makefile.am b/src/dhcp-manager/tests/Makefile.am index 578f7144ac..5c7f9ba20e 100644 --- a/src/dhcp-manager/tests/Makefile.am +++ b/src/dhcp-manager/tests/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I${top_builddir}/include \ + -I$(top_srcdir)/shared \ + -I${top_builddir}/shared \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ -I$(top_srcdir)/src/dhcp-manager \ diff --git a/src/dnsmasq-manager/tests/Makefile.am b/src/dnsmasq-manager/tests/Makefile.am index 0ddaa381c1..2c5e8e4063 100644 --- a/src/dnsmasq-manager/tests/Makefile.am +++ b/src/dnsmasq-manager/tests/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I${top_builddir}/include \ + -I$(top_srcdir)/shared \ + -I${top_builddir}/shared \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ -I$(top_srcdir)/src/dnsmasq-manager \ diff --git a/src/platform/tests/Makefile.am b/src/platform/tests/Makefile.am index 5996f34706..b097fcf6b2 100644 --- a/src/platform/tests/Makefile.am +++ b/src/platform/tests/Makefile.am @@ -1,7 +1,7 @@ AM_CPPFLAGS = \ -I${top_srcdir} \ - -I${top_srcdir}/include \ - -I${top_builddir}/include \ + -I${top_srcdir}/shared \ + -I${top_builddir}/shared \ -I${top_srcdir}/src \ -I${top_builddir}/src \ -I${top_srcdir}/libnm-core \ diff --git a/src/ppp-manager/Makefile.am b/src/ppp-manager/Makefile.am index 650c4301f2..5cf908df70 100644 --- a/src/ppp-manager/Makefile.am +++ b/src/ppp-manager/Makefile.am @@ -1,8 +1,8 @@ if WITH_PPP AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I${top_builddir}/include \ + -I${top_srcdir}/shared \ + -I${top_builddir}/shared \ -I${top_srcdir}/libnm-core \ -I${top_srcdir}/src \ -I${top_builddir}/libnm-core \ diff --git a/src/rdisc/tests/Makefile.am b/src/rdisc/tests/Makefile.am index cf302ad6c7..d520e4164a 100644 --- a/src/rdisc/tests/Makefile.am +++ b/src/rdisc/tests/Makefile.am @@ -1,7 +1,7 @@ AM_CPPFLAGS = \ -I${top_srcdir} \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I${top_srcdir}/src \ -I${top_srcdir}/src/platform \ -I${top_srcdir}/libnm-core \ diff --git a/src/settings/plugins/ibft/Makefile.am b/src/settings/plugins/ibft/Makefile.am index 49d78311de..a994808d84 100644 --- a/src/settings/plugins/ibft/Makefile.am +++ b/src/settings/plugins/ibft/Makefile.am @@ -14,8 +14,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/ \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ diff --git a/src/settings/plugins/ibft/tests/Makefile.am b/src/settings/plugins/ibft/tests/Makefile.am index 3c3b5cf577..29881e852d 100644 --- a/src/settings/plugins/ibft/tests/Makefile.am +++ b/src/settings/plugins/ibft/tests/Makefile.am @@ -5,8 +5,8 @@ if ENABLE_TESTS AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src/ \ diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am index ebae6374e5..ab96a32852 100644 --- a/src/settings/plugins/ifcfg-rh/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/Makefile.am @@ -43,8 +43,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/ \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am index 4f942d2050..25d271976e 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am @@ -7,8 +7,8 @@ SUBDIRS=network-scripts AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src/ \ diff --git a/src/settings/plugins/ifnet/Makefile.am b/src/settings/plugins/ifnet/Makefile.am index 5e1713a147..ffd8ab3caf 100644 --- a/src/settings/plugins/ifnet/Makefile.am +++ b/src/settings/plugins/ifnet/Makefile.am @@ -6,8 +6,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am index 9c1bcbf62e..1919f1410a 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.am +++ b/src/settings/plugins/ifnet/tests/Makefile.am @@ -4,8 +4,8 @@ if ENABLE_TESTS AM_CPPFLAGS= \ -I$(srcdir)/../ \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src \ diff --git a/src/settings/plugins/ifupdown/Makefile.am b/src/settings/plugins/ifupdown/Makefile.am index b3ab2efdfc..c5c645d358 100644 --- a/src/settings/plugins/ifupdown/Makefile.am +++ b/src/settings/plugins/ifupdown/Makefile.am @@ -5,8 +5,8 @@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am index 55d9f88b2a..29e9a7ed5c 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.am +++ b/src/settings/plugins/ifupdown/tests/Makefile.am @@ -1,8 +1,8 @@ if ENABLE_TESTS AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src \ diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am index 1278b2fa3c..ddcd15b292 100644 --- a/src/settings/plugins/keyfile/Makefile.am +++ b/src/settings/plugins/keyfile/Makefile.am @@ -5,8 +5,8 @@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index 34331e15a8..4d85f09a40 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -5,8 +5,8 @@ SUBDIRS=keyfiles @GNOME_CODE_COVERAGE_RULES@ AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src \ diff --git a/src/supplicant-manager/tests/Makefile.am b/src/supplicant-manager/tests/Makefile.am index 66bd7d581d..9ac0387c4b 100644 --- a/src/supplicant-manager/tests/Makefile.am +++ b/src/supplicant-manager/tests/Makefile.am @@ -1,8 +1,8 @@ SUBDIRS=certs AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src \ diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 18fce10088..26c2ed7f55 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -1,8 +1,8 @@ SUBDIRS = config AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src/platform \ diff --git a/src/tests/config/Makefile.am b/src/tests/config/Makefile.am index 80f923c46e..5d4aed5c86 100644 --- a/src/tests/config/Makefile.am +++ b/src/tests/config/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src/ \ From c7d4d67d535d4db9c853b04b6ead34d6b1428a88 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 21 Dec 2015 10:54:08 +0100 Subject: [PATCH 06/20] include: remove trailing semicolon from _Pragma() call --- shared/nm-macros-internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h index b4d2d23c91..14430c4277 100644 --- a/shared/nm-macros-internal.h +++ b/shared/nm-macros-internal.h @@ -84,11 +84,11 @@ #if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #define NM_PRAGMA_WARNING_DISABLE(warning) \ - _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic push") \ _Pragma(_NM_PRAGMA_WARNING_DO(warning)) #elif defined (__clang__) #define NM_PRAGMA_WARNING_DISABLE(warning) \ - _Pragma("clang diagnostic push"); \ + _Pragma("clang diagnostic push") \ _Pragma(_NM_PRAGMA_WARNING_DO(warning)) #else #define NM_PRAGMA_WARNING_DISABLE(warning) From 766f31507b02c4721bdbabdc79755ff23652d6c6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 21 Dec 2015 14:16:35 +0100 Subject: [PATCH 07/20] nmtst: add nmtst_main_loop_run() --- shared/nm-test-utils.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h index 28ae56fee7..27a8d16422 100644 --- a/shared/nm-test-utils.h +++ b/shared/nm-test-utils.h @@ -733,6 +733,45 @@ nmtst_rand_perm (GRand *rand, void *dst, const void *src, gsize elmt_size, gsize return dst; } +/*****************************************************************************/ + +inline static gboolean +_nmtst_main_loop_run_timeout (gpointer user_data) +{ + GMainLoop **p_loop = user_data; + + g_assert (p_loop); + g_assert (*p_loop); + + g_main_loop_quit (*p_loop); + *p_loop = NULL; + + return G_SOURCE_REMOVE; +} + +inline static gboolean +nmtst_main_loop_run (GMainLoop *loop, int timeout_ms) +{ + GSource *source = NULL; + guint id = 0; + GMainLoop *loopx = loop; + + if (timeout_ms > 0) { + source = g_timeout_source_new (timeout_ms); + g_source_set_callback (source, _nmtst_main_loop_run_timeout, &loopx, NULL); + id = g_source_attach (source, g_main_loop_get_context (loop)); + g_assert (id); + g_source_unref (source); + } + + g_main_loop_run (loop); + + /* if the timeout was reached, return FALSE. */ + return loopx != NULL; +} + +/*****************************************************************************/ + inline static const char * nmtst_get_sudo_cmd (void) { From c2bafa61537ba3699d94f87f20fd93b9484950b4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Dec 2015 11:53:45 +0100 Subject: [PATCH 08/20] nmtst: add nmtst_find_all_indexes() --- shared/nm-test-utils.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h index 27a8d16422..31b24eac91 100644 --- a/shared/nm-test-utils.h +++ b/shared/nm-test-utils.h @@ -807,6 +807,49 @@ nmtst_reexec_sudo (void) g_error (">> exec %s failed: %d - %s", __nmtst_internal.sudo_cmd, errsv, strerror (errsv)); } +/*****************************************************************************/ + +inline static gsize +nmtst_find_all_indexes (gpointer *elements, + gsize n_elements, + gpointer *needles, + gsize n_needles, + gboolean (*equal_fcn) (gpointer element, gpointer needle, gpointer user_data), + gpointer user_data, + gssize *out_idx) +{ + gsize i, j, k; + gsize found = 0; + + for (i = 0; i < n_needles; i++) { + gssize idx = -1; + + for (j = 0; j < n_elements; j++) { + + /* no duplicates */ + for (k = 0; k < i; k++) { + if (out_idx[k] == j) + goto next; + } + + if (equal_fcn (elements[j], needles[i], user_data)) { + idx = j; + break; + } +next: + ; + } + + out_idx[i] = idx; + if (idx >= 0) + found++; + } + + return found; +} + +/*****************************************************************************/ + #define __define_nmtst_static(NUM,SIZE) \ inline static const char * \ nmtst_static_##SIZE##_##NUM (const char *str) \ From 9a11577e63153720cfcda71aeef4be9f35f84ab2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Dec 2015 14:02:44 +0100 Subject: [PATCH 09/20] nmtst: add nmtst_uuid_generate() --- shared/nm-test-utils.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h index 31b24eac91..81c1fde54a 100644 --- a/shared/nm-test-utils.h +++ b/shared/nm-test-utils.h @@ -868,6 +868,17 @@ __define_nmtst_static(02, 1024) __define_nmtst_static(03, 1024) #undef __define_nmtst_static +inline static const char * +nmtst_uuid_generate (void) +{ + static char u[37]; + gs_free char *m = NULL; + + m = nm_utils_uuid_generate (); + g_assert (m && strlen (m) == sizeof (u) - 1); + memcpy (u, m, sizeof (u)); + return u; +} #define NMTST_SWAP(x,y) \ G_STMT_START { \ From f354d5f0fcf1515cd484350e0ba9cea23d676f96 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Dec 2015 14:28:14 +0100 Subject: [PATCH 10/20] nmtst: enable connection utility functions for libnm-glib/libnm-utils library --- shared/nm-test-utils.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h index 81c1fde54a..0402201c28 100644 --- a/shared/nm-test-utils.h +++ b/shared/nm-test-utils.h @@ -1261,7 +1261,7 @@ nmtst_ip6_config_clone (NMIP6Config *config) #endif -#if defined(__NM_SIMPLE_CONNECTION_H__) && defined(__NM_SETTING_CONNECTION_H__) +#if (defined(__NM_SIMPLE_CONNECTION_H__) && defined(__NM_SETTING_CONNECTION_H__)) || (defined(NM_CONNECTION_H)) inline static NMConnection * nmtst_create_minimal_connection (const char *id, const char *uuid, const char *type, NMSettingConnection **out_s_con) @@ -1279,7 +1279,13 @@ nmtst_create_minimal_connection (const char *id, const char *uuid, const char *t uuid = uuid_free = nm_utils_uuid_generate (); if (type) { - GType type_g = nm_setting_lookup_type (type); + GType type_g; + +#if defined(__NM_SIMPLE_CONNECTION_H__) + type_g = nm_setting_lookup_type (type); +#else + type_g = nm_connection_lookup_setting_type (type); +#endif g_assert (type_g != G_TYPE_INVALID); @@ -1287,7 +1293,12 @@ nmtst_create_minimal_connection (const char *id, const char *uuid, const char *t g_assert (NM_IS_SETTING (s_base)); } +#if defined(__NM_SIMPLE_CONNECTION_H__) con = nm_simple_connection_new (); +#else + con = nm_connection_new (); +#endif + s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); g_object_set (s_con, @@ -1358,7 +1369,11 @@ _nmtst_connection_duplicate_and_normalize (NMConnection *connection, ...) g_assert (NM_IS_CONNECTION (connection)); +#if defined(__NM_SIMPLE_CONNECTION_H__) connection = nm_simple_connection_new_clone (connection); +#else + connection = nm_connection_duplicate (connection); +#endif va_start (args, connection); was_modified = _nmtst_connection_normalize_v (connection, args); @@ -1440,7 +1455,11 @@ nmtst_assert_connection_verifies_without_normalization (NMConnection *con) g_assert (NM_IS_CONNECTION (con)); +#if defined(__NM_SIMPLE_CONNECTION_H__) clone = nm_simple_connection_new_clone (con); +#else + clone = nm_connection_duplicate (con); +#endif success = nm_connection_verify (con, &error); g_assert_no_error (error); From bdfcf02da3b268798e45608df96697ed899760fa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 21 Dec 2015 10:55:38 +0100 Subject: [PATCH 11/20] libnm/tests: add NMTSTC_SERVICE_INFO_SETUP() macro --- shared/nm-test-libnm-utils.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/shared/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h index 667ba90db6..290feea2e4 100644 --- a/shared/nm-test-libnm-utils.h +++ b/shared/nm-test-libnm-utils.h @@ -22,6 +22,8 @@ #include "nm-test-utils.h" +/*****************************************************************************/ + typedef struct { GDBusConnection *bus; GDBusProxy *proxy; @@ -32,6 +34,21 @@ typedef struct { NMTstcServiceInfo *nmtstc_service_init (void); void nmtstc_service_cleanup (NMTstcServiceInfo *info); +static inline void _nmtstc_auto_service_cleanup (NMTstcServiceInfo **info) +{ + if (info && *info) { + nmtstc_service_cleanup (*info); + *info = NULL; + } +} + +#define NMTSTC_SERVICE_INFO_SETUP(sinfo) \ + NM_PRAGMA_WARNING_DISABLE ("-Wunused-variable") \ + __attribute__ ((cleanup(_nmtstc_auto_service_cleanup))) NMTstcServiceInfo *sinfo = nmtstc_service_init (); \ + NM_PRAGMA_WARNING_REENABLE + +/*****************************************************************************/ + #if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) NMDevice *nmtstc_service_add_device (NMTstcServiceInfo *info, From 56880fbe692f52463e06298f1fe8a2e017e8d6bb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Dec 2015 13:53:20 +0100 Subject: [PATCH 12/20] libnm/tests: add nmtstc_nm_client_new() --- shared/nm-test-libnm-utils.h | 8 ++++++++ shared/nm-test-utils-impl.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/shared/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h index 290feea2e4..e1aad3633b 100644 --- a/shared/nm-test-libnm-utils.h +++ b/shared/nm-test-libnm-utils.h @@ -64,3 +64,11 @@ NMDevice * nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, #endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) + +#include "nm-client.h" + +NMClient *nmtstc_nm_client_new (void); + +#endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */ + diff --git a/shared/nm-test-utils-impl.c b/shared/nm-test-utils-impl.c index dac07b90d4..1f73cb35a9 100644 --- a/shared/nm-test-utils-impl.c +++ b/shared/nm-test-utils-impl.c @@ -236,3 +236,38 @@ nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, NMClient *client, } #endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ + +/*****************************************************************************/ + +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) + +NMClient * +nmtstc_nm_client_new (void) +{ + NMClient *client; + DBusGConnection *bus; + GError *error = NULL; + gboolean success; + + bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + g_assert_no_error (error); + g_assert (bus); + + client = g_object_new (NM_TYPE_CLIENT, + NM_OBJECT_DBUS_CONNECTION, bus, + NM_OBJECT_DBUS_PATH, NM_DBUS_PATH, + NULL); + g_assert (client != NULL); + + dbus_g_connection_unref (bus); + + success = g_initable_init (G_INITABLE (client), NULL, &error); + g_assert_no_error (error); + g_assert (success == TRUE); + + return client; +} + +#endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */ + +/*****************************************************************************/ From d90525ebfcfcd4325a063edd31dd3a578b97f39d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Dec 2015 13:53:28 +0100 Subject: [PATCH 13/20] libnm/tests: use nmtstc_nm_client_new() --- libnm-glib/tests/test-nm-client.c | 40 +++++-------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/libnm-glib/tests/test-nm-client.c b/libnm-glib/tests/test-nm-client.c index 42248947b7..b9b36bf69b 100644 --- a/libnm-glib/tests/test-nm-client.c +++ b/libnm-glib/tests/test-nm-client.c @@ -40,34 +40,6 @@ static NMTstcServiceInfo *sinfo; /*******************************************************************/ -static NMClient * -test_client_new (void) -{ - NMClient *client; - DBusGConnection *bus; - GError *error = NULL; - gboolean success; - - bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - g_assert_no_error (error); - - client = g_object_new (NM_TYPE_CLIENT, - NM_OBJECT_DBUS_CONNECTION, bus, - NM_OBJECT_DBUS_PATH, NM_DBUS_PATH, - NULL); - g_assert (client != NULL); - - dbus_g_connection_unref (bus); - - success = g_initable_init (G_INITABLE (client), NULL, &error); - g_assert_no_error (error); - g_assert (success == TRUE); - - return client; -} - -/*******************************************************************/ - static gboolean loop_quit (gpointer user_data) { @@ -182,7 +154,7 @@ test_device_added (void) DeviceAddedInfo info = { loop, FALSE, FALSE, 0, 0 }; sinfo = nmtstc_service_init (); - client = test_client_new (); + client = nmtstc_nm_client_new (); devices = nm_client_get_devices (client); g_assert (devices == NULL); @@ -339,7 +311,7 @@ test_wifi_ap_added_removed (void) char *expected_path = NULL; sinfo = nmtstc_service_init (); - client = test_client_new (); + client = nmtstc_nm_client_new (); /*************************************/ /* Add the wifi device */ @@ -562,7 +534,7 @@ test_wimax_nsp_added_removed (void) char *expected_path = NULL; sinfo = nmtstc_service_init (); - client = test_client_new (); + client = nmtstc_nm_client_new (); /*************************************/ /* Add the wimax device */ @@ -747,7 +719,7 @@ test_devices_array (void) GVariant *ret; sinfo = nmtstc_service_init (); - client = test_client_new (); + client = nmtstc_nm_client_new (); /*************************************/ /* Add some devices */ @@ -852,7 +824,7 @@ test_client_manager_running (void) int running_changed = 0; GError *error = NULL; - client1 = test_client_new (); + client1 = nmtstc_nm_client_new (); g_assert (!nm_client_get_manager_running (client1)); g_assert_cmpstr (nm_client_get_version (client1), ==, NULL); @@ -869,7 +841,7 @@ test_client_manager_running (void) /* Now start the test service. */ sinfo = nmtstc_service_init (); - client2 = test_client_new (); + client2 = nmtstc_nm_client_new (); /* client2 should know that NM is running, but the previously-created * client1 hasn't gotten the news yet. From 5edd265c0b43440c8c9d2dafa1dcf3861be45a76 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Dec 2015 14:05:22 +0100 Subject: [PATCH 14/20] libnm/tests: add nmtstc_nm_remote_settings_new() --- shared/nm-test-libnm-utils.h | 2 ++ shared/nm-test-utils-impl.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/shared/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h index e1aad3633b..dad5638f9f 100644 --- a/shared/nm-test-libnm-utils.h +++ b/shared/nm-test-libnm-utils.h @@ -67,8 +67,10 @@ NMDevice * nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, #if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) #include "nm-client.h" +#include "nm-remote-settings.h" NMClient *nmtstc_nm_client_new (void); +NMRemoteSettings *nmtstc_nm_remote_settings_new (void); #endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */ diff --git a/shared/nm-test-utils-impl.c b/shared/nm-test-utils-impl.c index 1f73cb35a9..91bf8b3c0c 100644 --- a/shared/nm-test-utils-impl.c +++ b/shared/nm-test-utils-impl.c @@ -268,6 +268,25 @@ nmtstc_nm_client_new (void) return client; } +NMRemoteSettings * +nmtstc_nm_remote_settings_new (void) +{ + NMRemoteSettings *settings; + DBusGConnection *bus; + GError *error = NULL; + + bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + g_assert_no_error (error); + g_assert (bus); + + settings = nm_remote_settings_new (bus); + g_assert (settings); + + dbus_g_connection_unref (bus); + + return settings; +} + #endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */ /*****************************************************************************/ From c0af56ac7a1466f36a579adba524b69e799689af Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Dec 2015 14:07:34 +0100 Subject: [PATCH 15/20] libnm/tests: use nmtstc_nm_remote_settings_new() --- libnm-glib/tests/test-remote-settings-client.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libnm-glib/tests/test-remote-settings-client.c b/libnm-glib/tests/test-remote-settings-client.c index fbeb558e1e..83227d4bbc 100644 --- a/libnm-glib/tests/test-remote-settings-client.c +++ b/libnm-glib/tests/test-remote-settings-client.c @@ -437,8 +437,7 @@ main (int argc, char **argv) sinfo = nmtstc_service_init (); - settings = nm_remote_settings_new (bus); - g_assert (settings != NULL); + settings = nmtstc_nm_remote_settings_new (); /* FIXME: these tests assume that they get run in order, but g_test_run() * does not actually guarantee that! From 570d24b88ca82332d472dcb562f5e0d825d63cf2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Dec 2015 14:07:36 +0100 Subject: [PATCH 16/20] libnm/tests: add dbus-glib support to "nm-test-libnm-utils" --- shared/nm-test-libnm-utils.h | 5 +++++ shared/nm-test-utils-impl.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/shared/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h index dad5638f9f..9645b9edff 100644 --- a/shared/nm-test-libnm-utils.h +++ b/shared/nm-test-libnm-utils.h @@ -29,6 +29,11 @@ typedef struct { GDBusProxy *proxy; GPid pid; int keepalive_fd; +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) + struct { + DBusGConnection *bus; + } libdbus; +#endif } NMTstcServiceInfo; NMTstcServiceInfo *nmtstc_service_init (void); diff --git a/shared/nm-test-utils-impl.c b/shared/nm-test-utils-impl.c index 91bf8b3c0c..fc6d6c2af8 100644 --- a/shared/nm-test-utils-impl.c +++ b/shared/nm-test-utils-impl.c @@ -26,8 +26,14 @@ #include "NetworkManager.h" #include "nm-dbus-compat.h" +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) +#include "nm-dbus-glib-types.h" +#endif + #include "nm-test-libnm-utils.h" +/*****************************************************************************/ + static gboolean name_exists (GDBusConnection *c, const char *name) { @@ -94,6 +100,11 @@ nmtstc_service_init (void) NULL, &error); g_assert_no_error (error); +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) + info->libdbus.bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + g_assert_no_error (error); + g_assert (info->libdbus.bus); +#endif return info; } @@ -116,6 +127,10 @@ nmtstc_service_cleanup (NMTstcServiceInfo *info) g_object_unref (info->bus); close (info->keepalive_fd); +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) + g_clear_pointer (&info->libdbus.bus, dbus_g_connection_unref); +#endif + memset (info, 0, sizeof (*info)); g_free (info); } From 8859cd0738ac8803d5b077a517aaa6476f7266d3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Dec 2015 13:50:19 +0100 Subject: [PATCH 17/20] libnm/tests: extend handling connections in python test service --- tools/test-networkmanager-service.py | 90 ++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 11 deletions(-) diff --git a/tools/test-networkmanager-service.py b/tools/test-networkmanager-service.py index ae63eaf745..6335fd8070 100755 --- a/tools/test-networkmanager-service.py +++ b/tools/test-networkmanager-service.py @@ -10,6 +10,7 @@ import dbus.service import dbus.mainloop.glib import random import collections +import uuid mainloop = GLib.MainLoop() @@ -918,6 +919,15 @@ class NetworkManager(ExportedObj): def AutoRemoveNextConnection(self): settings.auto_remove_next_connection() + @dbus.service.method(dbus_interface=IFACE_TEST, in_signature='a{sa{sv}}b', out_signature='o') + def AddConnection(self, connection, verify_connection): + return settings.add_connection(connection, verify_connection) + + @dbus.service.method(dbus_interface=IFACE_TEST, in_signature='sa{sa{sv}}b', out_signature='') + def UpdateConnection(self, path, connection, verify_connection): + return settings.update_connection(connection, path, verify_connection) + + ################################################################### IFACE_CONNECTION = 'org.freedesktop.NetworkManager.Settings.Connection' @@ -934,17 +944,15 @@ class MissingSettingException(dbus.DBusException): _dbus_error_name = IFACE_CONNECTION + '.MissingSetting' class Connection(dbus.service.Object): - def __init__(self, bus, object_path, settings, remove_func): - dbus.service.Object.__init__(self, bus, object_path) + def __init__(self, bus, object_path, settings, remove_func, verify_connection=True): - if 'connection' not in settings: - raise MissingSettingException('connection: setting is required') - s_con = settings['connection'] - if 'type' not in s_con: - raise MissingPropertyException('connection.type: property is required') - type = s_con['type'] - if not type in ['802-3-ethernet', '802-11-wireless', 'vlan', 'wimax']: - raise InvalidPropertyException('connection.type: unsupported connection type') + if self.get_uuid(settings) is None: + if 'connection' not in settings: + settings['connection'] = { } + settings['connection']['uuid'] = uuid.uuid4() + self.verify(settings, verify_strict=verify_connection) + + dbus.service.Object.__init__(self, bus, object_path) self.path = object_path self.settings = settings @@ -953,6 +961,45 @@ class Connection(dbus.service.Object): self.props = {} self.props['Unsaved'] = False + def get_uuid(self, settings=None): + if settings is None: + settings = self.settings + if 'connection' in settings: + s_con = settings['connection'] + if 'uuid' in s_con: + return s_con['uuid'] + return None + + def verify(self, settings=None, verify_strict=True): + if settings is None: + settings = self.settings; + if 'connection' not in settings: + raise MissingSettingException('connection: setting is required') + s_con = settings['connection'] + if 'type' not in s_con: + raise MissingPropertyException('connection.type: property is required') + if 'uuid' not in s_con: + raise MissingPropertyException('connection.uuid: property is required') + if 'id' not in s_con: + raise MissingPropertyException('connection.id: property is required') + + if not verify_strict: + return; + t = s_con['type'] + if t not in ['802-3-ethernet', '802-11-wireless', 'vlan', 'wimax']: + raise InvalidPropertyException('connection.type: unsupported connection type "%s"' % (t)) + + def update_connection(self, settings, verify_connection): + self.verify(settings, verify_strict=verify_connection) + + old_uuid = self.get_uuid() + new_uuid = self.get_uuid(settings) + if old_uuid != new_uuid: + raise InvalidPropertyException('connection.uuid: cannot change the uuid from %s to %s' % (old_uuid, new_uuid)) + + self.settings = settings; + self.Updated() + # Properties interface @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}') def GetAll(self, iface): @@ -986,6 +1033,10 @@ class Connection(dbus.service.Object): self.Removed() self.remove_from_connection() + @dbus.service.method(dbus_interface=IFACE_CONNECTION, in_signature='a{sa{sv}}', out_signature='') + def Update(self, settings): + self.update_connection(settings, TRUE) + @dbus.service.signal(IFACE_CONNECTION, signature='') def Removed(self): pass @@ -1024,9 +1075,18 @@ class Settings(dbus.service.Object): @dbus.service.method(dbus_interface=IFACE_SETTINGS, in_signature='a{sa{sv}}', out_signature='o') def AddConnection(self, settings): + return self.add_connection(settings) + + def add_connection(self, settings, verify_connection=True): path = "/org/freedesktop/NetworkManager/Settings/Connection/{0}".format(self.counter) + con = Connection(self.bus, path, settings, self.delete_connection, verify_connection) + + uuid = con.get_uuid() + if uuid in [c.get_uuid() for c in self.connections.itervalues()]: + raise InvalidSettingException('cannot add duplicate connection with uuid %s' % (uuid)) + self.counter = self.counter + 1 - self.connections[path] = Connection(self.bus, path, settings, self.delete_connection) + self.connections[path] = con self.props['Connections'] = dbus.Array(self.connections.keys(), 'o') self.NewConnection(path) self.PropertiesChanged({ 'connections': self.props['Connections'] }) @@ -1037,6 +1097,14 @@ class Settings(dbus.service.Object): return path + def update_connection(self, connection, path=None, verify_connection=True): + if path is None: + path = connection.path + if path not in self.connections: + raise UnknownConnectionException('Connection not found') + con = self.connections[path] + con.update_connection(connection, verify_connection) + def delete_connection(self, connection): del self.connections[connection.path] self.props['Connections'] = dbus.Array(self.connections.keys(), 'o') From 142ea41cae133f6e645fced9ee899196b6c682f2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Dec 2015 20:27:45 +0100 Subject: [PATCH 18/20] libnm/tests: add test code driving python test service --- shared/nm-test-libnm-utils.h | 20 +++++ shared/nm-test-utils-impl.c | 159 +++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) diff --git a/shared/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h index 9645b9edff..8d111003aa 100644 --- a/shared/nm-test-libnm-utils.h +++ b/shared/nm-test-libnm-utils.h @@ -79,3 +79,23 @@ NMRemoteSettings *nmtstc_nm_remote_settings_new (void); #endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */ +void nmtstc_service_add_connection (NMTstcServiceInfo *sinfo, + NMConnection *connection, + gboolean verify_connection, + char **out_path); + +void nmtstc_service_add_connection_variant (NMTstcServiceInfo *sinfo, + GVariant *connection, + gboolean verify_connection, + char **out_path); + +void nmtstc_service_update_connection (NMTstcServiceInfo *sinfo, + const char *path, + NMConnection *connection, + gboolean verify_connection); + +void nmtstc_service_update_connection_variant (NMTstcServiceInfo *sinfo, + const char *path, + GVariant *connection, + gboolean verify_connection); + diff --git a/shared/nm-test-utils-impl.c b/shared/nm-test-utils-impl.c index fc6d6c2af8..5cdfda3d79 100644 --- a/shared/nm-test-utils-impl.c +++ b/shared/nm-test-utils-impl.c @@ -59,6 +59,26 @@ name_exists (GDBusConnection *c, const char *name) return exists; } +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) + +static DBusGProxy * +_libdbus_create_proxy_test (DBusGConnection *bus) +{ + DBusGProxy *proxy; + + proxy = dbus_g_proxy_new_for_name (bus, + NM_DBUS_SERVICE, + NM_DBUS_PATH, + "org.freedesktop.NetworkManager.LibnmGlibTest"); + g_assert (proxy); + + dbus_g_proxy_set_default_timeout (proxy, G_MAXINT); + + return proxy; +} + +#endif + NMTstcServiceInfo * nmtstc_service_init (void) { @@ -252,6 +272,145 @@ nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, NMClient *client, #endif /* NM_NETWORKMANAGER_COMPILATION_LIB */ +void +nmtstc_service_add_connection (NMTstcServiceInfo *sinfo, + NMConnection *connection, + gboolean verify_connection, + char **out_path) +{ +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) + gs_unref_hashtable GHashTable *new_settings = NULL; + gboolean success; + gs_free_error GError *error = NULL; + gs_free char *path = NULL; + gs_unref_object DBusGProxy *proxy = NULL; + + g_assert (sinfo); + g_assert (NM_IS_CONNECTION (connection)); + + new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); + + proxy = _libdbus_create_proxy_test (sinfo->libdbus.bus); + + success = dbus_g_proxy_call (proxy, + "AddConnection", + &error, + DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings, + G_TYPE_BOOLEAN, verify_connection, + G_TYPE_INVALID, + DBUS_TYPE_G_OBJECT_PATH, &path, + G_TYPE_INVALID); + g_assert_no_error (error); + g_assert (success); + + g_assert (path && *path); + + if (out_path) + *out_path = g_strdup (path); +#else + nmtstc_service_add_connection_variant (sinfo, + nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL), + verify_connection, + out_path); +#endif +} + +void +nmtstc_service_add_connection_variant (NMTstcServiceInfo *sinfo, + GVariant *connection, + gboolean verify_connection, + char **out_path) +{ + GVariant *result; + GError *error = NULL; + + g_assert (sinfo); + g_assert (G_IS_DBUS_PROXY (sinfo->proxy)); + g_assert (g_variant_is_of_type (connection, G_VARIANT_TYPE ("a{sa{sv}}"))); + + result = g_dbus_proxy_call_sync (sinfo->proxy, + "AddConnection", + g_variant_new ("(vb)", connection, verify_connection), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 3000, + NULL, + &error); + g_assert_no_error (error); + g_assert (g_variant_is_of_type (result, G_VARIANT_TYPE ("(o)"))); + if (out_path) + g_variant_get (result, "(o)", out_path); + g_variant_unref (result); +} + +void +nmtstc_service_update_connection (NMTstcServiceInfo *sinfo, + const char *path, + NMConnection *connection, + gboolean verify_connection) +{ + if (!path) + path = nm_connection_get_path (connection); + g_assert (path); + +#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) + { + gs_unref_hashtable GHashTable *new_settings = NULL; + gboolean success; + gs_free_error GError *error = NULL; + gs_unref_object DBusGProxy *proxy = NULL; + + g_assert (sinfo); + g_assert (NM_IS_CONNECTION (connection)); + + new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); + + proxy = _libdbus_create_proxy_test (sinfo->libdbus.bus); + + success = dbus_g_proxy_call (proxy, + "UpdateConnection", + &error, + DBUS_TYPE_G_OBJECT_PATH, path, + DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings, + G_TYPE_BOOLEAN, verify_connection, + G_TYPE_INVALID, + G_TYPE_INVALID); + g_assert_no_error (error); + g_assert (success); + } +#else + nmtstc_service_update_connection_variant (sinfo, + path, + nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL), + verify_connection); +#endif +} + +void +nmtstc_service_update_connection_variant (NMTstcServiceInfo *sinfo, + const char *path, + GVariant *connection, + gboolean verify_connection) +{ + GVariant *result; + GError *error = NULL; + + g_assert (sinfo); + g_assert (G_IS_DBUS_PROXY (sinfo->proxy)); + g_assert (g_variant_is_of_type (connection, G_VARIANT_TYPE ("a{sa{sv}}"))); + g_assert (path && path[0] == '/'); + + result = g_dbus_proxy_call_sync (sinfo->proxy, + "UpdateConnection", + g_variant_new ("(ovb)", path, connection, verify_connection), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 3000, + NULL, + &error); + g_assert_no_error (error); + g_assert (g_variant_is_of_type (result, G_VARIANT_TYPE ("()"))); + g_variant_unref (result); +} + /*****************************************************************************/ #if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY) From 212e1c3a8481fef1ce780ed9b17d17fd51acdee3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Dec 2015 19:06:49 +0100 Subject: [PATCH 19/20] libnm-glib: avoid use-after-free when replace_settings() fails When replace_settings() fails, it emits the REMOVED signal. That in turn can free the self instance. Ensure to keep the instance alive long enough. --- libnm-glib/nm-remote-connection.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libnm-glib/nm-remote-connection.c b/libnm-glib/nm-remote-connection.c index 1bc545d555..4298129bc0 100644 --- a/libnm-glib/nm-remote-connection.c +++ b/libnm-glib/nm-remote-connection.c @@ -496,6 +496,9 @@ updated_get_settings_cb (DBusGProxy *proxy, priv->visible = FALSE; g_signal_emit (self, signals[VISIBLE], 0, FALSE); } else { + gs_unref_object NMConnection *self_alive = NULL; + + self_alive = g_object_ref (self); replace_settings (self, new_settings); g_hash_table_destroy (new_settings); @@ -618,6 +621,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); GHashTable *hash; + gs_unref_object NMConnection *self_alive = NULL; if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error, G_TYPE_INVALID, @@ -625,6 +629,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) G_TYPE_INVALID)) return FALSE; priv->visible = TRUE; + self_alive = g_object_ref (initable); replace_settings (NM_REMOTE_CONNECTION (initable), hash); g_hash_table_destroy (hash); @@ -688,6 +693,7 @@ init_get_settings_cb (DBusGProxy *proxy, NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection); GHashTable *settings; GError *error = NULL; + gs_unref_object NMConnection *self_alive = NULL; dbus_g_proxy_end_call (proxy, call, &error, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings, @@ -698,6 +704,7 @@ init_get_settings_cb (DBusGProxy *proxy, } priv->visible = TRUE; + self_alive = g_object_ref (init_data->connection); replace_settings (init_data->connection, settings); g_hash_table_destroy (settings); From 92f122525dab49fece51b6b6bda99c762507f7c9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 24 Dec 2015 17:20:39 +0100 Subject: [PATCH 20/20] libnm/tests: add tests for libnm handling invalid connections Add test showing how libnm/libnm-glib handles invalid connections, i.e. connections that fail nm_connection_verify(). libnm implements settings a static types (via different NMSetting types). This makes it unavoidable that eventually a newer server version will expose connections that fail verification in the client. For example, master added a new base type NMSettingTun. This setting type was not backported to legacy libnm-glib, thus such connection will not verify. Also, we want that newer server versions are backward compatible with older library versions. Thus also a pre-NMSettingTun libnm version has the same problem. The test shows that libnm is agnostic to whether the connection verifies. That is consistent behavior, but possibly problematic because most accessors to connections assert against a valid connection. Thus using the common nm_connection*() functions on an invalid connection can lead to problems. Also, due to the static nature of our NMSetting types, some properties can be silently dropped and thus mangling the connection without the library user noticing. libnm-glib prints a g_warning() whenever parsing an invalid connection. When an invalid connection is added initially, it is exposed to the library user. When a connection gets later invalidated due to an update, the connection disappears and it stays missing even if a subsequent update makes the connection valid again. libnm-glib's behavior indicates that we might wanted to hide invalid connections from the user. But it's very broken there. --- libnm-glib/tests/test-nm-client.c | 260 ++++++++++++++++++++++++++++++ libnm/tests/test-nm-client.c | 238 +++++++++++++++++++++++++++ 2 files changed, 498 insertions(+) diff --git a/libnm-glib/tests/test-nm-client.c b/libnm-glib/tests/test-nm-client.c index b9b36bf69b..f528bc26fb 100644 --- a/libnm-glib/tests/test-nm-client.c +++ b/libnm-glib/tests/test-nm-client.c @@ -32,6 +32,8 @@ #include "nm-device-wifi.h" #include "nm-device-ethernet.h" #include "nm-device-wimax.h" +#include "nm-connection.h" +#include "nm-setting.h" #include "nm-test-libnm-utils.h" @@ -874,6 +876,263 @@ test_client_manager_running (void) /*******************************************************************/ +static GPtrArray * +_slist_to_array (GPtrArray **connections, GSList *list) +{ + GPtrArray *array; + const GSList *iter; + + if (!*connections) + *connections = array = g_ptr_array_new (); + else { + array = *connections; + g_ptr_array_set_size (array, 0); + } + for (iter = list; iter; iter = iter->next) + g_ptr_array_add (array, iter->data); + g_slist_free (list); + return array; +} + +static gboolean +_test_connection_invalid_find_connections (gpointer element, gpointer needle, gpointer user_data) +{ + NMRemoteConnection *con = NM_REMOTE_CONNECTION (element); + const char *path = needle; + + g_assert (NM_IS_REMOTE_CONNECTION (con)); + g_assert (path && *path); + + return strcmp (path, nm_connection_get_path ((NMConnection *) con)) == 0; +} + +#define ASSERT_IDX(i) \ + g_assert_cmpint (idx[i], >=, 0); \ + g_assert (path##i && *path##i); \ + g_assert (NM_IS_REMOTE_CONNECTION (connections->pdata[idx[i]])); \ + g_assert_cmpstr (nm_connection_get_path (connections->pdata[idx[i]]), ==, path##i); + +static void +test_connection_invalid (void) +{ + NMTSTC_SERVICE_INFO_SETUP (my_sinfo) + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + gs_unref_object NMRemoteSettings *settings = NULL; + gs_unref_ptrarray GPtrArray *connections = NULL; + gs_free char *path0 = NULL; + gs_free char *path1 = NULL; + gs_free char *path2 = NULL; + gs_free char *uuid2 = NULL; + gsize n_found; + gssize idx[3]; + + /************************************************************************** + * Add two connection before starting libnm. One valid, one invalid. + *************************************************************************/ + + connection = nmtst_create_minimal_connection ("test-connection-invalid-0", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_UUID, nmtst_uuid_generate (), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + TRUE, + &path0); + + nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRED); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-1", + NM_SETTING_CONNECTION_TYPE, "invalid-type-1", + NM_SETTING_CONNECTION_UUID, nmtst_uuid_generate (), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + FALSE, + &path1); + + nmtst_main_loop_run (loop, 100); + + settings = nmtstc_nm_remote_settings_new (); + + g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); + + nmtst_main_loop_run (loop, 100); + + g_test_assert_expected_messages (); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1 }), + 2, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + + /************************************************************************** + * After having the client up and running, add another invalid connection + *************************************************************************/ + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2", + NM_SETTING_CONNECTION_TYPE, "invalid-type-2", + NM_SETTING_CONNECTION_UUID, (uuid2 = g_strdup (nmtst_uuid_generate ())), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + FALSE, + &path2); + + g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); + + nmtst_main_loop_run (loop, 100); + + g_test_assert_expected_messages (); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 3); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 3); + ASSERT_IDX (0); + ASSERT_IDX (1); + ASSERT_IDX (2); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[2]], 0, 0); + + /************************************************************************** + * Modify the invalid connection. Connection disappears + *************************************************************************/ + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2x", + NULL); + nmtstc_service_update_connection (my_sinfo, + path2, + connection, + FALSE); + + g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); + + nmtst_main_loop_run (loop, 100); + + g_test_assert_expected_messages (); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + g_assert_cmpint (idx[2], ==, -1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + + /************************************************************************** + * Modify the invalid connection again. Note that the connection stays + * invisible (although it exists, and is valid). + *************************************************************************/ + + g_clear_object (&connection); + connection = nmtst_create_minimal_connection ("test-connection-invalid-2", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2z", + NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", + NM_SETTING_CONNECTION_UUID, uuid2, + NULL); + + nmtstc_service_update_connection (my_sinfo, + path2, + connection, + FALSE); + + nmtst_main_loop_run (loop, 100); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + g_assert_cmpint (idx[2], ==, -1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + + + /************************************************************************** + * Modify the invalid connection and make it valid + *************************************************************************/ + + g_clear_object (&connection); + connection = nmtst_create_minimal_connection ("test-connection-invalid-1", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-1x", + NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connections->pdata[idx[1]]), + NULL); + + nmtstc_service_update_connection (my_sinfo, + path1, + connection, + FALSE); + + nmtst_main_loop_run (loop, 100); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + g_assert_cmpint (idx[2], ==, -1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[1]]); + g_assert_cmpstr ("test-connection-invalid-1x", ==, nm_connection_get_id (connections->pdata[idx[1]])); + +#undef ASSERT_IDX +} + +/*******************************************************************/ + NMTST_DEFINE (); int @@ -888,6 +1147,7 @@ main (int argc, char **argv) g_test_add_func ("/libnm-glib/wimax-nsp-added-removed", test_wimax_nsp_added_removed); g_test_add_func ("/libnm-glib/devices-array", test_devices_array); g_test_add_func ("/libnm-glib/client-manager-running", test_client_manager_running); + g_test_add_func ("/libnm/connection/invalid", test_connection_invalid); return g_test_run (); } diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c index f2701ab33f..5be69142e5 100644 --- a/libnm/tests/test-nm-client.c +++ b/libnm/tests/test-nm-client.c @@ -1228,6 +1228,243 @@ test_device_connection_compatibility (void) /*******************************************************************/ +static gboolean +_test_connection_invalid_find_connections (gpointer element, gpointer needle, gpointer user_data) +{ + NMRemoteConnection *con = NM_REMOTE_CONNECTION (element); + const char *path = needle; + + g_assert (NM_IS_REMOTE_CONNECTION (con)); + g_assert (path && *path); + + return strcmp (path, nm_connection_get_path ((NMConnection *) con)) == 0; +} + +#define ASSERT_IDX(i) \ + g_assert_cmpint (idx[i], >=, 0); \ + g_assert (path##i && *path##i); \ + g_assert (NM_IS_REMOTE_CONNECTION (connections->pdata[idx[i]])); \ + g_assert_cmpstr (nm_connection_get_path (connections->pdata[idx[i]]), ==, path##i); + +static void +test_connection_invalid (void) +{ + NMTSTC_SERVICE_INFO_SETUP (my_sinfo) + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + gs_unref_object NMClient *client = NULL; + const GPtrArray *connections; + gs_free_error GError *error = NULL; + gs_free char *path0 = NULL; + gs_free char *path1 = NULL; + gs_free char *path2 = NULL; + gs_free char *uuid2 = NULL; + gsize n_found; + gssize idx[3]; + + /************************************************************************** + * Add two connection before starting libnm. One valid, one invalid. + *************************************************************************/ + + connection = nmtst_create_minimal_connection ("test-connection-invalid-0", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_UUID, nmtst_uuid_generate (), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + TRUE, + &path0); + + nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRED); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-1", + NM_SETTING_CONNECTION_TYPE, "invalid-type-1", + NM_SETTING_CONNECTION_UUID, nmtst_uuid_generate (), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + FALSE, + &path1); + + + client = nm_client_new (NULL, &error); + g_assert_no_error (error); + + connections = nm_client_get_connections (client); + g_assert (connections); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1 }), + 2, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + + /************************************************************************** + * After having the client up and running, add another invalid connection + *************************************************************************/ + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2", + NM_SETTING_CONNECTION_TYPE, "invalid-type-2", + NM_SETTING_CONNECTION_UUID, (uuid2 = g_strdup (nmtst_uuid_generate ())), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + FALSE, + &path2); + + + nmtst_main_loop_run (loop, 100); + + + connections = nm_client_get_connections (client); + g_assert (connections); + + g_assert_cmpint (connections->len, ==, 3); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 3); + ASSERT_IDX (0); + ASSERT_IDX (1); + ASSERT_IDX (2); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[2]], 0, 0); + + /************************************************************************** + * Modify the invalid connection (still invalid) + *************************************************************************/ + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2x", + NULL); + nmtstc_service_update_connection (my_sinfo, + path2, + connection, + FALSE); + + nmtst_main_loop_run (loop, 100); + + connections = nm_client_get_connections (client); + g_assert (connections); + + g_assert_cmpint (connections->len, ==, 3); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 3); + ASSERT_IDX (0); + ASSERT_IDX (1); + ASSERT_IDX (2); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[2]], 0, 0); + g_assert_cmpstr ("test-connection-invalid-2x", ==, nm_connection_get_id (connections->pdata[idx[2]])); + + /************************************************************************** + * Modify the invalid connection (now becomes valid) + *************************************************************************/ + + g_clear_object (&connection); + connection = nmtst_create_minimal_connection ("test-connection-invalid-2", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2z", + NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", + NM_SETTING_CONNECTION_UUID, uuid2, + NULL); + + nmtstc_service_update_connection (my_sinfo, + path2, + connection, + FALSE); + + nmtst_main_loop_run (loop, 100); + + connections = nm_client_get_connections (client); + g_assert (connections); + + g_assert_cmpint (connections->len, ==, 3); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 3); + ASSERT_IDX (0); + ASSERT_IDX (1); + ASSERT_IDX (2); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[2]]); + g_assert_cmpstr ("test-connection-invalid-2z", ==, nm_connection_get_id (connections->pdata[idx[2]])); + + /************************************************************************** + * Modify the invalid connection and make it valid + *************************************************************************/ + + g_clear_object (&connection); + connection = nmtst_create_minimal_connection ("test-connection-invalid-1", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-1x", + NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connections->pdata[idx[1]]), + NULL); + + nmtstc_service_update_connection (my_sinfo, + path1, + connection, + FALSE); + + nmtst_main_loop_run (loop, 100); + + connections = nm_client_get_connections (client); + g_assert (connections); + + g_assert_cmpint (connections->len, ==, 3); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 3); + ASSERT_IDX (0); + ASSERT_IDX (1); + ASSERT_IDX (2); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[1]]); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[2]]); + g_assert_cmpstr ("test-connection-invalid-1x", ==, nm_connection_get_id (connections->pdata[idx[1]])); + g_assert_cmpstr ("test-connection-invalid-2z", ==, nm_connection_get_id (connections->pdata[idx[2]])); + +#undef ASSERT_IDX +} + +/*******************************************************************/ + NMTST_DEFINE (); int @@ -1249,6 +1486,7 @@ main (int argc, char **argv) g_test_add_func ("/libnm/activate-virtual", test_activate_virtual); g_test_add_func ("/libnm/activate-failed", test_activate_failed); g_test_add_func ("/libnm/device-connection-compatibility", test_device_connection_compatibility); + g_test_add_func ("/libnm/connection/invalid", test_connection_invalid); return g_test_run (); }