1#!/usr/bin/sh 2 3set -eux 4 5SOCAT="$1" 6SERVER="$2" 7CLIENT="$3" 8 9# Meet DBus bus and path name constraints, append own PID for parallel runs 10TEST_NAME="$(basename "$0" | tr '-' '_')"_${$} 11TEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")" 12PTY_PID="" 13SERVER_PID="" 14 15cd "$TEST_DIR" 16 17cleanup() 18{ 19 [ -z "$SERVER_PID" ] || kill "$SERVER_PID" || true 20 [ -z "$PTY_PID" ] || kill "$PTY_PID" 21 22 wait 23 cd - 24 rm -rf "$TEST_DIR" 25} 26 27trap cleanup EXIT 28 29TEST_CONF="${TEST_NAME}.conf" 30TEST_LOG="${TEST_NAME}.log" 31 32cat <<EOF > "$TEST_CONF" 33active-console = $TEST_NAME 34[$TEST_NAME] 35console-id = $TEST_NAME 36logfile = $TEST_LOG 37EOF 38 39"$SOCAT" PTY,raw,echo=0,wait-slave,link=local EXEC:'grep -m1 -qF client-wrote-this' & 40PTY_PID="$!" 41while ! [ -e local ]; do sleep 1; done 42 43"$SERVER" --config "$TEST_CONF" "$(realpath local)" & 44SERVER_PID="$!" 45while ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done 46 47sleep 1 48 49echo client-wrote-this | "$CLIENT" -i "$TEST_NAME" 50 51sleep 1 52 53kill -0 "$PTY_PID" && exit 1 54PTY_PID="" 55