From 1e69d2f5a4d9abaf6d399e4f2379a77adcf83b7a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 19 Oct 2015 15:19:27 +0100 Subject: [PATCH 4/6] When running dbus-daemon --session in tests, override listen address Otherwise, we can't reliably run tests for Windows, because the default listening address on Windows is "autolaunch:" which is global to a machine, resulting in testing an installed dbus-daemon instead of the one we intended to test. --- test/test-utils-glib.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index a40c30b..e084977 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -93,22 +93,14 @@ child_setup (gpointer user_data) static gchar * spawn_dbus_daemon (const gchar *binary, const gchar *configuration, + const gchar *listen_address, TestUser user, GPid *daemon_pid) { GError *error = NULL; GString *address; gint address_fd; - const gchar *const argv[] = { - binary, - configuration, - "--nofork", - "--print-address=1", /* stdout */ -#ifdef DBUS_UNIX - "--systemd-activation", -#endif - NULL - }; + GPtrArray *argv; #ifdef DBUS_UNIX const struct passwd *pwd = NULL; #endif @@ -166,8 +158,23 @@ spawn_dbus_daemon (const gchar *binary, #endif } + argv = g_ptr_array_new_with_free_func (g_free); + g_ptr_array_add (argv, g_strdup (binary)); + g_ptr_array_add (argv, g_strdup (configuration)); + g_ptr_array_add (argv, g_strdup ("--nofork")); + g_ptr_array_add (argv, g_strdup ("--print-address=1")); /* stdout */ + + if (listen_address != NULL) + g_ptr_array_add (argv, g_strdup (listen_address)); + +#ifdef DBUS_UNIX + g_ptr_array_add (argv, g_strdup ("--systemd-activation")); +#endif + + g_ptr_array_add (argv, NULL); + g_spawn_async_with_pipes (NULL, /* working directory */ - (gchar **) argv, /* g_s_a_w_p() is not const-correct :-( */ + (gchar **) argv->pdata, NULL, /* envp */ G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, #ifdef DBUS_UNIX @@ -182,6 +189,8 @@ spawn_dbus_daemon (const gchar *binary, &error); g_assert_no_error (error); + g_ptr_array_free (argv, TRUE); + address = g_string_new (NULL); /* polling until the dbus-daemon writes out its address is a bit stupid, @@ -223,8 +232,14 @@ test_get_dbus_daemon (const gchar *config_file, { gchar *dbus_daemon; gchar *arg; + const gchar *listen_address = NULL; gchar *address; + /* we often have to override this because on Windows, the default may be + * autolaunch:, which is globally-scoped and hence unsuitable for + * regression tests */ + listen_address = "--address=" TEST_LISTEN; + if (config_file != NULL) { @@ -239,6 +254,10 @@ test_get_dbus_daemon (const gchar *config_file, arg = g_strdup_printf ( "--config-file=%s/%s", g_getenv ("DBUS_TEST_DATA"), config_file); + + /* The configuration file is expected to give a suitable address, + * do not override it */ + listen_address = NULL; } else if (g_getenv ("DBUS_TEST_DATADIR") != NULL) { @@ -276,7 +295,8 @@ test_get_dbus_daemon (const gchar *config_file, } else { - address = spawn_dbus_daemon (dbus_daemon, arg, user, daemon_pid); + address = spawn_dbus_daemon (dbus_daemon, arg, + listen_address, user, daemon_pid); } g_free (dbus_daemon); -- 2.6.1