summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2013-11-19 00:33:29 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2014-02-16 23:52:32 +0000
commitecfe72ef925a9e561d9a6c94ba7bac12eede550e (patch)
treed04c0937bb9ee2de77b94c7cae8a245f40c79155
parent919a6dc73ed9717f5d2696dcf1d753cb5a789851 (diff)
tracker: Move with-session-bus-tracker.sh into test-case.vala
Eliminate the last bits of shell scripting from the test suites. Instead of starting and stopping the Tracker services through tracker-control, the Tracker services are now started through D-Bus activation, and die when the mock D-Bus bus is destroyed.
-rw-r--r--tests/lib/eds/test-case.vala2
-rw-r--r--tests/lib/telepathy/Makefile.am8
-rw-r--r--tests/lib/test-case.vala6
-rw-r--r--tests/lib/tracker/test-case.vala66
-rw-r--r--tests/tools/Makefile.am4
-rw-r--r--tests/tools/dbus-session.sh119
-rw-r--r--tests/tools/tracker.sh34
-rwxr-xr-xtests/tools/with-session-bus-tracker.sh48
-rwxr-xr-xtests/tools/with-session-bus.sh42
-rw-r--r--tests/tracker/Makefile.am11
10 files changed, 57 insertions, 283 deletions
diff --git a/tests/lib/eds/test-case.vala b/tests/lib/eds/test-case.vala
index 4422aad9..bc36d449 100644
--- a/tests/lib/eds/test-case.vala
+++ b/tests/lib/eds/test-case.vala
@@ -55,7 +55,7 @@ public class EdsTest.TestCase : Folks.TestCase
true);
}
- public override string? create_transient_dir ()
+ public override string create_transient_dir ()
{
var transient = base.create_transient_dir ();
diff --git a/tests/lib/telepathy/Makefile.am b/tests/lib/telepathy/Makefile.am
index 159073b0..be716c0e 100644
--- a/tests/lib/telepathy/Makefile.am
+++ b/tests/lib/telepathy/Makefile.am
@@ -21,6 +21,7 @@ libtpf_test_la_VALAFLAGS = \
--vapidir=$(abs_top_builddir)/tests/lib \
--vapidir=$(abs_top_srcdir)/tests/lib/key-file \
--vapidir=$(abs_top_builddir)/tests/lib/key-file \
+ --pkg build-conf \
--pkg folks-test \
--pkg kf-test \
--pkg tp-test-contactlist \
@@ -33,7 +34,14 @@ libtpf_test_la_SOURCES = \
libtpf_test_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/folks \
+ -include $(CONFIG_HEADER) \
-include $(top_srcdir)/folks/warnings.h \
+ -DABS_TOP_SRCDIR=\"${abs_top_srcdir}\" \
+ -DABS_TOP_BUILDDIR=\"${abs_top_builddir}\" \
+ -DPKGLIBEXECDIR=\"${pkglibexecdir}\" \
+ -DPACKAGE_DATADIR=\"${pkgdatadir}\" \
$(NULL)
libtpf_test_la_CFLAGS = \
diff --git a/tests/lib/test-case.vala b/tests/lib/test-case.vala
index 2b512456..febc251e 100644
--- a/tests/lib/test-case.vala
+++ b/tests/lib/test-case.vala
@@ -123,12 +123,8 @@ public abstract class Folks.TestCase : Object
*
* Subclasses may override this method to do additional setup
* (create more subdirectories or set more environment variables).
- *
- * FIXME: Subclasses relying on being called by with-session-bus-*.sh
- * may override this method to return null, although we should really
- * stop doing that.
*/
- public virtual string? create_transient_dir ()
+ public virtual string create_transient_dir ()
{
unowned string tmp = Environment.get_tmp_dir ();
string transient = "%s/folks-test.XXXXXX".printf (tmp);
diff --git a/tests/lib/tracker/test-case.vala b/tests/lib/tracker/test-case.vala
index 3a1acd37..fd0df80b 100644
--- a/tests/lib/tracker/test-case.vala
+++ b/tests/lib/tracker/test-case.vala
@@ -26,8 +26,8 @@
* Folks is configured to use the Tracker backend as primary store,
* and no other backends.
*
- * FIXME: For now, this relies on running under with-session-bus-tracker.sh
- * with FOLKS_BACKEND_PATH set.
+ * This uses tracker-control to start and stop Tracker services on a private
+ * D-Bus bus.
*/
public class TrackerTest.TestCase : Folks.TestCase
{
@@ -47,14 +47,6 @@ public class TrackerTest.TestCase : Folks.TestCase
*/
public TestCase (string name)
{
- /* This variable is set in the same place as the various variables we
- * care about for sandboxing purposes, like XDG_CONFIG_HOME and
- * DBUS_SESSION_BUS_ADDRESS. */
- if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS")
- != "tracker")
- error ("Tracker tests must be run in a private D-Bus session " +
- "with Tracker services");
-
base (name);
Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "tracker", true);
@@ -63,17 +55,53 @@ public class TrackerTest.TestCase : Folks.TestCase
this.tracker_backend = new TrackerTest.Backend ();
}
- public override string? create_transient_dir ()
- {
- /* Don't do anything. We're currently relying on
- * being wrapped in with-session-bus-tracker.sh. */
- return null;
- }
-
public override void private_bus_up ()
{
- /* Don't do anything. We're currently relying on
- * being wrapped in with-session-bus-tracker.sh. */
+ base.private_bus_up ();
+
+ /* Find out the libexec directory to use. */
+ int exit_status = -1;
+ string capture_stdout = null;
+
+ try
+ {
+ Process.spawn_sync (null /* cwd */,
+ { "pkg-config", "--variable=prefix", "tracker-miner-1.0" },
+ null /* envp */,
+ SpawnFlags.SEARCH_PATH /* flags */,
+ null /* child setup */,
+ out capture_stdout,
+ null /* do not capture stderr */,
+ out exit_status);
+
+ Process.check_exit_status (exit_status);
+ }
+ catch (GLib.Error e1)
+ {
+ error ("Error getting libexecdir from pkg-config: %s", e1.message);
+ }
+
+ /* FIXME: There really should be a libexec variable in the pkg-config
+ * file. */
+ var libexec = capture_stdout.strip () + "/libexec";
+
+ /* Create service files for the Tracker binaries. */
+ var service_file_name =
+ Path.build_filename (this.transient_dir, "dbus-1", "services",
+ "org.freedesktop.Tracker1.service");
+ var service_file = ("[D-BUS Service]\n" +
+ "Name=org.freedesktop.Tracker1\n" +
+ "Exec=%s/tracker-store\n").printf (libexec);
+
+ try
+ {
+ FileUtils.set_contents (service_file_name, service_file);
+ }
+ catch (FileError e2)
+ {
+ error ("Error creating D-Bus service file ā€˜%sā€™: %s",
+ service_file_name, e2.message);
+ }
}
public override void tear_down ()
diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am
index 11ab1593..542e5a28 100644
--- a/tests/tools/Makefile.am
+++ b/tests/tools/Makefile.am
@@ -1,9 +1,5 @@
EXTRA_DIST = \
- with-session-bus.sh \
- dbus-session.sh \
manager-file.py \
- with-session-bus-tracker.sh \
- tracker.sh \
$(NULL)
-include $(top_srcdir)/git.mk
diff --git a/tests/tools/dbus-session.sh b/tests/tools/dbus-session.sh
deleted file mode 100644
index 35c09d40..00000000
--- a/tests/tools/dbus-session.sh
+++ /dev/null
@@ -1,119 +0,0 @@
-#
-# Helper functions to start your own D-Bus session.
-#
-# Refactored from with-session-bush.sh (from telepathy-glib).
-#
-# The canonical location of this program is the telepathy-glib tools/
-# directory, please synchronize any changes with that copy.
-#
-# Copyright (C) 2007-2008,2011 Collabora Ltd. <http://www.collabora.co.uk/>
-#
-# Copying and distribution of this file, with or without modification,
-# are permitted in any medium without royalty provided the copyright
-# notice and this notice are preserved.
-
-
-dbus_daemon_args="--print-address=5 --print-pid=6 --fork"
-dbus_verbose=0
-dbus_me=with-session-bus
-dbus_sleep=0
-dbus_with_session=""
-dbus_config_file=""
-
-# Params:
-# verbose: 0 for off and 1 for on
-#
-dbus_init () {
- unset DBUS_SESSION_BUS_ADDRESS
- unset DBUS_SESSION_BUS_PID
- unset DBUS_STARTER_ADDRESS
- unset DBUS_STARTER_BUS_TYPE
-
- exec 5> $dbus_me-$$.address
- exec 6> $dbus_me-$$.pid
- dbus_verbose=$1
-}
-
-dbus_usage ()
-{
- echo "usage: $me [options] -- program [program_options]" >&2
- echo "Requires write access to the current directory." >&2
- echo "" >&2
- echo "If \$WITH_SESSION_BUS_FORK_DBUS_MONITOR is set, fork dbus-monitor" >&2
- echo "with the arguments in \$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT." >&2
- echo "The output of dbus-monitor is saved in $me-<pid>.dbus-monitor-logs" >&2
- exit 2
-}
-
-dbus_parse_args () {
- while test "z$1" != "z--"; do
- case "$1" in
- --sleep=*)
- sleep="$1"
- dbus_sleep="${sleep#--sleep=}"
- shift
- ;;
- --session)
- dbus_with_session="--session"
- shift
- ;;
- --config-file=*)
- # FIXME: assumes config file doesn't contain any special characters
- dbus_config_file="$1"
- shift
- ;;
- *)
- dbus_usage
- ;;
- esac
- done
-}
-
-dbus_start () {
- local args="$dbus_daemon_args $dbus_with_session $dbus_config_file "
-
- if [ $dbus_verbose -gt 0 ] ; then
- echo -n "dbus args $args "
- fi
-
- dbus-daemon $args
-
- {
- if [ $dbus_verbose -gt 0 ] ; then
- echo -n "Temporary bus daemon is "; cat $dbus_me-$$.address;
- fi
- } >&2
-
- {
- if [ $dbus_verbose -gt 0 ] ; then
- echo -n "Temporary bus daemon PID is "; head -n1 $dbus_me-$$.pid;
- fi
- } >&2
-
- DBUS_SESSION_BUS_ADDRESS="`cat $dbus_me-$$.address`"
- export DBUS_SESSION_BUS_ADDRESS
-
- if [ -n "$WITH_SESSION_BUS_FORK_DBUS_MONITOR" ] ; then
- if [ $dbus_verbose -gt 0 ] ; then
- echo -n "Forking dbus-monitor " \
- "$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT" >&2
- fi
- dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT \
- > $dbus_me-$$.dbus-monitor-logs 2>&1 &
- fi
-}
-
-#
-# This should be called for INT, HUP and TERM signals
-#
-dbus_stop () {
- pid=`head -n1 $dbus_me-$$.pid`
- if test -n "$pid" ; then
- if [ $dbus_verbose -gt 0 ] ; then
- echo "Killing temporary bus daemon: $pid" >&2
- fi
- kill -INT "$pid"
- fi
- rm -f $dbus_me-$$.address
- rm -f $dbus_me-$$.pid
-}
diff --git a/tests/tools/tracker.sh b/tests/tools/tracker.sh
deleted file mode 100644
index dbe91b46..00000000
--- a/tests/tools/tracker.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Helper functions to start your own Tracker instance. This depends
-# on you having your own D-Bus session bus started (first).
-#
-#
-# Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
-#
-# Copying and distribution of this file, with or without modification,
-# are permitted in any medium without royalty provided the copyright
-# notice and this notice are preserved.
-
-tracker_tmpdir=$(mktemp -d)
-
-tracker_init_settings () {
- export XDG_DATA_HOME=$tracker_tmpdir/.local
- export XDG_CACHE_HOME=$tracker_tmpdir/.cache
- export XDG_CONFIG_HOME=$tracker_tmpdir/.config
-}
-
-# This should be called on INT TERM and EXIT
-tracker_cleanup () {
- rm -rf $tracker_tmpdir
- rm -rf $tracker_tmpdir
-}
-
-tracker_start () {
- tracker-control -r > /dev/null 2>&1
-}
-
-tracker_stop () {
- tracker_cleanup
- tracker-control -r > /dev/null 2>&1
-}
-
diff --git a/tests/tools/with-session-bus-tracker.sh b/tests/tools/with-session-bus-tracker.sh
deleted file mode 100755
index cf1a8f38..00000000
--- a/tests/tools/with-session-bus-tracker.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-# with-session-bus.sh - run a program with a temporary D-Bus session daemon
-#
-# interesting bits have been move into dbus to permit reusability
-#
-# Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/>
-#
-# Copying and distribution of this file, with or without modification,
-# are permitted in any medium without royalty provided the copyright
-# notice and this notice are preserved.
-
-
-cur_dir=`dirname $0`
-
-. $cur_dir"/dbus-session.sh"
-. $cur_dir"/tracker.sh"
-
-dbus_parse_args $@
-while test "z$1" != "z--"; do
- shift
-done
-shift
-if test "z$1" = "z"; then dbus_usage; fi
-
-cleanup ()
-{
- tracker_stop
- dbus_stop
-}
-
-trap cleanup INT HUP TERM
-
-tracker_init_settings
-dbus_init 0
-
-dbus_start
-tracker_start
-
-FOLKS_TESTS_SANDBOXED_DBUS=tracker
-export FOLKS_TESTS_SANDBOXED_DBUS
-
-e=0
-"$@" || e=$?
-
-trap - INT HUP TERM
-cleanup
-
-exit $e
diff --git a/tests/tools/with-session-bus.sh b/tests/tools/with-session-bus.sh
deleted file mode 100755
index 43585350..00000000
--- a/tests/tools/with-session-bus.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/sh
-# with-session-bus.sh - run a program with a temporary D-Bus session daemon
-#
-# interesting bits have been move into dbus to permit reusability
-#
-# Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/>
-#
-# Copying and distribution of this file, with or without modification,
-# are permitted in any medium without royalty provided the copyright
-# notice and this notice are preserved.
-
-
-cur_dir=`dirname $0`
-
-. $cur_dir"/dbus-session.sh"
-
-dbus_parse_args $@
-while test "z$1" != "z--"; do
- shift
-done
-shift
-if test "z$1" = "z"; then dbus_usage; fi
-
-cleanup ()
-{
- dbus_stop
-}
-
-trap cleanup INT HUP TERM
-
-dbus_init 0
-dbus_start
-
-FOLKS_TESTS_SANDBOXED_DBUS=no-services
-export FOLKS_TESTS_SANDBOXED_DBUS
-
-"$@" || e=$?
-
-trap - INT HUP TERM
-cleanup
-
-exit $e
diff --git a/tests/tracker/Makefile.am b/tests/tracker/Makefile.am
index 0882260e..c8d481f7 100644
--- a/tests/tracker/Makefile.am
+++ b/tests/tracker/Makefile.am
@@ -36,8 +36,6 @@ LDADD = \
-L$(top_srcdir)/backends/tracker/lib \
$(NULL)
-RUN_WITH_PRIVATE_BUS = $(top_srcdir)/tests/tools/with-session-bus-tracker.sh
-
# in order from least to most complex
noinst_PROGRAMS = \
individual-retrieval \
@@ -100,10 +98,6 @@ noinst_PROGRAMS = \
set-null-avatar \
$(NULL)
-TESTS_ENVIRONMENT = \
- $(RUN_WITH_PRIVATE_BUS) \
- --session \
- --
TESTS = $(noinst_PROGRAMS)
individual_retrieval_SOURCES = \
@@ -338,11 +332,6 @@ set_null_avatar_SOURCES = \
set-null-avatar.vala \
$(NULL)
-CLEANFILES = \
- *.pid \
- *.address \
- $(NULL)
-
-include $(top_srcdir)/git.mk
-include $(top_srcdir)/check.mk
-include $(top_srcdir)/valgrind.mk