summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib.sh6
-rwxr-xr-xscripts/tests/test-usb.sh77
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#
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)"