1#!/bin/sh 2# 3# This script is modified from dbus's run-with-temp-session-bus.sh. 4# 5 6SCRIPTNAME="$0" 7 8die() 9{ 10 if ! test -z "$DBUS_SESSION_BUS_PID" ; then 11 echo "killing message bus "$DBUS_SESSION_BUS_PID >&2 12 kill -9 $DBUS_SESSION_BUS_PID 13 fi 14 echo $SCRIPTNAME: $* >&2 15 exit 1 16} 17 18## convenient to be able to ctrl+C without leaking the message bus process 19trap 'die "Received SIGINT"' INT 20 21unset DBUS_SESSION_BUS_ADDRESS 22unset DBUS_SESSION_BUS_PID 23 24echo "Running dbus-launch --sh-syntax" >&2 25 26eval `dbus-launch --sh-syntax` 27 28if test -z "$DBUS_SESSION_BUS_PID" ; then 29 die "Failed to launch message bus for test script to run" 30fi 31 32echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2 33 34TEMP_PULSE_DIR=`mktemp -d` 35export PULSE_RUNTIME_PATH=${TEMP_PULSE_DIR} 36 37# this script would be called inside src/ directory, so we need to use the correct path. 38# notice that for tests, we don't load ALSA related modules. 39pulseaudio -n \ 40 --log-target=file:${PWD}/pulse-daemon.log \ 41 --log-level=debug \ 42 --load="module-null-sink" \ 43 --load="module-null-source" \ 44 --load="module-suspend-on-idle" \ 45 --load="module-native-protocol-unix" \ 46 --load="module-cli-protocol-unix" \ 47 & 48 49# wait a few seconds to let the daemon start! 50sleep 2 51 52unset DISPLAY 53 54EXIT_CODE=0 55 56for ONE_TEST in $@; do 57 ${ONE_TEST} || EXIT_CODE=1 58done 59 60# terminate the designated pulseaudio daemon 61pacmd exit 62 63wait 64 65kill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2 66 67sleep 2 68 69## be sure it really died 70kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true 71 72exit $EXIT_CODE 73