From cf6f363da9a584bdcee5187d05ea36413135594c Mon Sep 17 00:00:00 2001 From: vasilito Date: Mon, 20 Jul 2026 07:08:28 +0900 Subject: [PATCH] tests: fix qemu-login-expect fail-marker guard, docstring flags, retry count Post-review fixes: - Phase 2 no longer breaks early when only --fail_marker is set: the 'if not args.pass_marker: break' guard skipped all output reads, so a fail marker was never detected (exit 0 instead of 1). Now breaks only when neither pass nor fail markers are configured. - docstring referenced --pass/--fail; argparse registers --pass_marker/--fail_marker. Align the docstring. - retry echo said 'attempt N/3' but the loop limit is 5 attempts; say /5. - warn and skip malformed steps (missing expect:/send: prefix) instead of spinning in select until timeout. --- local/scripts/qemu-login-expect.py | 10 +++++++--- local/scripts/test-iommu-qemu.sh | 2 +- local/scripts/test-ps2-qemu.sh | 2 +- local/scripts/test-timer-qemu.sh | 2 +- local/scripts/test-usb-storage-qemu.sh | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/local/scripts/qemu-login-expect.py b/local/scripts/qemu-login-expect.py index f0dffff1e4..a94bb7701a 100644 --- a/local/scripts/qemu-login-expect.py +++ b/local/scripts/qemu-login-expect.py @@ -10,8 +10,8 @@ installed without sudo). Spec model: an ordered list of steps. Each step is `expect:` (wait for the literal text in guest output) or `send:` (write text + CR to the -guest). After all steps, wait for `--pass ` to succeed, or `--fail -` / timeout to fail. +guest). After all steps, wait for `--pass_marker ` to succeed, or +`--fail_marker ` / timeout to fail. """ import argparse import os @@ -98,6 +98,10 @@ def main() -> int: i += 1 deadline = time.monotonic() + args.timeout continue + if not step.startswith("send:") and not step.startswith("expect:"): + print(f"WARN: ignoring malformed step (want expect:/send: prefix): {step!r}", file=sys.stderr) + i += 1 + continue r, _, _ = select.select([out], [], [], 0.5) if r: chunk = os.read(out.fileno(), 65536) @@ -119,7 +123,7 @@ def main() -> int: while not state["failed"]: if state["passes"] and len(state["passes"]) == len(args.pass_marker): break - if not args.pass_marker: + if not args.pass_marker and not args.fail_marker: break if time.monotonic() > deadline: break diff --git a/local/scripts/test-iommu-qemu.sh b/local/scripts/test-iommu-qemu.sh index a8a0b7565d..e8c6d51a04 100755 --- a/local/scripts/test-iommu-qemu.sh +++ b/local/scripts/test-iommu-qemu.sh @@ -136,7 +136,7 @@ if [[ "$check_mode" -eq 1 ]]; then fi if [[ ( $rc -eq 3 || $rc -eq 137 ) && $attempt -lt 5 ]]; then attempt=$((attempt + 1)) - echo "QEMU exited before completing the check; retrying (attempt $attempt/3)" + echo "QEMU exited before completing the check; retrying (attempt $attempt/5)" sleep 2 continue fi diff --git a/local/scripts/test-ps2-qemu.sh b/local/scripts/test-ps2-qemu.sh index 531754ca23..179a0607ee 100755 --- a/local/scripts/test-ps2-qemu.sh +++ b/local/scripts/test-ps2-qemu.sh @@ -118,7 +118,7 @@ if [[ "$check_mode" -eq 1 ]]; then fi if [[ ( $rc -eq 3 || $rc -eq 137 ) && $attempt -lt 5 ]]; then attempt=$((attempt + 1)) - echo "QEMU exited before completing the check; retrying (attempt $attempt/3)" + echo "QEMU exited before completing the check; retrying (attempt $attempt/5)" sleep 2 continue fi diff --git a/local/scripts/test-timer-qemu.sh b/local/scripts/test-timer-qemu.sh index 60d59bdd61..3b242f9ff7 100755 --- a/local/scripts/test-timer-qemu.sh +++ b/local/scripts/test-timer-qemu.sh @@ -116,7 +116,7 @@ if [[ "$check_mode" -eq 1 ]]; then fi if [[ ( $rc -eq 3 || $rc -eq 137 ) && $attempt -lt 5 ]]; then attempt=$((attempt + 1)) - echo "QEMU exited before completing the check; retrying (attempt $attempt/3)" + echo "QEMU exited before completing the check; retrying (attempt $attempt/5)" sleep 2 continue fi diff --git a/local/scripts/test-usb-storage-qemu.sh b/local/scripts/test-usb-storage-qemu.sh index 61502aebc7..ce43e2e071 100755 --- a/local/scripts/test-usb-storage-qemu.sh +++ b/local/scripts/test-usb-storage-qemu.sh @@ -143,7 +143,7 @@ while true; do fi if [[ ( $rc -eq 3 || $rc -eq 137 ) && $attempt -lt 5 ]]; then attempt=$((attempt + 1)) - echo "QEMU exited before completing the check; retrying (attempt $attempt/3)" + echo "QEMU exited before completing the check; retrying (attempt $attempt/5)" sleep 2 continue fi