test: add portal hardware lifecycle coverage

This commit is contained in:
2026-09-06 20:03:38 +10:00
parent fcd991c5a2
commit d57f6c91c5
15 changed files with 595 additions and 20 deletions
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
set -euo pipefail
usage() {
echo "Usage: $0 --port /dev/serial/by-id/... [--timeout seconds]" >&2
exit 2
}
port=""
timeout_seconds=300
while [[ $# -gt 0 ]]; do
case "$1" in
--port) [[ $# -ge 2 ]] || usage; port="${2:-}"; shift 2 ;;
--timeout) [[ $# -ge 2 ]] || usage; timeout_seconds="${2:-}"; shift 2 ;;
*) usage ;;
esac
done
[[ -n "$port" && -e "$port" ]] || usage
[[ "$timeout_seconds" =~ ^[1-9][0-9]*$ ]] || usage
capture_file="$(mktemp -p /tmp wifimanager-unity.XXXXXX)"
monitor_pid=""
preserve_capture=false
cleanup() {
if [[ -n "$monitor_pid" ]] && kill -0 "$monitor_pid" 2>/dev/null; then
kill "$monitor_pid" 2>/dev/null || true
wait "$monitor_pid" 2>/dev/null || true
fi
if [[ "$preserve_capture" == "false" ]]; then
rm -f "$capture_file"
fi
}
trap cleanup EXIT
# Start immediately after upload. PlatformIO's interactive monitor cannot run
# without a TTY; socat opens only this port and streams its configured 115200
# baud output into the capture file without touching another board.
timeout --foreground "$timeout_seconds" socat -u "FILE:$port,raw,echo=0,b115200" STDOUT \
>"$capture_file" 2>&1 &
monitor_pid="$!"
while kill -0 "$monitor_pid" 2>/dev/null; do
if grep -aqE '[0-9]+ Tests [0-9]+ Failures' "$capture_file"; then
kill "$monitor_pid" 2>/dev/null || true
wait "$monitor_pid" 2>/dev/null || true
monitor_pid=""
if grep -aq "Tests 0 Failures" "$capture_file" && grep -aq "^OK" "$capture_file"; then
grep -aE '\[METRIC\]|Tests [0-9]+ Failures|^OK$' "$capture_file" || true
exit 0
fi
echo "Unity reported a test failure:" >&2
grep -anE ':FAIL|FAIL$|\[METRIC\]|Tests [0-9]+ Failures' "$capture_file" >&2 || true
tail -n 80 "$capture_file" >&2 || true
preserve_capture=true
echo "Full serial capture retained at $capture_file" >&2
exit 1
fi
sleep 0.25
done
wait "$monitor_pid" || true
monitor_pid=""
preserve_capture=true
echo "Serial monitoring ended before Unity produced a summary; capture retained at $capture_file" >&2
exit 1
+33 -4
View File
@@ -2,16 +2,35 @@
set -euo pipefail
usage() {
echo "Usage: $0 compile|examples --platform esp8266|esp32" >&2
cat <<'EOF' >&2
Usage:
./scripts/test.sh compile --platform esp8266|esp32
./scripts/test.sh examples --platform esp8266|esp32
./scripts/test.sh hardware --platform esp8266|esp32 --port /dev/serial/by-id/...
EOF
exit 2
}
[[ $# -eq 3 && ( "${1:-}" == "compile" || "${1:-}" == "examples" ) && "${2:-}" == "--platform" ]] || usage
platform="${3:-}"
mode="${1:-}"
[[ "$mode" == "compile" || "$mode" == "examples" || "$mode" == "hardware" ]] || usage
shift
platform=""
port=""
while [[ $# -gt 0 ]]; do
case "$1" in
--platform) [[ $# -ge 2 ]] || usage; platform="${2:-}"; shift 2 ;;
--port) [[ $# -ge 2 ]] || usage; port="${2:-}"; shift 2 ;;
*) usage ;;
esac
done
[[ "$platform" == "esp8266" || "$platform" == "esp32" ]] || usage
[[ "$mode" != "hardware" || -n "$port" ]] || usage
[[ "$mode" != "hardware" || -e "$port" ]] || { echo "Serial port not found: $port" >&2; exit 1; }
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [[ "$1" == "examples" ]]; then
if [[ "$mode" == "examples" ]]; then
mapfile -t examples < <(find "$root/examples" -mindepth 2 -maxdepth 2 -type f -name platformio.ini -printf '%h\n' | sort)
if (( ${#examples[@]} == 0 )); then
echo "No example projects found" >&2
@@ -24,6 +43,16 @@ if [[ "$1" == "examples" ]]; then
exit 0
fi
if [[ "$mode" == "hardware" ]]; then
# Upload first, then capture from the normal boot reset. The Unity sketch
# deliberately waits two seconds before it begins its test sequence.
pio test -d "$root" -e "$platform" --filter test_wifimanager \
--upload-port "$port" --without-testing
"$root/scripts/capture-unity-serial.sh" --port "$port" --timeout 300
echo "WiFiManager hardware test passed for $platform on $port"
exit 0
fi
cached_library="$root/test/compile-project/.pio/libdeps/${platform}/WiFiManager"
# The fixture intentionally declares only this local package. Remove a prior
# link so each check resolves the current manifest as a fresh consumer would.