Alexander Hansen | 6498f9f | 2024-09-13 17:15:33 +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 | PTYS_PID="" |
| 12 | SERVER_PID="" |
| 13 | |
| 14 | cd "$TEST_DIR" |
| 15 | |
| 16 | cleanup() |
| 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 | |
| 25 | trap cleanup EXIT |
| 26 | |
| 27 | TEST_CONF="${TEST_NAME}.conf" |
| 28 | TEST_LOG="${TEST_NAME}.log" |
Marshall Zhan | 366651d | 2024-08-22 17:10:44 +0800 | [diff] [blame] | 29 | BLOCK_SIZE=1024 |
| 30 | LOG_MAX_SIZE=$((5 * $BLOCK_SIZE)) |
Alexander Hansen | 6498f9f | 2024-09-13 17:15:33 +0200 | [diff] [blame] | 31 | |
| 32 | cat <<EOF > "$TEST_CONF" |
| 33 | logfile = $TEST_LOG |
| 34 | console-id = $TEST_NAME |
Marshall Zhan | 366651d | 2024-08-22 17:10:44 +0800 | [diff] [blame] | 35 | logsize = $LOG_MAX_SIZE |
Alexander Hansen | 6498f9f | 2024-09-13 17:15:33 +0200 | [diff] [blame] | 36 | EOF |
| 37 | |
Marshall Zhan | 366651d | 2024-08-22 17:10:44 +0800 | [diff] [blame] | 38 | dd if=/dev/zero bs=$BLOCK_SIZE count=$(($LOG_MAX_SIZE / $BLOCK_SIZE)) >> "$TEST_LOG" |
| 39 | |
Alexander Hansen | 6498f9f | 2024-09-13 17:15:33 +0200 | [diff] [blame] | 40 | "$SOCAT" -u PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local & |
| 41 | PTYS_PID="$!" |
| 42 | while ! [ -e remote ] || ! [ -e local ]; do sleep 1; done |
| 43 | |
| 44 | "$SERVER" --config "$TEST_CONF" "$(realpath local)" & |
| 45 | SERVER_PID="$!" |
| 46 | while ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done |
| 47 | |
| 48 | echo console-should-log-to-file-legacy-syntax > remote |
| 49 | sleep 1 |
| 50 | grep -LF console-should-log-to-file-legacy-syntax "$TEST_LOG" |
Marshall Zhan | 366651d | 2024-08-22 17:10:44 +0800 | [diff] [blame] | 51 | |
| 52 | [ -e "$TEST_LOG" ] && [ $(stat -c%s "$TEST_LOG") -le $LOG_MAX_SIZE ] |