blob: 1dbfb2175c533e19e3e00462d84a780f3ebe9308 [file] [log] [blame] [edit]
#!/usr/bin/sh
set -eux
SOCAT="$1"
SERVER="$2"
# Meet DBus bus and path name constraints, append own PID for parallel runs
TEST_NAME="$(basename "$0" | tr '-' '_')"_${$}
TEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")"
PTYS_PID=""
SERVER_PID=""
cd "$TEST_DIR"
cleanup()
{
[ -z "$SERVER_PID" ] || kill -s INT "$SERVER_PID"
[ -z "$PTYS_PID" ] || kill "$PTYS_PID"
wait
cd -
rm -rf "$TEST_DIR"
}
trap cleanup EXIT
TEST_CONF="${TEST_NAME}.conf"
TEST_LOG="${TEST_NAME}.log"
BLOCK_SIZE=1024
LOG_MAX_SIZE=$((5 * $BLOCK_SIZE))
cat <<EOF > "$TEST_CONF"
logfile = $TEST_LOG
console-id = $TEST_NAME
logsize = $LOG_MAX_SIZE
EOF
dd if=/dev/zero bs=$BLOCK_SIZE count=$(($LOG_MAX_SIZE / $BLOCK_SIZE)) >> "$TEST_LOG"
"$SOCAT" -u PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local &
PTYS_PID="$!"
while ! [ -e remote ] || ! [ -e local ]; do sleep 1; done
"$SERVER" --config "$TEST_CONF" "$(realpath local)" &
SERVER_PID="$!"
while ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done
echo console-should-log-to-file-legacy-syntax > remote
sleep 1
grep -LF console-should-log-to-file-legacy-syntax "$TEST_LOG"
[ -e "$TEST_LOG" ] && [ $(stat -c%s "$TEST_LOG") -le $LOG_MAX_SIZE ]