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