diff options
author | Simon McVittie <smcv@collabora.com> | 2017-06-02 12:22:59 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2017-06-08 17:00:38 +0100 |
commit | cc1ee6c39dafd8d5e24b94739131ecf4ef5c4c5b (patch) | |
tree | 2e8a4995f0004721b5d54c166bb80daca56addca /test | |
parent | bde40c8970d7e1314edc9f84d5bf55c7fc6d8e57 (diff) | |
download | dbus-cc1ee6c39dafd8d5e24b94739131ecf4ef5c4c5b.tar.gz |
test/dbus-daemon: Exercise the Peer interface
We have to skip the GetMachineId() part during build-time testing
if it wouldn't work - there is no guarantee that dbus has ever been
installed on the build system. However, we can insist on it during
installed-tests, if we make sure to complete the installation for the
Travis-CI build by running dbus-uuidgen.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101257
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 2 | ||||
-rw-r--r-- | test/dbus-daemon.c | 122 |
2 files changed, 124 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 5beb1b29..7c3f2ce1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -238,6 +238,7 @@ installcheck_environment = \ export DBUS_TEST_EXEC=@abs_top_builddir@/test; \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \ + export DBUS_TEST_UNINSTALLED=1; \ ${NULL} # Tests in bus/config-parser.c rely on these specific values for XDG_* and @@ -256,6 +257,7 @@ AM_TESTS_ENVIRONMENT = \ export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \ export DBUS_TEST_EXEC=@abs_top_builddir@/test; \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ + export DBUS_TEST_UNINSTALLED=1; \ $(NULL) manual_authz_SOURCES = manual-authz.c diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index 9f9dd723..8eeaa195 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -36,6 +36,8 @@ #include <glib/gstdio.h> #include <gio/gio.h> +#include "dbus/dbus-internals.h" +#include "dbus/dbus-string.h" #include "test-utils-glib.h" #include <string.h> @@ -1049,6 +1051,123 @@ test_pending_fd_timeout (Fixture *f, #endif static void +test_peer_get_machine_id (Fixture *f, + gconstpointer context) +{ + DBusString what_i_think; + const char *what_daemon_thinks; + DBusMessage *m = NULL; + DBusPendingCall *pc = NULL; + DBusError error = DBUS_ERROR_INIT; + DBusGUID uuid; + + if (f->skip) + return; + + /* Unlike dbus_get_local_machine_id(), this does not consider it to be + * a fatal error if dbus is not correctly installed, which is + * useful during build-time tests on a system where dbus might not be + * installed at all. */ + if (!_dbus_read_local_machine_uuid (&uuid, FALSE, &error)) + { + if (g_getenv ("DBUS_TEST_UNINSTALLED") != NULL) + { + /* When running unit tests during make check or make installcheck, + * tolerate this */ + g_test_skip ("Machine UUID not available"); + return; + } + else + { + /* When running integration tests, don't tolerate it */ + g_error ("dbus not installed correctly: machine UUID not available"); + } + } + + if (!_dbus_string_init (&what_i_think) || + !_dbus_uuid_encode (&uuid, &what_i_think)) + g_error ("OOM"); + + /* Check that the dbus-daemon agrees with us. */ + m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_PEER, + "GetMachineId"); + + if (m == NULL || + !dbus_connection_send_with_reply (f->left_conn, m, &pc, + DBUS_TIMEOUT_USE_DEFAULT) || + pc == NULL) + g_error ("OOM"); + + dbus_message_unref (m); + m = NULL; + + if (dbus_pending_call_get_completed (pc)) + test_pending_call_store_reply (pc, &m); + else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply, + &m, NULL)) + g_error ("OOM"); + + while (m == NULL) + test_main_context_iterate (f->ctx, TRUE); + + if (!dbus_message_get_args (m, &error, + DBUS_TYPE_STRING, &what_daemon_thinks, + DBUS_TYPE_INVALID)) + g_error ("%s: %s", error.name, error.message); + + g_assert_cmpstr (_dbus_string_get_const_data (&what_i_think), ==, + what_daemon_thinks); + g_assert_nonnull (what_daemon_thinks); + g_assert_cmpuint (strlen (what_daemon_thinks), ==, 32); + + dbus_message_unref (m); + dbus_pending_call_unref (pc); + _dbus_string_free (&what_i_think); +} + +static void +test_peer_ping (Fixture *f, + gconstpointer context) +{ + DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, DBUS_INTERFACE_PEER, "Ping"); + DBusPendingCall *pc = NULL; + DBusError error = DBUS_ERROR_INIT; + + if (f->skip) + return; + + m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, DBUS_INTERFACE_PEER, "Ping"); + + if (m == NULL || + !dbus_connection_send_with_reply (f->left_conn, m, &pc, + DBUS_TIMEOUT_USE_DEFAULT) || + pc == NULL) + g_error ("OOM"); + + dbus_message_unref (m); + m = NULL; + + if (dbus_pending_call_get_completed (pc)) + test_pending_call_store_reply (pc, &m); + else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply, + &m, NULL)) + g_error ("OOM"); + + while (m == NULL) + test_main_context_iterate (f->ctx, TRUE); + + if (!dbus_message_get_args (m, &error, DBUS_TYPE_INVALID)) + g_error ("%s: %s", error.name, error.message); + + dbus_message_unref (m); + dbus_pending_call_unref (pc); +} + +static void teardown (Fixture *f, gconstpointer context G_GNUC_UNUSED) { @@ -1197,6 +1316,9 @@ main (int argc, g_test_add ("/limits/max-names-per-connection", Fixture, &max_names_per_connection_config, setup, test_max_names_per_connection, teardown); + g_test_add ("/peer/ping", Fixture, NULL, setup, test_peer_ping, teardown); + g_test_add ("/peer/get-machine-id", Fixture, NULL, + setup, test_peer_get_machine_id, teardown); #if defined(DBUS_UNIX) && defined(HAVE_UNIX_FD_PASSING) && defined(HAVE_GIO_UNIX) g_test_add ("/limits/pending-fd-timeout", Fixture, |