Alexander Hansen | c7602e0 | 2024-08-02 16:13:56 +0200 | [diff] [blame] | 1 | #!/usr/bin/sh |
| 2 | |
| 3 | set -eux |
| 4 | |
| 5 | SOCAT="$1" |
| 6 | SERVER="$2" |
| 7 | |
| 8 | # Meet DBus bus and path name constraints, append own PID for parallel runs |
| 9 | TEST_NAME="$(basename "$0" | tr '-' '_')"_${$} |
| 10 | TEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")" |
| 11 | |
| 12 | PTY_PID="" |
| 13 | SERVER_PID="" |
| 14 | |
| 15 | cd "$TEST_DIR" |
| 16 | |
| 17 | cleanup() |
| 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 | |
| 27 | trap cleanup EXIT |
| 28 | |
| 29 | TEST_CONF="${TEST_NAME}.conf" |
| 30 | TEST_LOG="${TEST_NAME}.log" |
| 31 | |
| 32 | cat <<EOF > "$TEST_CONF" |
| 33 | active-console = $TEST_NAME |
| 34 | [$TEST_NAME] |
| 35 | console-id = $TEST_NAME |
| 36 | logfile = $TEST_LOG |
| 37 | EOF |
| 38 | |
| 39 | "$SOCAT" PTY,raw,echo=0,link=local EXEC:'grep -m1 -qF socket-write' & |
| 40 | PTY_PID="$!" |
| 41 | while ! [ -e local ]; do sleep 1; done |
| 42 | |
| 43 | "$SERVER" --config "$TEST_CONF" "$(realpath local)" & |
| 44 | SERVER_PID="$!" |
| 45 | while ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done |
| 46 | |
| 47 | sleep 1 |
| 48 | |
| 49 | echo socket-write | socat -u - "ABSTRACT:obmc-console.${TEST_NAME}" |
| 50 | |
| 51 | sleep 1 |
| 52 | |
| 53 | kill -0 "$PTY_PID" && exit 1 |
| 54 | PTY_PID="" |