summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-09-22 19:04:23 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-10-21 12:37:45 +0100
commit27b65f054da59f2ce660af6b1c3ecdc2647c07bd (patch)
tree500729588265c30769f8ce2856c3fdd61597302a
parentf3538c4210447c572aa82cb2eb0305ef7f70b2b3 (diff)
downloaddbus-glib-27b65f054da59f2ce660af6b1c3ecdc2647c07bd.tar.gz
Separate the test for shared-bus equivalence into its own binary
When valgrinding tests it's useful to avoid using the shared bus, which cannot be closed. Move all the essential shared-bus use into a test which can be treated specially. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41129 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r--.gitignore1
-rw-r--r--test/core/Makefile.am6
-rwxr-xr-xtest/core/run-test.sh1
-rw-r--r--test/core/shared-bus.c135
-rw-r--r--test/core/test-dbus-glib.c5
5 files changed, 142 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index fc19cfb..c77c252 100644
--- a/.gitignore
+++ b/.gitignore
@@ -209,6 +209,7 @@ test/core/test-proxy-peer
test/core/test-service-glib
test/core/test-service-glib-bindings.h
test/core/test-service-glib-glue.h
+/test/core/test-shared-bus
test/core/test-thread-client
test/core/test-thread-server
test/core/test-types
diff --git a/test/core/Makefile.am b/test/core/Makefile.am
index 700120d..5bc9952 100644
--- a/test/core/Makefile.am
+++ b/test/core/Makefile.am
@@ -63,7 +63,9 @@ noinst_PROGRAMS = \
test-proxy-peer \
test-registrations \
test-variant-recursion \
- test-gvariant
+ test-gvariant \
+ test-shared-bus \
+ $(NULL)
test_30574_SOURCES = \
30574.c
@@ -156,6 +158,8 @@ test_gvariant_SOURCES = \
test_peer_on_bus_SOURCES = peer-on-bus.c
+test_shared_bus_SOURCES = shared-bus.c
+
CLEANFILES = \
$(BUILT_SOURCES) \
run-with-tmp-session-bus.conf
diff --git a/test/core/run-test.sh b/test/core/run-test.sh
index dbc35f7..fe4dc21 100755
--- a/test/core/run-test.sh
+++ b/test/core/run-test.sh
@@ -43,6 +43,7 @@ else
if test x$DBUS_TEST_MONITOR != x; then
dbus-monitor --session &
fi
+ ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-shared-bus || die "test-shared-bus failed"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-types || die "test-types failed"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-registrations || die "test-registrations failed"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-dbus-glib || die "test-dbus-glib failed"
diff --git a/test/core/shared-bus.c b/test/core/shared-bus.c
new file mode 100644
index 0000000..0ab575c
--- /dev/null
+++ b/test/core/shared-bus.c
@@ -0,0 +1,135 @@
+/* Regression test for the shared bus instance.
+ * This test is expected to "leak" the shared connection.
+ *
+ * Copyright © 2006-2010 Red Hat, Inc.
+ * Copyright © 2006-2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright © 2011 Nokia Corporation
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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 of the License, 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
+ */
+
+#include <config.h>
+
+#include <glib.h>
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+GMainLoop *loop = NULL;
+
+typedef struct {
+ DBusGConnection *bus;
+ DBusGConnection *priv;
+ GError *error;
+} Fixture;
+
+static void
+destroy_cb (DBusGProxy *proxy G_GNUC_UNUSED,
+ gpointer user_data)
+{
+ gboolean *disconnected = user_data;
+
+ *disconnected = TRUE;
+}
+
+static void
+disconnect (DBusGConnection **bus)
+{
+ DBusGProxy *proxy;
+ gboolean disconnected = FALSE;
+
+ g_printerr ("Disconnecting... ");
+
+ dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (*bus),
+ FALSE);
+ proxy = dbus_g_proxy_new_for_peer (*bus, "/",
+ "org.freedesktop.DBus.Peer");
+ g_signal_connect (G_OBJECT (proxy), "destroy", G_CALLBACK (destroy_cb),
+ &disconnected);
+
+ dbus_connection_close (dbus_g_connection_get_connection (*bus));
+
+ while (!disconnected)
+ {
+ g_printerr (".");
+ g_main_context_iteration (NULL, TRUE);
+ }
+
+ g_signal_handlers_disconnect_by_func (proxy, destroy_cb, &disconnected);
+ g_object_unref (proxy);
+ dbus_g_connection_unref (*bus);
+ *bus = NULL;
+
+ g_printerr (" disconnected\n");
+}
+
+static void
+setup (Fixture *f,
+ gconstpointer test_data G_GNUC_UNUSED)
+{
+}
+
+static void
+teardown (Fixture *f,
+ gconstpointer test_data G_GNUC_UNUSED)
+{
+ if (f->bus != NULL)
+ dbus_g_connection_unref (f->bus);
+
+ if (f->priv != NULL)
+ disconnect (&f->priv);
+
+ g_clear_error (&f->error);
+ dbus_shutdown ();
+}
+
+static void
+test_shared_bus (Fixture *f,
+ gconstpointer test_data G_GNUC_UNUSED)
+{
+ f->bus = dbus_g_bus_get (DBUS_BUS_SESSION, &f->error);
+ g_assert_no_error (f->error);
+ g_assert (f->bus != NULL);
+ dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (f->bus),
+ FALSE);
+
+ g_assert (f->bus == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
+ g_assert (f->bus == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
+ g_assert (f->bus == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
+
+ f->priv = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, &f->error);
+ g_assert_no_error (f->error);
+ g_assert (f->priv != NULL);
+ g_assert (f->priv != f->bus);
+ dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (f->priv),
+ FALSE);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_type_init ();
+ g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add ("/shared-bus", Fixture, NULL, setup, test_shared_bus,
+ teardown);
+
+ return g_test_run ();
+}
diff --git a/test/core/test-dbus-glib.c b/test/core/test-dbus-glib.c
index ffc2ae9..1b8c3fc 100644
--- a/test/core/test-dbus-glib.c
+++ b/test/core/test-dbus-glib.c
@@ -549,11 +549,6 @@ main (int argc, char **argv)
if (connection == NULL)
lose_gerror ("Failed to open connection to bus", error);
- /* should always get the same one */
- g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
- g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
- g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
-
/* Create a proxy object for the "bus driver" */
driver = dbus_g_proxy_new_for_name (connection,