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.
This commit is contained in:
@@ -10,8 +10,8 @@ installed without sudo).
|
||||
|
||||
Spec model: an ordered list of steps. Each step is `expect:<text>` (wait for
|
||||
the literal text in guest output) or `send:<text>` (write text + CR to the
|
||||
guest). After all steps, wait for `--pass <text>` to succeed, or `--fail
|
||||
<text>` / timeout to fail.
|
||||
guest). After all steps, wait for `--pass_marker <text>` to succeed, or
|
||||
`--fail_marker <text>` / 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user