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")" 11PTYS_PID="" 12SERVER_PID="" 13 14cd "$TEST_DIR" 15 16cleanup() 17{ 18 [ -z "$SERVER_PID" ] || kill -s INT "$SERVER_PID" 19 [ -z "$PTYS_PID" ] || kill "$PTYS_PID" 20 wait 21 cd - 22 rm -rf "$TEST_DIR" 23} 24 25trap cleanup EXIT 26 27TEST_CONF="${TEST_NAME}.conf" 28TEST_LOG="${TEST_NAME}.log" 29BLOCK_SIZE=1024 30LOG_MAX_SIZE=$((5 * $BLOCK_SIZE)) 31 32cat <<EOF > "$TEST_CONF" 33active-console = $TEST_NAME 34logsize = $LOG_MAX_SIZE 35[$TEST_NAME] 36logfile = $TEST_LOG 37console-id = $TEST_NAME 38EOF 39 40dd if=/dev/zero bs=$BLOCK_SIZE count=$(($LOG_MAX_SIZE / $BLOCK_SIZE)) >> "$TEST_LOG" 41 42"$SOCAT" -u PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local & 43PTYS_PID="$!" 44while ! [ -e remote ] || ! [ -e local ]; do sleep 1; done 45 46"$SERVER" --config "$TEST_CONF" "$(realpath local)" & 47SERVER_PID="$!" 48while ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done 49 50echo console-should-log-to-file > remote 51sleep 1 52grep -LF console-should-log-to-file "$TEST_LOG" 53 54[ -e "$TEST_LOG" ] && [ $(stat -c%s "$TEST_LOG") -le $LOG_MAX_SIZE ] 55