summaryrefslogtreecommitdiffstats
path: root/scripts/tests
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-01 16:33:09 +0100
committersalmonik <salmonik@tuta.io>2026-11-01 16:33:09 +0100
commit363e24bcd18a28948f63fa78ac8a4eaa8784fe59 (patch)
tree6b74ab993ff42e3bf15b01f4cfd09bcb3f0d5ea6 /scripts/tests
parentusb: real-hardware rework — hubs, both EHCI controllers, keyboard, xHCI har... (diff)
downloadrs-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 'scripts/tests')
-rwxr-xr-xscripts/tests/test-usb.sh77
1 files changed, 77 insertions, 0 deletions
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#
22set -euo pipefail
23source "$(dirname "$0")/../lib.sh"
24
25echo "==> 1/3 build (kernel + bins)"
26build_all
27
28echo "==> 2/3 stage system image"
29stage_image --force
30
31# Per-controller log/socket files; test_boot() reads these globals.
32case_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
42case_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
48case_done() {
49 kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true
50 sleep 0.5
51 echo " $1: mouse + keyboard OK"
52}
53
54echo "==> 3/3 EHCI (USB2) enumeration"
55case_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
59case_arms ehci
60sendkeys "h"
61wait_log "$LOG" "kbd report" 10 || fail "ehci: no keyboard report decoded"
62tr -d '\r' < "$LOG" | grep -qx "h" || fail "ehci: typed key did not reach the shell"
63case_done ehci
64
65echo "==> 3/3 xHCI (USB3) enumeration"
66case_boot xhci \
67 -device qemu-xhci,id=xhci \
68 -device usb-mouse,bus=xhci.0 \
69 -device usb-kbd,bus=xhci.0
70case_arms xhci
71sendkeys "he"
72wait_log "$LOG" "kbd report" 10 || fail "xhci: no keyboard report decoded"
73wait_log "$LOG" "unknown command: he" 15 || fail "xhci: typed text did not reach the shell"
74case_done xhci
75
76echo ""
77echo "PASS — USB enumeration + HID input (EHCI and xHCI)"