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