From f0f369f6067843c877b8543cbe7fb09472b31201 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 28 Oct 2026 19:33:26 -0700 Subject: [PATCH] feat(e2e): add probes of display modes and of changing one --- .../qemu_windows/w1_display_change.py | 90 +++++++++++++++++++ .../qemu_windows/w1_display_modes.py | 67 ++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 e2e/platforms/qemu_windows/w1_display_change.py create mode 100644 e2e/platforms/qemu_windows/w1_display_modes.py diff --git a/e2e/platforms/qemu_windows/w1_display_change.py b/e2e/platforms/qemu_windows/w1_display_change.py new file mode 100644 index 00000000..1c71946f --- /dev/null +++ b/e2e/platforms/qemu_windows/w1_display_change.py @@ -0,0 +1,90 @@ +"""W1: what does kfw do when the resolution of a display changes? + +usage: python -m platforms.qemu_windows.w1_display_change GOLDEN BIN_DIR OUT [STATE] + +Plugs in a second display, sends two windows to it, changes its mode (through +display.ps1) to a larger and then a smaller one, and back, and every second +for 20 s prints the display's size as the OS has it, the daemon's monitor size +and work area, and whether the windows are inside the work area and clear of +each other. A probe: it prints what it saw. +""" + +import importlib +import sys +import time +from pathlib import Path + +from komorebi_vm.core.checks import Checks + +from .guest import Guest +from .run import BINARIES +from .windows_platform import WindowsPlatform + +HERE = Path(__file__).parent +SCRIPT = "C:\\e2e\\display.ps1" +DEVICE = "\\\\.\\DISPLAY2" +SIZES = [(1280, 720), (800, 600), (1024, 768)] + + +def display(guest: Guest, *args: str) -> str: + result = guest.agent.exec( + "powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", + "-File", SCRIPT, *args, + ) + return (result["stdout"] + result["stderr"]).strip() + + +def watch(platform: WindowsPlatform, moved, label: str, seconds: int = 20) -> None: + t0 = time.monotonic() + last = None + while time.monotonic() - t0 < seconds: + monitors = platform.state().monitors + displays = platform.displays() + if len(monitors) > 1 and len(displays) > 1: + monitor, shown = monitors[1], displays[1] + frames = [w.frame for c in moved + if (w := platform.os_window(c)) is not None] + inside = all(f.inside(monitor.work_area, 1) for f in frames) + apart = not any(a.overlaps(b) for i, a in enumerate(frames) + for b in frames[i + 1:]) + now = (f"OS {shown.w}x{shown.h}, daemon monitor " + f"{monitor.size.w}x{monitor.size.h}, work area " + f"{monitor.work_area.w}x{monitor.work_area.h}, windows " + f"inside {inside}, apart {apart}") + else: + now = f"monitors {len(monitors)}, displays {len(displays)}" + if now != last: + print(f"PASTE {label} +{time.monotonic() - t0:.0f}s: {now}") + last = now + time.sleep(1) + + +def main(argv: list[str]) -> int: + golden, bin_dir, out = (Path(a) for a in argv[:3]) + state = Path(argv[3]) if len(argv) > 3 else None + out.mkdir(parents=True, exist_ok=True) + tiling = importlib.import_module("komorebi_vm.core.scenarios.tiling") + with Guest(golden, out / "guest", state=state) as guest: + guest.upload(bin_dir, BINARIES) + guest.agent.put_file(HERE / "display.ps1", SCRIPT) + platform = WindowsPlatform(guest.qmp, guest.agent, out, scale=1.5) + platform.start_komorebi() + clients = tiling.run(platform, Checks()) + platform.add_display() + platform.wait_for(lambda: len(platform.state().monitors) == 2, 30) + moved = clients[1:] + for client in moved: + platform.activate(client) + platform.komorebic("move-to-monitor", "1") + platform.wait_for( + lambda c=client: platform.state().workspace_of( + c.title, monitor=1) is not None) + watch(platform, moved, "before", 3) + for width, height in SIZES: + print(f"PASTE {display(guest, 'set', DEVICE, str(width), str(height))}") + watch(platform, moved, f"at {width}x{height}") + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/e2e/platforms/qemu_windows/w1_display_modes.py b/e2e/platforms/qemu_windows/w1_display_modes.py new file mode 100644 index 00000000..bc4d6622 --- /dev/null +++ b/e2e/platforms/qemu_windows/w1_display_modes.py @@ -0,0 +1,67 @@ +"""W1: which display devices and modes does the guest have, and can one change? + +usage: python -m platforms.qemu_windows.w1_display_modes GOLDEN OUT STATE + +Plugs in a second display, prints the devices of the guest with the current +mode of each and the modes it lists, then tries to change the mode of each +device to the first listed other than the current one, and prints the +size the operating system reports for it afterwards. A probe: it prints what +it saw. +""" + +import re +import sys +import time +from pathlib import Path + +from .guest import Guest +from .windows_platform import WindowsPlatform + +HERE = Path(__file__).parent +SCRIPT = "C:\\e2e\\display.ps1" + + +def display(guest: Guest, *args: str) -> str: + result = guest.agent.exec( + "powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", + "-File", SCRIPT, *args, + ) + return (result["stdout"] + result["stderr"]).strip() + + +def main(argv: list[str]) -> int: + golden, out = Path(argv[0]), Path(argv[1]) + state = Path(argv[2]) if len(argv) > 2 else None + out.mkdir(parents=True, exist_ok=True) + with Guest(golden, out / "guest", state=state) as guest: + guest.agent.exec("cmd", "/c", "mkdir C:\\e2e 2>nul") + guest.agent.put_file(HERE / SCRIPT.split("\\")[-1], SCRIPT) + platform = WindowsPlatform(guest.qmp, guest.agent, out) + platform.add_display() + time.sleep(5) + listing = display(guest, "list") + for line in listing.splitlines(): + print(f"PASTE {line}") + device = None + for line in listing.splitlines(): + if line.startswith("device "): + device = line.split()[1] + elif line.strip().startswith("current"): + current = re.search(r"(\d+x\d+)", line).group(1) + elif line.strip().startswith("modes:") and device: + other = [m for m in line.split()[1:] if m != current] + if other: + wanted = sorted(other, key=lambda m: int(m.split("x")[0]))[0] + w, h = wanted.split("x") + print(f"PASTE {display(guest, 'set', device, w, h)}") + time.sleep(3) + print("PASTE displays now: " + ", ".join( + f"{d['monitor']}" for d in guest.agent.displays())) + print("PASTE " + "; ".join( + l for l in display(guest, "list").splitlines() + if "current" in l)) + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:]))