[telepathy-mission-control/refs/tags/5.0.beta64] test/twisted: run a modified build of MC that exits gracefully

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Mar 26 08:20:00 PDT 2009


The normal mc-server exits via _exit() when disconnected from D-Bus. This
doesn't run atexit handlers, which is undesirable when using gcov for
targeted testing.

Also use libtool correctly when invoking the modified build, and add a
template test that doesn't do anything.
---
 .gitignore                             |    1 +
 test/twisted/Makefile.am               |   19 +++++-
 test/twisted/do-nothing.py             |    8 ++
 test/twisted/mc-debug-server.c         |  119 ++++++++++++++++++++++++++++++++
 test/twisted/tools/exec-with-log.sh.in |    4 +-
 5 files changed, 148 insertions(+), 3 deletions(-)
 create mode 100644 test/twisted/do-nothing.py
 create mode 100644 test/twisted/mc-debug-server.c

diff --git a/.gitignore b/.gitignore
index 57f5e60..bc8dae3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,6 +70,7 @@ tags
 test/mc-client
 test/twisted/with-session-bus-*.dbus-monitor-logs
 test/twisted/accounts/accounts.cfg
+/test/twisted/mc-debug-server
 test/twisted/tools/exec-with-log.sh
 test/twisted/tools/missioncontrol-testing.log
 test/twisted/tools/org.freedesktop.Telepathy.MissionControl.service
diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index d002005..603d6e2 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -1,8 +1,23 @@
 TWISTED_TESTS =
 
 TWISTED_BASIC_TESTS = \
-        test-account.py \
-        test-connect.py
+	do-nothing.py \
+	test-account.py \
+	test-connect.py
+
+# A debug version of the normal MC executable, which exits cleanly on
+# disconnection from D-Bus (so gcov info gets written out)
+noinst_PROGRAMS = mc-debug-server
+mc_debug_server_SOURCES = mc-debug-server.c
+mc_debug_server_LDADD = $(top_builddir)/src/libmissioncontrol-server.la
+
+INCLUDES = \
+	-I$(top_srcdir) -I$(top_builddir) \
+	-I$(top_srcdir)/src -I$(top_builddir)/src \
+	$(DBUS_CFLAGS) \
+	$(TELEPATHY_CFLAGS) \
+	-DMC_DISABLE_DEPRECATED \
+	-DLIBDIR="@libdir@" -DLIBVERSION="0"
 
 TESTS =
 
diff --git a/test/twisted/do-nothing.py b/test/twisted/do-nothing.py
new file mode 100644
index 0000000..f874017
--- /dev/null
+++ b/test/twisted/do-nothing.py
@@ -0,0 +1,8 @@
+from mctest import exec_test
+
+def test(q, bus, mc):
+    pass
+
+
+if __name__ == '__main__':
+    exec_test(test, {})
diff --git a/test/twisted/mc-debug-server.c b/test/twisted/mc-debug-server.c
new file mode 100644
index 0000000..64d79ab
--- /dev/null
+++ b/test/twisted/mc-debug-server.c
@@ -0,0 +1,119 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 8 -*- */
+/*
+ * This file is part of mission-control
+ *
+ * Copyright (C) 2007 Nokia Corporation. 
+ *
+ * Contact: Naba Kumar  <naba.kumar at nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include <telepathy-glib/debug.h>
+#include <telepathy-glib/util.h>
+
+#include "mcd-service.h"
+
+
+static void
+on_abort (McdService * mcd)
+{
+    g_debug ("Exiting now ...");
+
+    mcd_debug_print_tree (mcd);
+
+    g_object_unref (mcd);
+    g_debug ("MC now exits .. bye bye");
+    exit (0);
+}
+
+static DBusHandlerResult
+dbus_filter_function (DBusConnection *connection,
+                      DBusMessage *message,
+                      void *user_data)
+{
+  if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
+      !tp_strdiff (dbus_message_get_path (message), DBUS_PATH_LOCAL))
+    {
+      g_message ("Got disconnected from the session bus");
+      exit (69); /* EX_UNAVAILABLE */
+    }
+
+  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+int
+main (int argc, char **argv)
+{
+    TpDBusDaemon *bus_daemon = NULL;
+    McdService *mcd = NULL;
+    GError *error = NULL;
+    DBusConnection *connection;
+    int ret = 1;
+
+    g_type_init ();
+
+    tp_debug_set_flags (g_getenv ("MC_TP_DEBUG"));
+
+    bus_daemon = tp_dbus_daemon_dup (&error);
+
+    if (bus_daemon == NULL)
+    {
+        g_warning ("%s", error->message);
+        g_error_free (error);
+        error = NULL;
+        goto out;
+    }
+
+    /* It appears that dbus-glib registers a filter that wrongly returns
+     * DBUS_HANDLER_RESULT_HANDLED for signals, so for *our* filter to have any
+     * effect, we need to install it as soon as possible */
+    connection = dbus_g_connection_get_connection (
+        ((TpProxy *) bus_daemon)->dbus_connection);
+    dbus_connection_add_filter (connection, dbus_filter_function, NULL, NULL);
+
+    mcd = mcd_service_new ();
+
+    /* Listen for suicide notification */
+    g_signal_connect_after (mcd, "abort", G_CALLBACK (on_abort), mcd);
+
+    /* connect */
+    mcd_mission_connect (MCD_MISSION (mcd));
+
+    /* MC initialization sets exit on disconnect - turn it off again, so we
+     * get a graceful exit from the above handler instead (to keep gcov
+     * happy) */
+    dbus_connection_set_exit_on_disconnect (connection, FALSE);
+
+    mcd_service_run (MCD_OBJECT (mcd));
+
+    ret = 0;
+
+out:
+    if (bus_daemon != NULL)
+    {
+        g_object_unref (bus_daemon);
+    }
+
+    return ret;
+}
diff --git a/test/twisted/tools/exec-with-log.sh.in b/test/twisted/tools/exec-with-log.sh.in
index 48f77d2..56eb69d 100644
--- a/test/twisted/tools/exec-with-log.sh.in
+++ b/test/twisted/tools/exec-with-log.sh.in
@@ -44,4 +44,6 @@ if [ -e "@abs_top_builddir@/test/twisted/accounts/accounts.cfg" ] ; then
         exit 1
 fi
 
-exec $MISSIONCONTROL_WRAPPER @abs_top_builddir@/server/mission-control
+exec @abs_top_builddir@/libtool --mode=execute \
+        $MISSIONCONTROL_WRAPPER \
+        @abs_top_builddir@/test/twisted/mc-debug-server
-- 
1.5.6.5




More information about the telepathy-commits mailing list