From 7958276c9f0d230053520ba20f2a00f5ecda18e4 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 1 Nov 2026 15:53:29 +0100 Subject: scripts: rebuild the dev loop around build.sh/run.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- scripts/tests/sendkeys.py | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 scripts/tests/sendkeys.py (limited to 'scripts/tests/sendkeys.py') 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 @@ +#!/usr/bin/env python3 +"""Type lines into a QEMU guest via the monitor's `sendkey` command. + +Each positional argument is one line: it is typed character by character +(US layout) followed by Enter. Use it to drive the rs-dos shell from a +test script without a display. + +Used by scripts/tests/test-*.sh, and manually against an interactive +session started with `./scripts/run.sh --monitor`: + + ./scripts/tests/sendkeys.py "ls /disk" "date" "poweroff" + ./scripts/tests/sendkeys.py --sock /tmp/rsdos-monitor.sock "date" + +Environment: QMON_SOCK (default: /tmp/rsdos-monitor.sock) +""" +import os +import socket +import sys +import time + +SOCK = os.environ.get("QMON_SOCK", "/tmp/rsdos-monitor.sock") + +# Unshifted punctuation needs QEMU's *named* keys — bare '-'/'.'/'/' are +# not valid sendkey names (and '-' is the modifier separator). +BASE = { + "-": "minus", "=": "equal", "[": "bracketleft", "]": "bracketright", + "\\": "backslash", ";": "semicolon", "'": "apostrophe", + ",": "comma", ".": "dot", "/": "slash", "`": "grave", +} + +# Characters that need a shift key on US layout, and the key QEMU's +# `sendkey` understands for them. +SHIFT = { + "~": "grave", "!": "1", "@": "2", "#": "3", "$": "4", "%": "5", + "^": "6", "&": "7", "*": "8", "(": "9", ")": "0", + "_": "minus", "+": "equal", "{": "bracketleft", "}": "bracketright", + "|": "backslash", ":": "semicolon", '"': "apostrophe", + "<": "comma", ">": "dot", "?": "slash", +} + +ALNUM = set("abcdefghijklmnopqrstuvwxyz0123456789") + + +def connect(path, timeout=60): + """Connect to the monitor socket, retrying until QEMU is up.""" + deadline = time.time() + timeout + while True: + try: + s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + s.connect(path) + return s + except OSError: + if time.time() > deadline: + raise + time.sleep(0.2) + + +def sendkey(sock, keys): + sock.sendall(("sendkey %s\n" % keys).encode()) + + +def type_line(sock, line): + for ch in line: + if ch == " ": + sendkey(sock, "spc") + elif ch in BASE: + sendkey(sock, BASE[ch]) + elif ch in SHIFT: + sendkey(sock, "shift-" + SHIFT[ch]) + elif ch.isupper(): + sendkey(sock, "shift-" + ch.lower()) + elif ch in ALNUM: + sendkey(sock, ch) + else: + sys.stderr.write("warning: no sendkey mapping for %r\n" % ch) + continue + time.sleep(0.25) + sendkey(sock, "ret") + time.sleep(1.5) + + +def main(): + args = [a for a in sys.argv[1:] if a != "--sock"] + sock_path = SOCK + if "--sock" in sys.argv: + i = sys.argv.index("--sock") + sock_path = sys.argv[i + 1] + args = sys.argv[i + 2:] + if not args: + sys.stderr.write(__doc__ or "") + return 1 + sock = connect(sock_path) + # Let the monitor drain any startup banner before typing. + time.sleep(0.5) + for line in args: + try: + type_line(sock, line) + except OSError: + # Guest powered off (last line was usually "poweroff"). + break + return 0 + + +if __name__ == "__main__": + sys.exit(main()) -- cgit v1.2.3