summaryrefslogtreecommitdiffstats
path: root/scripts/tests/sendkeys.py
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-01 15:53:29 +0100
committersalmonik <salmonik@tuta.io>2026-11-01 15:53:29 +0100
commit7958276c9f0d230053520ba20f2a00f5ecda18e4 (patch)
tree596f5f71ad597ed951bae98de818cb37f171a18d /scripts/tests/sendkeys.py
parentfs: /bin alias for the system volume (diff)
downloadrs-dos-7958276c9f0d230053520ba20f2a00f5ecda18e4.tar.gz
rs-dos-7958276c9f0d230053520ba20f2a00f5ecda18e4.zip
scripts: rebuild the dev loop around build.sh/run.sh
`make` did not parse at all (missing separator at line 139), so every make target was dead. The folder also carried three overlapping launchers (boot.sh, qemu.sh, boot-image.sh) plus a fourth partial one in the Makefile, `cargo build --package rsdos` copy-pasted eight times, the QEMU invocation copy-pasted per script, and the test helpers (fail/wait_log/wait_qemu_exit/qemu_hmp) duplicated in five tests. New layout: - scripts/lib.sh: single config (image, OVMF, mem/smp), the one cargo invocation (build_all), the one QEMU shape (qemu_args), and the test harness (test_boot, wait_log, wait_qemu_exit, qemu_hmp, sendkeys) - scripts/build.sh: kernel + every bins/* in one pass - scripts/mksystem.sh: freshness-aware image build that now stages every bins/*.efi into /bin/cli|gui (they were never copied before) - scripts/run.sh: build + stage + boot in one command; --headless, --debug (GDB stub), --monitor (HMP socket), --fresh, --mem/--smp/ --bios/--image; on Wayland it auto-selects XWayland plus grab-on-hover so the mouse can be captured (Ctrl+Alt+G toggles) - scripts/tests/: the five automated tests on the shared harness - deleted: boot.sh, qemu.sh, boot-image.sh, lib-boot-args.sh, build-image-release.sh, build-bootloader.sh (rsboot chain dropped) The Makefile is now a thin wrapper: make run, make test, make system, make inspect, make help. Two-command flow: ./scripts/build.sh then ./scripts/run.sh (run.sh alone also works). Stale test assumptions fixed so the suite is green again: test-gfx waited for "gfx: check" while the shell prints "gfx check: PASS"; test-mouse/test-msg hardcoded msgrecv = task 3 (wm-input took slot 3 — ids are parsed from the log now); the queue-full probe targeted task 0, whose exec pump drains its own queue as completion codes (moved to the cursor task, which never recvs). Verified in QEMU: make test -> test-disk, test-gfx, test-mouse, test-msg, test-fault all PASS.
Diffstat (limited to 'scripts/tests/sendkeys.py')
-rwxr-xr-xscripts/tests/sendkeys.py105
1 files changed, 105 insertions, 0 deletions
diff --git a/scripts/tests/sendkeys.py b/scripts/tests/sendkeys.py
new file mode 100755
index 0000000..9300242
--- /dev/null
+++ b/scripts/tests/sendkeys.py
@@ -0,0 +1,105 @@
1#!/usr/bin/env python3
2"""Type lines into a QEMU guest via the monitor's `sendkey` command.
3
4Each positional argument is one line: it is typed character by character
5(US layout) followed by Enter. Use it to drive the rs-dos shell from a
6test script without a display.
7
8Used by scripts/tests/test-*.sh, and manually against an interactive
9session started with `./scripts/run.sh --monitor`:
10
11 ./scripts/tests/sendkeys.py "ls /disk" "date" "poweroff"
12 ./scripts/tests/sendkeys.py --sock /tmp/rsdos-monitor.sock "date"
13
14Environment: QMON_SOCK (default: /tmp/rsdos-monitor.sock)
15"""
16import os
17import socket
18import sys
19import time
20
21SOCK = os.environ.get("QMON_SOCK", "/tmp/rsdos-monitor.sock")
22
23# Unshifted punctuation needs QEMU's *named* keys — bare '-'/'.'/'/' are
24# not valid sendkey names (and '-' is the modifier separator).
25BASE = {
26 "-": "minus", "=": "equal", "[": "bracketleft", "]": "bracketright",
27 "\\": "backslash", ";": "semicolon", "'": "apostrophe",
28 ",": "comma", ".": "dot", "/": "slash", "`": "grave",
29}
30
31# Characters that need a shift key on US layout, and the key QEMU's
32# `sendkey` understands for them.
33SHIFT = {
34 "~": "grave", "!": "1", "@": "2", "#": "3", "$": "4", "%": "5",
35 "^": "6", "&": "7", "*": "8", "(": "9", ")": "0",
36 "_": "minus", "+": "equal", "{": "bracketleft", "}": "bracketright",
37 "|": "backslash", ":": "semicolon", '"': "apostrophe",
38 "<": "comma", ">": "dot", "?": "slash",
39}
40
41ALNUM = set("abcdefghijklmnopqrstuvwxyz0123456789")
42
43
44def connect(path, timeout=60):
45 """Connect to the monitor socket, retrying until QEMU is up."""
46 deadline = time.time() + timeout
47 while True:
48 try:
49 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
50 s.connect(path)
51 return s
52 except OSError:
53 if time.time() > deadline:
54 raise
55 time.sleep(0.2)
56
57
58def sendkey(sock, keys):
59 sock.sendall(("sendkey %s\n" % keys).encode())
60
61
62def type_line(sock, line):
63 for ch in line:
64 if ch == " ":
65 sendkey(sock, "spc")
66 elif ch in BASE:
67 sendkey(sock, BASE[ch])
68 elif ch in SHIFT:
69 sendkey(sock, "shift-" + SHIFT[ch])
70 elif ch.isupper():
71 sendkey(sock, "shift-" + ch.lower())
72 elif ch in ALNUM:
73 sendkey(sock, ch)
74 else:
75 sys.stderr.write("warning: no sendkey mapping for %r\n" % ch)
76 continue
77 time.sleep(0.25)
78 sendkey(sock, "ret")
79 time.sleep(1.5)
80
81
82def main():
83 args = [a for a in sys.argv[1:] if a != "--sock"]
84 sock_path = SOCK
85 if "--sock" in sys.argv:
86 i = sys.argv.index("--sock")
87 sock_path = sys.argv[i + 1]
88 args = sys.argv[i + 2:]
89 if not args:
90 sys.stderr.write(__doc__ or "")
91 return 1
92 sock = connect(sock_path)
93 # Let the monitor drain any startup banner before typing.
94 time.sleep(0.5)
95 for line in args:
96 try:
97 type_line(sock, line)
98 except OSError:
99 # Guest powered off (last line was usually "poweroff").
100 break
101 return 0
102
103
104if __name__ == "__main__":
105 sys.exit(main())