blob: 1dbfb2175c533e19e3e00462d84a780f3ebe9308 [file] [log] [blame]
Alexander Hansen6498f9f2024-09-13 17:15:33 +02001#!/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"
Marshall Zhan366651d2024-08-22 17:10:44 +080029BLOCK_SIZE=1024
30LOG_MAX_SIZE=$((5 * $BLOCK_SIZE))
Alexander Hansen6498f9f2024-09-13 17:15:33 +020031
32cat <<EOF > "$TEST_CONF"
33logfile = $TEST_LOG
34console-id = $TEST_NAME
Marshall Zhan366651d2024-08-22 17:10:44 +080035logsize = $LOG_MAX_SIZE
Alexander Hansen6498f9f2024-09-13 17:15:33 +020036EOF
37
Marshall Zhan366651d2024-08-22 17:10:44 +080038dd if=/dev/zero bs=$BLOCK_SIZE count=$(($LOG_MAX_SIZE / $BLOCK_SIZE)) >> "$TEST_LOG"
39
Alexander Hansen6498f9f2024-09-13 17:15:33 +020040"$SOCAT" -u 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
48echo console-should-log-to-file-legacy-syntax > remote
49sleep 1
50grep -LF console-should-log-to-file-legacy-syntax "$TEST_LOG"
Marshall Zhan366651d2024-08-22 17:10:44 +080051
52[ -e "$TEST_LOG" ] && [ $(stat -c%s "$TEST_LOG") -le $LOG_MAX_SIZE ]