diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 15:53:29 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 15:53:29 +0100 |
| commit | 7958276c9f0d230053520ba20f2a00f5ecda18e4 (patch) | |
| tree | 596f5f71ad597ed951bae98de818cb37f171a18d /scripts/sendkeys.py | |
| parent | fs: /bin alias for the system volume (diff) | |
| download | rs-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/sendkeys.py')
| -rwxr-xr-x | scripts/sendkeys.py | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/scripts/sendkeys.py b/scripts/sendkeys.py deleted file mode 100755 index a67903d..0000000 --- a/scripts/sendkeys.py +++ /dev/null | |||
| @@ -1,103 +0,0 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | """Type lines into a QEMU guest via the monitor's `sendkey` command. | ||
| 3 | |||
| 4 | Each 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 | ||
| 6 | test script without a display. | ||
| 7 | |||
| 8 | Usage: | ||
| 9 | sendkeys.py "ls /disk" "echo hi WRITING /disk/a.txt" "poweroff" | ||
| 10 | sendkeys.py --sock /tmp/qmon.sock "date" | ||
| 11 | |||
| 12 | Environment: QMON_SOCK (default: /tmp/qmon.sock) | ||
| 13 | """ | ||
| 14 | import os | ||
| 15 | import socket | ||
| 16 | import sys | ||
| 17 | import time | ||
| 18 | |||
| 19 | SOCK = os.environ.get("QMON_SOCK", "/tmp/qmon.sock") | ||
| 20 | |||
| 21 | # Unshifted punctuation needs QEMU's *named* keys — bare '-'/'.'/'/' are | ||
| 22 | # not valid sendkey names (and '-' is the modifier separator). | ||
| 23 | BASE = { | ||
| 24 | "-": "minus", "=": "equal", "[": "bracketleft", "]": "bracketright", | ||
| 25 | "\\": "backslash", ";": "semicolon", "'": "apostrophe", | ||
| 26 | ",": "comma", ".": "dot", "/": "slash", "`": "grave", | ||
| 27 | } | ||
| 28 | |||
| 29 | # Characters that need a shift key on US layout, and the key QEMU's | ||
| 30 | # `sendkey` understands for them. | ||
| 31 | SHIFT = { | ||
| 32 | "~": "grave", "!": "1", "@": "2", "#": "3", "$": "4", "%": "5", | ||
| 33 | "^": "6", "&": "7", "*": "8", "(": "9", ")": "0", | ||
| 34 | "_": "minus", "+": "equal", "{": "bracketleft", "}": "bracketright", | ||
| 35 | "|": "backslash", ":": "semicolon", '"': "apostrophe", | ||
| 36 | "<": "comma", ">": "dot", "?": "slash", | ||
| 37 | } | ||
| 38 | |||
| 39 | ALNUM = set("abcdefghijklmnopqrstuvwxyz0123456789") | ||
| 40 | |||
| 41 | |||
| 42 | def connect(path, timeout=60): | ||
| 43 | """Connect to the monitor socket, retrying until QEMU is up.""" | ||
| 44 | deadline = time.time() + timeout | ||
| 45 | while True: | ||
| 46 | try: | ||
| 47 | s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| 48 | s.connect(path) | ||
| 49 | return s | ||
| 50 | except OSError: | ||
| 51 | if time.time() > deadline: | ||
| 52 | raise | ||
| 53 | time.sleep(0.2) | ||
| 54 | |||
| 55 | |||
| 56 | def sendkey(sock, keys): | ||
| 57 | sock.sendall(("sendkey %s\n" % keys).encode()) | ||
| 58 | |||
| 59 | |||
| 60 | def type_line(sock, line): | ||
| 61 | for ch in line: | ||
| 62 | if ch == " ": | ||
| 63 | sendkey(sock, "spc") | ||
| 64 | elif ch in BASE: | ||
| 65 | sendkey(sock, BASE[ch]) | ||
| 66 | elif ch in SHIFT: | ||
| 67 | sendkey(sock, "shift-" + SHIFT[ch]) | ||
| 68 | elif ch.isupper(): | ||
| 69 | sendkey(sock, "shift-" + ch.lower()) | ||
| 70 | elif ch in ALNUM: | ||
| 71 | sendkey(sock, ch) | ||
| 72 | else: | ||
| 73 | sys.stderr.write("warning: no sendkey mapping for %r\n" % ch) | ||
| 74 | continue | ||
| 75 | time.sleep(0.25) | ||
| 76 | sendkey(sock, "ret") | ||
| 77 | time.sleep(1.5) | ||
| 78 | |||
| 79 | |||
| 80 | def main(): | ||
| 81 | args = [a for a in sys.argv[1:] if a != "--sock"] | ||
| 82 | sock_path = SOCK | ||
| 83 | if "--sock" in sys.argv: | ||
| 84 | i = sys.argv.index("--sock") | ||
| 85 | sock_path = sys.argv[i + 1] | ||
| 86 | args = sys.argv[i + 2:] | ||
| 87 | if not args: | ||
| 88 | sys.stderr.write(__doc__ or "") | ||
| 89 | return 1 | ||
| 90 | sock = connect(sock_path) | ||
| 91 | # Let the monitor drain any startup banner before typing. | ||
| 92 | time.sleep(0.5) | ||
| 93 | for line in args: | ||
| 94 | try: | ||
| 95 | type_line(sock, line) | ||
| 96 | except OSError: | ||
| 97 | # Guest powered off (last line was usually "poweroff"). | ||
| 98 | break | ||
| 99 | return 0 | ||
| 100 | |||
| 101 | |||
| 102 | if __name__ == "__main__": | ||
| 103 | sys.exit(main()) | ||
