[gjs] Add run-with-dbus to gtester invocation.



commit 5374f31b37b0a146d1d0fac8a5bd4bc1200c90f6
Author: C. Scott Ananian <cscott litl com>
Date:   Fri Jun 5 13:53:38 2009 -0400

    Add run-with-dbus to gtester invocation.
    
    This allows 'make check' to use an independent dbus instance, so that
    (a) headless buildbots can successfully make check, and (b) this test
    is decoupled from details of the user's desktop environment.
    
    The run-with-dbus code originally written by Havoc Pennington <hp pobox com>,
    Tommi Komulainen <tko litl com>, Xan López <xan litl com>,
    Johan Bilien <jobi litl com>, and Marco Pesenti Gritti <marcopg litl com>
    for Litl, LLC.
---
 .gitignore         |    7 ++
 Makefile-test.am   |   24 +++++--
 test/run-with-dbus |  185 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/test-bus.conf |   43 ++++++++++++
 4 files changed, 254 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore
index ff83eee..72a2b2c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,8 @@
 *.la
 *.lo
 *.o
+*.gir
+*.typelib
 .deps/
 .libs/
 INSTALL
@@ -21,6 +23,8 @@ gjs-1.0.pc
 gjs-console
 gjs-dbus-1.0.pc
 gjs-gi-1.0.pc
+gjs-tests
+gjs-unit
 gjstest.c
 gjstest.c.stamp
 gjstest.h
@@ -30,3 +34,6 @@ libtool
 ltmain.sh
 missing
 stamp-h1
+test_user_data
+uninstalled-test-bus.conf
+uninstalled-system-test-bus.conf
diff --git a/Makefile-test.am b/Makefile-test.am
index 42d0073..6143925 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -1,4 +1,5 @@
-GTESTER = ${TESTS_ENVIRONMENT} gtester
+RUN_WITH_DBUS = ${top_srcdir}/test/run-with-dbus --session --system
+GTESTER = ${TESTS_ENVIRONMENT} ${RUN_WITH_DBUS} gtester
 
 ########################################################################
 TEST_PROGS += gjs-tests
@@ -64,6 +65,11 @@ EXTRA_DIST +=			\
 ########################################################################
 TESTS_ENVIRONMENT =				\
 	abs_top_srcdir="$(abs_top_srcdir)"	\
+	DBUS_SESSION_BUS_ADDRESS=''			\
+	XDG_DATA_HOME=$(abs_top_builddir)/test_user_data \
+        GJS_DEBUG_OUTPUT=$(builddir)/test_user_data/logs/gjs.log    \
+	BUILDDIR=$(abs_top_builddir)			\
+	GJS_USE_UNINSTALLED_FILES=1			\
 	LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):$(FIREFOX_JS_LIBDIR)"	\
 	G_FILENAME_ENCODING=latin1	# ensure filenames are not utf8
 
@@ -96,14 +102,20 @@ valgrind-check valgrind-test: $(gjsnative_LTLIBRARIES) ${TEST_PROGS}
 	    echo "valgrind failed for:$$failed"; exit 1; \
 	  }; \
 	}
-CLEANFILES += $(TEST_PROGS:%=valgrind.%.log)
+CLEANFILES +=					\
+	$(TEST_PROGS:%=valgrind.%.log)		\
+	uninstalled-test-bus.conf		\
+	uninstalled-system-test-bus.conf
+
+clean-local:
+	-rm -rf test_user_data
 
 EXTRA_DIST +=					\
 	test/js/modules/jsUnit.js		\
 	test/js/modules/alwaysThrows.js         \
 	test/js/modules/foobar.js               \
- 	test/js/modules/mutualImport/a.js       \
- 	test/js/modules/mutualImport/b.js       \
+	test/js/modules/mutualImport/a.js       \
+	test/js/modules/mutualImport/b.js       \
 	test/js/modules/subA/.secret.js         \
 	test/js/modules/subA/.hidden/hidden.js  \
 	test/js/modules/subA/foo                \
@@ -120,7 +132,9 @@ EXTRA_DIST +=					\
 	test/js/testLocale.js			\
 	test/js/testMainloop.js			\
 	test/js/testSignals.js			\
-	test/js/testTweener.js
+	test/js/testTweener.js			\
+	test/run-with-dbus			\
+	test/test-bus.conf
 
 ########################################################################
 if ENABLE_COVERAGE
diff --git a/test/run-with-dbus b/test/run-with-dbus
new file mode 100755
index 0000000..c8238f0
--- /dev/null
+++ b/test/run-with-dbus
@@ -0,0 +1,185 @@
+#! /bin/sh
+# Copyright 2008-2009 litl, LLC. All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+SCRIPTNAME=$0
+START_SYSTEM_BUS=
+START_SESSION_BUS=
+
+done=0
+
+while [ "$done" != 1 ]; do
+    case $1 in
+        --system )
+            START_SYSTEM_BUS=1
+            ;;
+        --session)
+            START_SESSION_BUS=1
+            ;;
+        * )
+            WRAPPED_SCRIPT=$1
+            done=1
+            ;;
+    esac
+    shift
+done
+
+if ! test -z "$GJS_FORCE_FAKE_SYSTEM_BUS" ; then
+    echo "Forcing fake system bus"
+    START_SYSTEM_BUS=1
+fi
+
+die()
+{
+    if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+        echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
+        kill -9 $DBUS_SESSION_BUS_PID
+    fi
+
+    if ! test -z "$DBUS_SYSTEM_BUS_PID" ; then
+        echo "killing message bus "$DBUS_SYSTEM_BUS_PID >&2
+        kill -9 $DBUS_SYSTEM_BUS_PID
+    fi
+
+    echo $SCRIPTNAME: $* >&2
+    exit 1
+}
+
+## convenient to be able to ctrl+C without leaking the message bus process
+trap 'die "Received terminal signal"' INT TERM HUP
+
+TOP_SRCDIR="${TOP_SRCDIR:-$abs_top_srcdir}"
+if test -z "$TOP_SRCDIR" ; then
+    die "Must set TOP_SRCDIR or abs_top_srcdir"
+fi
+
+if test -z "$BUILDDIR" ; then
+    die "Must set BUILDDIR"
+fi
+
+RANDOM=`uuidgen -r | cut -d '-' -f 3`
+
+## this has to be set BEFORE we start session bus,
+## or stuff the session bus starts won't get it
+if ! test -z "$START_SYSTEM_BUS" ; then
+    DBUS_SYSTEM_BUS_ADDRESS="unix:abstract=/tmp/dbus-$USER-$$-$RANDOM-system"
+    export DBUS_SYSTEM_BUS_ADDRESS
+fi
+
+STDERR_LOGFILE="$BUILDDIR"/stderr.log
+if test x"$XDG_DATA_HOME" != x ; then
+    mkdir -p "$XDG_DATA_HOME"/logs || exit 1
+    STDERR_LOGFILE="$XDG_DATA_HOME"/logs/stderr.log
+fi
+/bin/rm -f "$STDERR_LOGFILE"
+SYSTEM_MONITOR_LOGFILE=`echo "$STDERR_LOGFILE" | sed -e s/stderr.log/dbus-system.log/g`
+
+if ! test -z "$START_SESSION_BUS" ; then
+    CONFIG_FILE="$TOP_SRCDIR"/test/test-bus.conf
+
+    if test x"$GJS_USE_UNINSTALLED_FILES" != x ; then
+        NEW_CONFIG_FILE="$BUILDDIR"/uninstalled-test-bus.conf
+
+        SED_RULE="s@<type>session</type>@<type>session</type><standard_session_servicedirs/><servicedir>$PWD/test-services/</servicedir>@"
+
+        if test x"$GJS_USE_FIXED_DBUS_ADDRESS" != x ; then
+            # use fixed path (unix:abstract=/tmp/dbus-$USER-$DISPLAY) for session bus for
+            # easy access across shells
+            # (DISPLAY without ':' as dbus doesn't like it unescaped)
+            SED_RULE="$SED_RULE;s@<listen>.*</listen>@<listen>unix:abstract=/tmp/dbus-$USER-${DISPLAY#:}</listen>@"
+        else
+            SED_RULE="$SED_RULE;s@<listen>.*</listen>@<listen>unix:abstract=/tmp/dbus-$USER-$$-$RANDOM</listen>@"
+        fi
+        sed -e "$SED_RULE" "$CONFIG_FILE" > "$NEW_CONFIG_FILE"
+        CONFIG_FILE="$NEW_CONFIG_FILE"
+        echo "Created config file $CONFIG_FILE with $BUILDDIR/test-services servicedir"
+    fi
+
+    unset DBUS_SESSION_BUS_ADDRESS
+    unset DBUS_SESSION_BUS_PID
+
+    echo "Running dbus-launch --config-file=$CONFIG_FILE" >&2
+
+    eval `dbus-launch --exit-with-session --sh-syntax --config-file=$CONFIG_FILE 2>"$STDERR_LOGFILE"`
+
+    if test -z "$DBUS_SESSION_BUS_PID" ; then
+        die "Failed to launch message bus for test script to run"
+    fi
+
+    echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
+fi
+
+if ! test -z "$START_SYSTEM_BUS" ; then
+    SYSTEM_CONFIG_FILE="$TOP_SRCDIR"/test/test-bus.conf
+
+    if test x"$GJS_USE_UNINSTALLED_FILES" != x; then
+        NEW_SYSTEM_CONFIG_FILE="$BUILDDIR"/uninstalled-system-test-bus.conf
+
+        SED_RULE="s@<type>session</type>@<type>system</type><servicedir>$BUILDDIR/test-system-services/</servicedir>@"
+        # use fixed path (unix:abstract=/tmp/dbus-$USER-$DISPLAY) for session bus for
+        # easy access across shells
+        # (DISPLAY without ':' as dbus doesn't like it unescaped)
+        SED_RULE="$SED_RULE;s@<listen>.*</listen>@<listen>$DBUS_SYSTEM_BUS_ADDRESS</listen>@"
+        sed -e "$SED_RULE" "$SYSTEM_CONFIG_FILE" > "$NEW_SYSTEM_CONFIG_FILE"
+        SYSTEM_CONFIG_FILE="$NEW_SYSTEM_CONFIG_FILE"
+        echo "Created config file $SYSTEM_CONFIG_FILE with $BUILDDIR/test-system-services servicedir"
+    else
+        die "System bus makes no sense when installed, set GJS_USE_UNINSTALLED_FILES"
+    fi
+
+    echo "Running dbus-daemon --fork --print-pid --config-file=$SYSTEM_CONFIG_FILE" >&2
+
+    unset DBUS_SYSTEM_BUS_PID
+    DBUS_SYSTEM_BUS_PID=`dbus-daemon --fork --print-pid --config-file=$SYSTEM_CONFIG_FILE 2>>"$STDERR_LOGFILE"`
+
+    if test -z "$DBUS_SYSTEM_BUS_PID" ; then
+        die "Failed to launch system bus for test script to run"
+    fi
+
+    echo "Started bus pid $DBUS_SYSTEM_BUS_PID at $DBUS_SYSTEM_BUS_ADDRESS" >&2
+
+    dbus-monitor --system "type='method_call'" "type='signal'" "type='method_return'" "type='error'" > "$SYSTEM_MONITOR_LOGFILE" 2>&1 &
+
+fi
+
+# Execute wrapped script
+echo "Running with dbus: $WRAPPED_SCRIPT $@ with stderr to $STDERR_LOGFILE" >&2
+$WRAPPED_SCRIPT "$@" 2>>"$STDERR_LOGFILE" || die "script \"$WRAPPED_SCRIPT\" failed"
+
+if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+    kill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
+fi
+
+if ! test -z "$DBUS_SYSTEM_BUS_PID" ; then
+    kill -TERM $DBUS_SYSTEM_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SYSTEM_BUS_PID" >&2
+fi
+
+sleep 2
+
+## be sure it really died
+if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+    kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
+fi
+
+if ! test -z "$DBUS_SYSTEM_BUS_PID" ; then
+    kill -9 $DBUS_SYSTEM_BUS_PID > /dev/null 2>&1 || true
+fi
+
+exit 0
diff --git a/test/test-bus.conf b/test/test-bus.conf
new file mode 100644
index 0000000..96546b1
--- /dev/null
+++ b/test/test-bus.conf
@@ -0,0 +1,43 @@
+<!-- Configuration file for a dbus daemon we run for test purposes -->
+
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd";>
+<busconfig>
+  <!-- Our well-known bus type, don't change this -->
+  <type>session</type>
+
+  <listen>unix:tmpdir=/tmp</listen>
+
+  <policy context="default">
+    <!-- Allow everything to be sent -->
+    <allow send_destination="*" eavesdrop="true"/>
+    <!-- Allow everything to be received -->
+    <allow eavesdrop="true"/>
+    <!-- Allow anyone to own anything -->
+    <allow own="*"/>
+  </policy>
+
+  <!-- For the session bus, override the default relatively-low limits
+       with essentially infinite limits, since the bus is just running
+       as the user anyway, using up bus resources is not something we need
+       to worry about. In some cases, we do set the limits lower than
+       "all available memory" if exceeding the limit is almost certainly a bug,
+       having the bus enforce a limit is nicer than a huge memory leak. But the
+       intent is that these limits should never be hit. -->
+
+  <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max -->
+  <limit name="max_incoming_bytes">1000000000</limit>
+  <limit name="max_outgoing_bytes">1000000000</limit>
+  <limit name="max_message_size">1000000000</limit>
+  <limit name="service_start_timeout">120000</limit>
+  <limit name="auth_timeout">240000</limit>
+  <limit name="max_completed_connections">100000</limit>
+  <limit name="max_incomplete_connections">10000</limit>
+  <limit name="max_connections_per_user">100000</limit>
+  <limit name="max_pending_service_starts">10000</limit>
+  <limit name="max_names_per_connection">50000</limit>
+  <limit name="max_match_rules_per_connection">50000</limit>
+  <limit name="max_replies_per_connection">50000</limit>
+  <limit name="reply_timeout">300000</limit>
+
+</busconfig>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]