summaryrefslogtreecommitdiff
path: root/libnm-glib
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-05-06 08:51:26 +0200
committerThomas Haller <thaller@redhat.com>2018-05-11 16:51:20 +0200
commit9628aabc2fbf9315eb9c87478da1588c72d8b44c (patch)
treee6eb56b0d25e50d009b79f880ba910677def9e9d /libnm-glib
parent3934a2c392e8d6c600b211afee871989a338a1fe (diff)
tests: use libnm via pygobject in tools/test-networkmanager-service.py
tools/test-networkmanager-service.py is our NetworkManager stub server. NetworkManager uses libnm(-core) heavily, for example to decide whether a connection verifies (nm_connection_verify()) and for normalizing connections (nm_connection_normalize()). If the stub server wants to mimic NetworkManager, it also must use these function. Luckily, we already can do so, by loading libnm using python GObject introspection. We already correctly set GI_TYPELIB_PATH search path, so that the correct libnm is loaded -- provided that we build with introspection enabled. We still need to gracefully fail, if starting the stub server fails. That requries some extra effort. If the stub server notices that something is missing, it shall exit with status 77. That will cause the tests to g_test_skip().
Diffstat (limited to 'libnm-glib')
-rw-r--r--libnm-glib/tests/test-nm-client.c21
-rw-r--r--libnm-glib/tests/test-remote-settings-client.c20
2 files changed, 34 insertions, 7 deletions
diff --git a/libnm-glib/tests/test-nm-client.c b/libnm-glib/tests/test-nm-client.c
index 943252033..df8572153 100644
--- a/libnm-glib/tests/test-nm-client.c
+++ b/libnm-glib/tests/test-nm-client.c
@@ -155,6 +155,9 @@ test_device_added (void)
DeviceAddedInfo info = { loop, FALSE, FALSE, 0, 0 };
sinfo = nmtstc_service_init ();
+ if (!nmtstc_service_available (sinfo))
+ return;
+
client = nmtstc_nm_client_new ();
devices = nm_client_get_devices (client);
@@ -312,6 +315,9 @@ test_wifi_ap_added_removed (void)
char *expected_path = NULL;
sinfo = nmtstc_service_init ();
+ if (!nmtstc_service_available (sinfo))
+ return;
+
client = nmtstc_nm_client_new ();
/*************************************/
@@ -535,6 +541,9 @@ test_wimax_nsp_added_removed (void)
char *expected_path = NULL;
sinfo = nmtstc_service_init ();
+ if (!nmtstc_service_available (sinfo))
+ return;
+
client = nmtstc_nm_client_new ();
/*************************************/
@@ -720,6 +729,9 @@ test_devices_array (void)
GVariant *ret;
sinfo = nmtstc_service_init ();
+ if (!nmtstc_service_available (sinfo))
+ return;
+
client = nmtstc_nm_client_new ();
/*************************************/
@@ -820,7 +832,8 @@ manager_running_changed (GObject *client,
static void
test_client_manager_running (void)
{
- NMClient *client1, *client2;
+ gs_unref_object NMClient *client1 = NULL;
+ gs_unref_object NMClient *client2 = NULL;
guint quit_id;
int running_changed = 0;
GError *error = NULL;
@@ -842,6 +855,9 @@ test_client_manager_running (void)
/* Now start the test service. */
sinfo = nmtstc_service_init ();
+ if (!nmtstc_service_available (sinfo))
+ return;
+
client2 = nmtstc_nm_client_new ();
/* client2 should know that NM is running, but the previously-created
@@ -868,9 +884,6 @@ test_client_manager_running (void)
g_assert_cmpint (running_changed, ==, 2);
g_assert (!nm_client_get_manager_running (client1));
g_source_remove (quit_id);
-
- g_object_unref (client1);
- g_object_unref (client2);
}
/*****************************************************************************/
diff --git a/libnm-glib/tests/test-remote-settings-client.c b/libnm-glib/tests/test-remote-settings-client.c
index 0f3492981..031e83f81 100644
--- a/libnm-glib/tests/test-remote-settings-client.c
+++ b/libnm-glib/tests/test-remote-settings-client.c
@@ -70,6 +70,9 @@ test_add_connection (void)
time_t start, now;
gboolean done = FALSE;
+ if (!nmtstc_service_available (sinfo))
+ return;
+
connection = nm_connection_new ();
s_con = (NMSettingConnection *) nm_setting_connection_new ();
@@ -145,6 +148,9 @@ test_make_invisible (void)
gboolean done = FALSE, has_settings = FALSE;
char *path;
+ if (!nmtstc_service_available (sinfo))
+ return;
+
g_assert (remote != NULL);
/* Listen for the remove event when the connection becomes invisible */
@@ -212,6 +218,9 @@ test_make_visible (void)
char *path;
NMRemoteConnection *new = NULL;
+ if (!nmtstc_service_available (sinfo))
+ return;
+
g_assert (remote != NULL);
/* Wait for the new-connection signal when the connection is visible again */
@@ -292,6 +301,9 @@ test_remove_connection (void)
gboolean done = FALSE;
char *path;
+ if (!nmtstc_service_available (sinfo))
+ return;
+
/* Find a connection to delete */
list = nm_remote_settings_list_connections (settings);
g_assert_cmpint (g_slist_length (list), >, 0);
@@ -360,11 +372,14 @@ settings_service_running_changed (GObject *client,
static void
test_service_running (void)
{
- NMRemoteSettings *settings2;
+ gs_unref_object NMRemoteSettings *settings2 = NULL;
guint quit_id;
int running_changed = 0;
gboolean running;
+ if (!nmtstc_service_available (sinfo))
+ return;
+
loop = g_main_loop_new (NULL, FALSE);
g_object_get (G_OBJECT (settings),
@@ -403,6 +418,7 @@ test_service_running (void)
/* Now restart it */
sinfo = nmtstc_service_init ();
+ g_assert (nmtstc_service_available (sinfo));
quit_id = g_timeout_add_seconds (5, loop_quit, loop);
g_main_loop_run (loop);
@@ -413,8 +429,6 @@ test_service_running (void)
NM_REMOTE_SETTINGS_SERVICE_RUNNING, &running,
NULL);
g_assert (running == TRUE);
-
- g_object_unref (settings2);
}
/*****************************************************************************/