153a5a1b3Sopenharmony_ci#!/bin/sh
253a5a1b3Sopenharmony_ci#
353a5a1b3Sopenharmony_ci# This script is modified from dbus's run-with-temp-session-bus.sh.
453a5a1b3Sopenharmony_ci#
553a5a1b3Sopenharmony_ci
653a5a1b3Sopenharmony_ciSCRIPTNAME="$0"
753a5a1b3Sopenharmony_ci
853a5a1b3Sopenharmony_cidie()
953a5a1b3Sopenharmony_ci{
1053a5a1b3Sopenharmony_ci    if ! test -z "$DBUS_SESSION_BUS_PID" ; then
1153a5a1b3Sopenharmony_ci        echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
1253a5a1b3Sopenharmony_ci        kill -9 $DBUS_SESSION_BUS_PID
1353a5a1b3Sopenharmony_ci    fi
1453a5a1b3Sopenharmony_ci    echo $SCRIPTNAME: $* >&2
1553a5a1b3Sopenharmony_ci    exit 1
1653a5a1b3Sopenharmony_ci}
1753a5a1b3Sopenharmony_ci
1853a5a1b3Sopenharmony_ci## convenient to be able to ctrl+C without leaking the message bus process
1953a5a1b3Sopenharmony_citrap 'die "Received SIGINT"' INT
2053a5a1b3Sopenharmony_ci
2153a5a1b3Sopenharmony_ciunset DBUS_SESSION_BUS_ADDRESS
2253a5a1b3Sopenharmony_ciunset DBUS_SESSION_BUS_PID
2353a5a1b3Sopenharmony_ci
2453a5a1b3Sopenharmony_ciecho "Running dbus-launch --sh-syntax" >&2
2553a5a1b3Sopenharmony_ci
2653a5a1b3Sopenharmony_cieval `dbus-launch --sh-syntax`
2753a5a1b3Sopenharmony_ci
2853a5a1b3Sopenharmony_ciif test -z "$DBUS_SESSION_BUS_PID" ; then
2953a5a1b3Sopenharmony_ci    die "Failed to launch message bus for test script to run"
3053a5a1b3Sopenharmony_cifi
3153a5a1b3Sopenharmony_ci
3253a5a1b3Sopenharmony_ciecho "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
3353a5a1b3Sopenharmony_ci
3453a5a1b3Sopenharmony_ciTEMP_PULSE_DIR=`mktemp -d`
3553a5a1b3Sopenharmony_ciexport PULSE_RUNTIME_PATH=${TEMP_PULSE_DIR}
3653a5a1b3Sopenharmony_ci
3753a5a1b3Sopenharmony_ci# this script would be called inside src/ directory, so we need to use the correct path.
3853a5a1b3Sopenharmony_ci# notice that for tests, we don't load ALSA related modules.
3953a5a1b3Sopenharmony_cipulseaudio -n \
4053a5a1b3Sopenharmony_ci        --log-target=file:${PWD}/pulse-daemon.log \
4153a5a1b3Sopenharmony_ci        --log-level=debug \
4253a5a1b3Sopenharmony_ci        --load="module-null-sink" \
4353a5a1b3Sopenharmony_ci        --load="module-null-source" \
4453a5a1b3Sopenharmony_ci        --load="module-suspend-on-idle" \
4553a5a1b3Sopenharmony_ci        --load="module-native-protocol-unix" \
4653a5a1b3Sopenharmony_ci        --load="module-cli-protocol-unix" \
4753a5a1b3Sopenharmony_ci        &
4853a5a1b3Sopenharmony_ci
4953a5a1b3Sopenharmony_ci# wait a few seconds to let the daemon start!
5053a5a1b3Sopenharmony_cisleep 2
5153a5a1b3Sopenharmony_ci
5253a5a1b3Sopenharmony_ciunset DISPLAY
5353a5a1b3Sopenharmony_ci
5453a5a1b3Sopenharmony_ciEXIT_CODE=0
5553a5a1b3Sopenharmony_ci
5653a5a1b3Sopenharmony_cifor ONE_TEST in $@; do
5753a5a1b3Sopenharmony_ci    ${ONE_TEST} || EXIT_CODE=1
5853a5a1b3Sopenharmony_cidone
5953a5a1b3Sopenharmony_ci
6053a5a1b3Sopenharmony_ci# terminate the designated pulseaudio daemon
6153a5a1b3Sopenharmony_cipacmd exit
6253a5a1b3Sopenharmony_ci
6353a5a1b3Sopenharmony_ciwait
6453a5a1b3Sopenharmony_ci
6553a5a1b3Sopenharmony_cikill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
6653a5a1b3Sopenharmony_ci
6753a5a1b3Sopenharmony_cisleep 2
6853a5a1b3Sopenharmony_ci
6953a5a1b3Sopenharmony_ci## be sure it really died
7053a5a1b3Sopenharmony_cikill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
7153a5a1b3Sopenharmony_ci
7253a5a1b3Sopenharmony_ciexit $EXIT_CODE
73