diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2015-10-19 15:19:27 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2015-10-26 11:57:35 +0000 |
commit | 4eddd1bf52dd00dfc651f3aa3e2411d9d438ef51 (patch) | |
tree | f8083853df34288aba25f3efa7974d2540617d0f | |
parent | 382cb17d37e9098b2dcec6bc20b92467b63a7ae3 (diff) |
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.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92538
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
-rw-r--r-- | test/test-utils-glib.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index a40c30b7..e0849771 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); |