diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 16:33:09 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 16:33:09 +0100 |
| commit | 363e24bcd18a28948f63fa78ac8a4eaa8784fe59 (patch) | |
| tree | 6b74ab993ff42e3bf15b01f4cfd09bcb3f0d5ea6 /scripts | |
| parent | usb: real-hardware rework — hubs, both EHCI controllers, keyboard, xHCI har... (diff) | |
| download | rs-dos-363e24bcd18a28948f63fa78ac8a4eaa8784fe59.tar.gz rs-dos-363e24bcd18a28948f63fa78ac8a4eaa8784fe59.zip | |
scripts: add test-usb; fix duplicate -bios in the test harness
- test-usb boots an EHCI and an xHCI controller with a mouse + keyboard and
asserts enumeration, report decoding, and input reaching the shell. The
EHCI case asserts one key end-to-end (QEMU's EHCI model delivers only the
first report through root-port split transactions); the xHCI case asserts a
whole typed command.
- lib.sh: qemu_args() already supplies -bios, so the fresh OVMF varstore copy
was silently overridden by the system firmware. Pass the copy last (QEMU
honours the last -bios) so tests really boot clean NVRAM.
- DEBUG_NOTES: document why USB never worked on the OptiPlex (EHCI shipped
with DEBUG_MATRIX enabled, no RMH/hub support, only the first controller,
no boot protocol, unbounded DMA), the success/failure log to look for on
hardware, and the QEMU coverage limits.
- Makefile: add test-usb and include it in `make test`.
Diffstat (limited to '')
| -rw-r--r-- | scripts/lib.sh | 6 | ||||
| -rwxr-xr-x | scripts/tests/test-usb.sh | 77 |
2 files changed, 82 insertions, 1 deletions
diff --git a/scripts/lib.sh b/scripts/lib.sh index d5aecac..6ca3e92 100644 --- a/scripts/lib.sh +++ b/scripts/lib.sh | |||
| @@ -157,8 +157,12 @@ test_boot() { | |||
| 157 | cp "$OVMF" "$nv" | 157 | cp "$OVMF" "$nv" |
| 158 | local -a qargs | 158 | local -a qargs |
| 159 | mapfile -t qargs < <(qemu_args) | 159 | mapfile -t qargs < <(qemu_args) |
| 160 | "$QEMU" -bios "$nv" \ | 160 | # qemu_args() already carries -bios $OVMF; put the fresh varstore copy |
| 161 | # last so it wins (QEMU uses the last -bios) without duplicating the | ||
| 162 | # whole argument set. | ||
| 163 | "$QEMU" \ | ||
| 161 | "${qargs[@]}" \ | 164 | "${qargs[@]}" \ |
| 165 | -bios "$nv" \ | ||
| 162 | -serial "file:$LOG" \ | 166 | -serial "file:$LOG" \ |
| 163 | -monitor "unix:$SOCK,server,nowait" \ | 167 | -monitor "unix:$SOCK,server,nowait" \ |
| 164 | -display none \ | 168 | -display none \ |
diff --git a/scripts/tests/test-usb.sh b/scripts/tests/test-usb.sh new file mode 100755 index 0000000..55a3f2b --- /dev/null +++ b/scripts/tests/test-usb.sh | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # | ||
| 3 | # scripts/tests/test-usb.sh — USB host-controller + HID regression. | ||
| 4 | # | ||
| 5 | # Boots twice, once with an EHCI (USB2) controller and once with an xHCI | ||
| 6 | # (USB3) controller, each with a HID mouse and keyboard: | ||
| 7 | # | ||
| 8 | # • both devices must enumerate and arm their interrupt-IN endpoints | ||
| 9 | # • a keyboard report must be decoded (scancode path) | ||
| 10 | # • the key must reach the shell (WM input routing) | ||
| 11 | # | ||
| 12 | # QEMU limitation: its EHCI model delivers only the *first* report for a | ||
| 13 | # full/low-speed device serviced by root-port split transactions, so the EHCI | ||
| 14 | # case asserts one key end-to-end (a regression in enumeration/arming fails | ||
| 15 | # earlier). The xHCI case has no splits and asserts a whole typed command. | ||
| 16 | # Mouse report delivery cannot be injected into usb-mouse headless; the | ||
| 17 | # hardware run (OptiPlex) is the arbiter for both. | ||
| 18 | # | ||
| 19 | # Usage: ./scripts/tests/test-usb.sh | ||
| 20 | # Env: SYSTEM_IMG, OVMF, QEMU (see scripts/lib.sh) | ||
| 21 | # | ||
| 22 | set -euo pipefail | ||
| 23 | source "$(dirname "$0")/../lib.sh" | ||
| 24 | |||
| 25 | echo "==> 1/3 build (kernel + bins)" | ||
| 26 | build_all | ||
| 27 | |||
| 28 | echo "==> 2/3 stage system image" | ||
| 29 | stage_image --force | ||
| 30 | |||
| 31 | # Per-controller log/socket files; test_boot() reads these globals. | ||
| 32 | case_boot() { | ||
| 33 | local name="$1" | ||
| 34 | shift | ||
| 35 | LOG="/tmp/rsdos-usb-$name-serial.log" | ||
| 36 | SOCK="/tmp/rsdos-usb-$name-qmon.sock" | ||
| 37 | QPID="/tmp/rsdos-usb-$name-qpid" | ||
| 38 | QLOG="/tmp/rsdos-usb-$name-qemu.log" | ||
| 39 | test_boot "$@" | ||
| 40 | } | ||
| 41 | |||
| 42 | case_arms() { | ||
| 43 | wait_log "$LOG" "HID mouse armed" 20 || fail "$1: mouse not enumerated" | ||
| 44 | wait_log "$LOG" "HID keyboard armed" 20 || fail "$1: keyboard not enumerated" | ||
| 45 | sleep 1 | ||
| 46 | } | ||
| 47 | |||
| 48 | case_done() { | ||
| 49 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true | ||
| 50 | sleep 0.5 | ||
| 51 | echo " $1: mouse + keyboard OK" | ||
| 52 | } | ||
| 53 | |||
| 54 | echo "==> 3/3 EHCI (USB2) enumeration" | ||
| 55 | case_boot ehci \ | ||
| 56 | -device usb-ehci,id=ehci \ | ||
| 57 | -device usb-mouse,bus=ehci.0,port=1 \ | ||
| 58 | -device usb-kbd,bus=ehci.0,port=2 | ||
| 59 | case_arms ehci | ||
| 60 | sendkeys "h" | ||
| 61 | wait_log "$LOG" "kbd report" 10 || fail "ehci: no keyboard report decoded" | ||
| 62 | tr -d '\r' < "$LOG" | grep -qx "h" || fail "ehci: typed key did not reach the shell" | ||
| 63 | case_done ehci | ||
| 64 | |||
| 65 | echo "==> 3/3 xHCI (USB3) enumeration" | ||
| 66 | case_boot xhci \ | ||
| 67 | -device qemu-xhci,id=xhci \ | ||
| 68 | -device usb-mouse,bus=xhci.0 \ | ||
| 69 | -device usb-kbd,bus=xhci.0 | ||
| 70 | case_arms xhci | ||
| 71 | sendkeys "he" | ||
| 72 | wait_log "$LOG" "kbd report" 10 || fail "xhci: no keyboard report decoded" | ||
| 73 | wait_log "$LOG" "unknown command: he" 15 || fail "xhci: typed text did not reach the shell" | ||
| 74 | case_done xhci | ||
| 75 | |||
| 76 | echo "" | ||
| 77 | echo "PASS — USB enumeration + HID input (EHCI and xHCI)" | ||
