mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
feat(e2e): add the probes behind the Windows guest's findings
Each w1_*.py prints what it saw: the pointer, a second display, hotplug, the drag, the placement rule, focus follows mouse and what stop leaves hidden. W1.md has the results.
This commit is contained in:
1 parent
07ef8e93d6
commit
a8d0a5096d
12 files changed
+875
No files matched your search
@@ -0,0 +1,86 @@
|
||||
"""Where does a drag fall short: the input path, or the daemon?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_drag GOLDEN BIN_DIR OUT
|
||||
|
||||
Drags the right border of a plain `komorebi-testwin` that no daemon manages,
|
||||
by 30, 60 and 120 px, and prints the cursor Windows reports after each drag,
|
||||
the frame during the glide and the frame at the end. A probe: it records what
|
||||
it saw.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from .guest import Guest
|
||||
from .qmp import Qmp
|
||||
|
||||
CURSOR = (
|
||||
"Add-Type -AssemblyName System.Windows.Forms; "
|
||||
"$p = [System.Windows.Forms.Cursor]::Position; '{0},{1}' -f $p.X, $p.Y"
|
||||
)
|
||||
|
||||
|
||||
def frame(guest: Guest):
|
||||
for w in guest.agent.os_windows():
|
||||
if w["title"] == "w1":
|
||||
return w["frame"]
|
||||
return None
|
||||
|
||||
|
||||
def cursor(guest: Guest) -> str:
|
||||
out = guest.agent.exec("powershell", "-NoProfile", "-Command", CURSOR)
|
||||
return out["stdout"].strip()
|
||||
|
||||
|
||||
def drag(guest: Guest, qmp: Qmp, start, end, size, steps=25, ms=30):
|
||||
width, height = size
|
||||
qmp.pointer_move(*start, width, height)
|
||||
time.sleep(0.3)
|
||||
qmp.pointer_button(True)
|
||||
samples = []
|
||||
for i in range(1, steps + 1):
|
||||
x = start[0] + (end[0] - start[0]) * i // steps
|
||||
y = start[1] + (end[1] - start[1]) * i // steps
|
||||
qmp.pointer_move(x, y, width, height)
|
||||
time.sleep(ms / 1000)
|
||||
if i % 5 == 0:
|
||||
f = frame(guest)
|
||||
samples.append((x, f["left"] + f["right"] if f else None))
|
||||
after_glide = frame(guest)
|
||||
qmp.pointer_button(False)
|
||||
time.sleep(0.5)
|
||||
return samples, after_glide
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, bin_dir, out = (Path(a) for a in argv)
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
with Guest(golden, out / "guest") as guest:
|
||||
guest.upload(bin_dir, ["komorebi-testwin.exe"])
|
||||
guest.agent.spawn(
|
||||
"C:\\e2e\\bin\\komorebi-testwin.exe", "--title", "w1",
|
||||
"--size", "400x300",
|
||||
)
|
||||
time.sleep(3)
|
||||
monitor = guest.agent.displays()[0]["monitor"]
|
||||
size = (monitor["right"], monitor["bottom"])
|
||||
for dx in (30, 60, 120):
|
||||
f = frame(guest)
|
||||
right = f["left"] + f["right"]
|
||||
start = (right + 4, f["top"] + f["bottom"] // 2)
|
||||
end = (start[0] + dx, start[1])
|
||||
samples, glide = drag(guest, guest.qmp, start, end, size)
|
||||
after = frame(guest)
|
||||
print(f"PASTE dx={dx} asked end x={end[0]}")
|
||||
print(f"PASTE cursor after release: {cursor(guest)}")
|
||||
print(f"PASTE right edge before {right}, "
|
||||
f"at end of glide {glide['left'] + glide['right']}, "
|
||||
f"after release {after['left'] + after['right']}, "
|
||||
f"gain {after['left'] + after['right'] - right}")
|
||||
print(f"PASTE samples (pointer x, frame right edge): {samples}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,96 @@
|
||||
"""W1: how soon does focus follows mouse (the windows implementation) act?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_ffm GOLDEN BIN_DIR OUT
|
||||
|
||||
Opens the tiling windows, enables focus follows mouse, moves the pointer
|
||||
between two windows and prints how long each takes to get the focus; then
|
||||
turns it off with `toggle`, on with `enable`, and does the same, once with
|
||||
a single pointer move and once with a few small ones. 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
|
||||
|
||||
|
||||
def middle(platform, client):
|
||||
f = platform.os_window(client).frame
|
||||
return f.x + f.w // 2, f.y + f.h // 2
|
||||
|
||||
|
||||
def focused(platform, client) -> bool:
|
||||
w = platform.os_window(client)
|
||||
return w is not None and w.focused
|
||||
|
||||
|
||||
def timed(platform, label, target, point, wiggle=False) -> None:
|
||||
t0 = time.monotonic()
|
||||
platform.pointer.move(*point)
|
||||
seen = None
|
||||
while time.monotonic() - t0 < 15:
|
||||
if focused(platform, target):
|
||||
seen = time.monotonic() - t0
|
||||
break
|
||||
if wiggle:
|
||||
platform.pointer.move(point[0] + 3, point[1] + 3)
|
||||
platform.pointer.move(*point)
|
||||
time.sleep(0.25)
|
||||
print(f"PASTE {label}: focused after "
|
||||
f"{seen if seen is None else round(seen, 2)}s")
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, bin_dir, out = (Path(a) for a in argv[:3])
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
tiling = importlib.import_module("komorebi_vm.core.scenarios.tiling")
|
||||
with Guest(golden, out / "guest") as guest:
|
||||
guest.upload(bin_dir, BINARIES)
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out)
|
||||
platform.start_komorebi(log_level="debug")
|
||||
clients = tiling.run(platform, Checks())
|
||||
a, b = clients[0], clients[1]
|
||||
pa, pb = middle(platform, a), middle(platform, b)
|
||||
platform.komorebic("focus-follows-mouse", "enable")
|
||||
time.sleep(1)
|
||||
timed(platform, "first enable, over a", a, pa)
|
||||
timed(platform, "first enable, over b", b, pb)
|
||||
timed(platform, "first enable, back over a", a, pa)
|
||||
platform.komorebic("toggle-focus-follows-mouse",
|
||||
"--implementation", "windows")
|
||||
time.sleep(1)
|
||||
timed(platform, "toggled off, over b (expect never)", b, pb)
|
||||
platform.komorebic("focus-follows-mouse", "enable")
|
||||
time.sleep(1)
|
||||
timed(platform, "enabled again, over a", a, pa)
|
||||
timed(platform, "enabled again, over b", b, pb)
|
||||
timed(platform, "enabled again, back over a, wiggling", a, pa, True)
|
||||
timed(platform, "enabled again, over b, wiggling", b, pb, True)
|
||||
# variant 1: disable and enable, no toggle
|
||||
platform.komorebic("focus-follows-mouse", "disable")
|
||||
time.sleep(1)
|
||||
platform.komorebic("focus-follows-mouse", "enable")
|
||||
time.sleep(1)
|
||||
timed(platform, "disable+enable, over a", a, pa)
|
||||
timed(platform, "disable+enable, over b", b, pb)
|
||||
# variant 2: toggle twice
|
||||
platform.komorebic("toggle-focus-follows-mouse",
|
||||
"--implementation", "windows")
|
||||
time.sleep(1)
|
||||
platform.komorebic("toggle-focus-follows-mouse",
|
||||
"--implementation", "windows")
|
||||
time.sleep(1)
|
||||
timed(platform, "toggle twice, over a", a, pa)
|
||||
timed(platform, "toggle twice, over b", b, pb)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,88 @@
|
||||
"""W1: what does focus follows mouse need to work after it was turned off?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_ffm2 GOLDEN BIN_DIR OUT [STATE]
|
||||
|
||||
The failing sequence of the `focus_follows_mouse` scenario, in a fresh guest
|
||||
for each variant. With it on, the pointer goes over `a`, then `b`; it is
|
||||
turned off with `toggle`, the pointer parked at PARK; then the setting is turned
|
||||
on with HOW, the pointer goes over `a` and then over `b`, and the probe prints
|
||||
how long `b` took to get the focus. PARK is `b` (the scenario), `a`, or the
|
||||
corner of the display (off both windows); HOW is `enable` or `toggle`.
|
||||
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 .w1_ffm import focused, middle
|
||||
from .windows_platform import WindowsPlatform
|
||||
|
||||
VARIANTS = [
|
||||
("b", "enable"), # the scenario
|
||||
("corner", "enable"), # off both windows
|
||||
("a", "enable"), # on the window that has the focus
|
||||
("b", "toggle"), # turned on with the toggle
|
||||
]
|
||||
TOGGLE = ("toggle-focus-follows-mouse", "--implementation", "windows")
|
||||
|
||||
|
||||
def wait(platform, target, seconds=15):
|
||||
t0 = time.monotonic()
|
||||
while time.monotonic() - t0 < seconds:
|
||||
if focused(platform, target):
|
||||
return round(time.monotonic() - t0, 2)
|
||||
time.sleep(0.25)
|
||||
return None
|
||||
|
||||
|
||||
def one(golden, bin_dir, out, state, park, how) -> None:
|
||||
tiling = importlib.import_module("komorebi_vm.core.scenarios.tiling")
|
||||
with Guest(golden, out / f"guest-{park}-{how}", state=state) as guest:
|
||||
guest.upload(bin_dir, BINARIES)
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out, scale=1.5)
|
||||
platform.start_komorebi()
|
||||
clients = tiling.run(platform, Checks())
|
||||
a, b = clients[0], clients[1]
|
||||
pa, pb = middle(platform, a), middle(platform, b)
|
||||
spots = {"a": pa, "b": pb, "corner": (5, 5)}
|
||||
platform.komorebic("focus-follows-mouse", "enable")
|
||||
time.sleep(1)
|
||||
platform.pointer.move(*pa)
|
||||
wait(platform, a)
|
||||
platform.pointer.move(*pb)
|
||||
wait(platform, b)
|
||||
platform.pointer.move(*pa)
|
||||
wait(platform, a)
|
||||
platform.komorebic(*TOGGLE)
|
||||
time.sleep(1)
|
||||
platform.pointer.move(*spots[park])
|
||||
time.sleep(3)
|
||||
if how == "enable":
|
||||
platform.komorebic("focus-follows-mouse", "enable")
|
||||
else:
|
||||
platform.komorebic(*TOGGLE)
|
||||
time.sleep(1)
|
||||
platform.pointer.move(*pa)
|
||||
wait(platform, a, 3)
|
||||
platform.pointer.move(*pb)
|
||||
print(f"PASTE parked off at {park}, turned on with {how}: "
|
||||
f"b focused after {wait(platform, b)}s")
|
||||
|
||||
|
||||
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)
|
||||
for park, how in VARIANTS:
|
||||
one(golden, bin_dir, out, state, park, how)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,67 @@
|
||||
"""W1: which step of the focus_follows_mouse scenario makes its last check fail?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_ffm3 GOLDEN BIN_DIR OUT STATE
|
||||
|
||||
The scenario's steps, in a fresh guest for each variant, with the pieces that
|
||||
differ from `w1_ffm2` switched on or off: STATE (a `komorebic state` before
|
||||
the toggle) and POLL (the scenario's 3 s poll of the second window while the
|
||||
setting is off, instead of a sleep). Prints whether the second window got the
|
||||
focus after the setting was turned on again. A probe.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import itertools
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
|
||||
from .guest import Guest
|
||||
from .run import BINARIES
|
||||
from .w1_ffm import focused, middle
|
||||
from .w1_ffm2 import TOGGLE, wait
|
||||
from .windows_platform import WindowsPlatform
|
||||
|
||||
|
||||
def one(golden, bin_dir, out, state, with_state, poll) -> None:
|
||||
tiling = importlib.import_module("komorebi_vm.core.scenarios.tiling")
|
||||
name = f"state{int(with_state)}-poll{int(poll)}"
|
||||
with Guest(golden, out / name, state=state) as guest:
|
||||
guest.upload(bin_dir, BINARIES)
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out, scale=1.5)
|
||||
platform.start_komorebi()
|
||||
a, b = tiling.run(platform, Checks())[:2]
|
||||
pa, pb = middle(platform, a), middle(platform, b)
|
||||
platform.komorebic("focus-follows-mouse", "enable")
|
||||
time.sleep(1)
|
||||
for target, point in ((a, pa), (b, pb), (a, pa)):
|
||||
platform.pointer.move(*point)
|
||||
wait(platform, target, 10)
|
||||
if with_state:
|
||||
platform.state().focused_title()
|
||||
platform.komorebic(*TOGGLE)
|
||||
time.sleep(1)
|
||||
platform.pointer.move(*pb)
|
||||
if poll:
|
||||
platform.wait_for(lambda: focused(platform, b), timeout=3)
|
||||
else:
|
||||
time.sleep(4.5)
|
||||
platform.komorebic("focus-follows-mouse", "enable")
|
||||
time.sleep(1)
|
||||
platform.pointer.move(*pa)
|
||||
wait(platform, a, 10)
|
||||
platform.pointer.move(*pb)
|
||||
print(f"PASTE {name}: b focused after {wait(platform, b)}s")
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, bin_dir, out, state = (Path(a) for a in argv[:4])
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
for with_state, poll in itertools.product((False, True), repeat=2):
|
||||
one(golden, bin_dir, out, state, with_state, poll)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,108 @@
|
||||
"""W1: can the second QXL display be hotplugged and unplugged at runtime?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_hotplug GOLDEN QXL_ISO OUT [BIN_DIR]
|
||||
|
||||
The guest boots with one display, a hotplug-capable PCIe root port and the
|
||||
driver CD; `device_add` then adds a QXL device through QMP and `device_del`
|
||||
removes it. Prints what the agent and (with BIN_DIR) kfw saw at each step.
|
||||
A probe: it records what it saw.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from .agent import AgentError
|
||||
from .guest import Guest
|
||||
from .windows_platform import WindowsPlatform
|
||||
|
||||
POWERSHELL = ["powershell", "-NoProfile", "-Command"]
|
||||
|
||||
|
||||
def seen(guest: Guest, platform: WindowsPlatform | None, label: str) -> None:
|
||||
displays = guest.agent.displays()
|
||||
line = f"PASTE {label}: windows displays {len(displays)}"
|
||||
if platform is not None:
|
||||
line += f", kfw monitors {len(platform.state().monitors)}"
|
||||
print(line)
|
||||
for d in displays:
|
||||
print("PASTE ", d["monitor"], "primary" if d["primary"] else "")
|
||||
|
||||
|
||||
def wait_displays(guest: Guest, count: int, timeout: float = 40) -> bool:
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
try:
|
||||
if len(guest.agent.displays()) == count:
|
||||
return True
|
||||
except (OSError, ValueError, AgentError) as e:
|
||||
# the agent dropped the connection: say so, and reconnect
|
||||
print("PASTE agent call failed:", type(e).__name__, e)
|
||||
try:
|
||||
guest.agent.connect(timeout=10)
|
||||
except AgentError:
|
||||
print("PASTE agent did not come back in 10 s")
|
||||
time.sleep(1)
|
||||
return False
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, qxl_iso, out = (Path(a) for a in argv[:3])
|
||||
bin_dir = Path(argv[3]) if len(argv) > 3 else None
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
extra = [
|
||||
"-device", "pcie-root-port,id=rp1,chassis=1,slot=1",
|
||||
"-drive", f"if=none,id=qd,file={qxl_iso},media=cdrom,readonly=on",
|
||||
"-device", "ide-cd,drive=qd,bus=ide.0",
|
||||
]
|
||||
with Guest(golden, out / "guest", extra=extra) as guest:
|
||||
platform = None
|
||||
if bin_dir:
|
||||
guest.upload(bin_dir, ["komorebi.exe", "komorebic.exe"])
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out)
|
||||
platform.start_komorebi()
|
||||
time.sleep(3)
|
||||
seen(guest, platform, "before")
|
||||
|
||||
found = guest.agent.exec(
|
||||
*POWERSHELL,
|
||||
"(Get-PSDrive -PSProvider FileSystem | Where-Object "
|
||||
"{ Test-Path (Join-Path $_.Root 'qxldod.inf') }).Root",
|
||||
)["stdout"].strip()
|
||||
# the driver goes into the store first, so the device gets it on
|
||||
# arrival, as it will from the golden image
|
||||
guest.agent.exec("pnputil", "/add-driver", f"{found}qxldod.inf")
|
||||
|
||||
t0 = time.monotonic()
|
||||
guest.qmp.execute(
|
||||
"device_add", driver="qxl", id="qxl2", bus="rp1",
|
||||
ram_size_mb=64, vram_size_mb=64, vgamem_mb=16,
|
||||
)
|
||||
ok = wait_displays(guest, 2)
|
||||
took = time.monotonic() - t0
|
||||
print(f"PASTE device_add: second display after {took:.1f}s:", ok)
|
||||
time.sleep(3)
|
||||
guest.qmp.screendump(out / "after-add.png")
|
||||
seen(guest, platform, "after device_add")
|
||||
|
||||
t0 = time.monotonic()
|
||||
guest.qmp.execute("device_del", id="qxl2")
|
||||
ok = wait_displays(guest, 1)
|
||||
took = time.monotonic() - t0
|
||||
print(f"PASTE device_del: one display again after {took:.1f}s:", ok)
|
||||
time.sleep(3)
|
||||
seen(guest, platform, "after device_del")
|
||||
if platform is not None:
|
||||
t0 = time.monotonic()
|
||||
while time.monotonic() - t0 < 45:
|
||||
if len(platform.state().monitors) == 1:
|
||||
break
|
||||
time.sleep(1)
|
||||
n = len(platform.state().monitors)
|
||||
print(f"PASTE kfw monitors {n} after a further "
|
||||
f"{time.monotonic() - t0:.0f}s")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,60 @@
|
||||
"""W1: how long does kfw take to drop a monitor that was unplugged?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_hotplug_lag GOLDEN BIN_DIR OUT [N]
|
||||
|
||||
N times (default 5): plugs a display and, once kfw has a monitor for it,
|
||||
unplugs it, then polls the OS and `komorebic state` every second for up to
|
||||
90 s and prints when each says one display. With the daemon at debug level
|
||||
the daemon's log of each round is kept in OUT. A probe: it prints what it saw.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from .guest import Guest
|
||||
from .run import BINARIES, _fetch_logs
|
||||
from .windows_platform import WindowsPlatform
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, bin_dir, out = (Path(a) for a in argv[:3])
|
||||
rounds = int(argv[3]) if len(argv) > 3 else 5
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
with Guest(golden, out / "guest") as guest:
|
||||
guest.upload(bin_dir, BINARIES)
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out)
|
||||
platform.start_komorebi(log_level="debug")
|
||||
for n in range(1, rounds + 1):
|
||||
print(f"PASTE load {open('/proc/loadavg').read().split()[0]}")
|
||||
platform.add_display()
|
||||
deadline = time.monotonic() + 60
|
||||
while time.monotonic() < deadline:
|
||||
if len(platform.state().monitors) == 2:
|
||||
break
|
||||
time.sleep(1)
|
||||
print(f"PASTE round {n}: kfw monitors "
|
||||
f"{len(platform.state().monitors)} after the plug")
|
||||
t0 = time.monotonic()
|
||||
platform.remove_display()
|
||||
os_after = time.monotonic() - t0
|
||||
seen_os = seen_kfw = None
|
||||
while time.monotonic() - t0 < 90:
|
||||
if seen_os is None and len(platform.displays()) == 1:
|
||||
seen_os = time.monotonic() - t0
|
||||
if len(platform.state().monitors) == 1:
|
||||
seen_kfw = time.monotonic() - t0
|
||||
break
|
||||
time.sleep(1)
|
||||
print(f"PASTE round {n}: remove_display returned after "
|
||||
f"{os_after:.1f}s; OS one display at "
|
||||
f"{seen_os if seen_os is None else round(seen_os, 1)}s; "
|
||||
f"kfw one monitor at "
|
||||
f"{seen_kfw if seen_kfw is None else round(seen_kfw, 1)}s")
|
||||
# the daemon's log of all the rounds
|
||||
_fetch_logs(guest, out)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,56 @@
|
||||
"""W1: does kfw accept an integer as `initial_window_placement_rules`?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_placement_int GOLDEN BIN_DIR OUT
|
||||
|
||||
Starts komorebi.exe with a config whose rules are the number 2, then the
|
||||
string "2", and prints whether it stayed up and what it wrote to stderr.
|
||||
A probe: it records what it saw.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from .guest import Guest
|
||||
from .run import BINARIES
|
||||
from .windows_platform import GUEST_BIN, WindowsPlatform
|
||||
|
||||
SCRIPT = (
|
||||
"$p = Start-Process -FilePath '{exe}' -ArgumentList "
|
||||
"'--clean-state','--config','C:\\e2e\\komorebi.json' "
|
||||
"-RedirectStandardError C:\\e2e\\err.txt -PassThru -WindowStyle Hidden; "
|
||||
"Start-Sleep 6; "
|
||||
"\"exited=$($p.HasExited) code=$($p.ExitCode)\"; "
|
||||
"Get-Content C:\\e2e\\err.txt; "
|
||||
"if (-not $p.HasExited) {{ & '{c}' stop | Out-Null; Start-Sleep 2 }}"
|
||||
)
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, bin_dir, out = (Path(a) for a in argv[:3])
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
with Guest(golden, out / "guest") as guest:
|
||||
guest.upload(bin_dir, BINARIES)
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out)
|
||||
for rules in (2, "2"):
|
||||
config = {"monitors": [{"workspaces": [
|
||||
{"name": "a", "layout": "BSP",
|
||||
"initial_window_placement_rules": rules}]}]}
|
||||
local = out / "komorebi.json"
|
||||
local.write_text(json.dumps(config))
|
||||
guest.agent.put_file(local, "C:\\e2e\\komorebi.json")
|
||||
result = guest.agent.exec(
|
||||
"powershell", "-NoProfile", "-Command",
|
||||
SCRIPT.format(
|
||||
exe=f"{GUEST_BIN}\\komorebi.exe",
|
||||
c=f"{GUEST_BIN}\\komorebic.exe",
|
||||
),
|
||||
)
|
||||
print(f"PASTE rules={rules!r}:")
|
||||
for line in (result["stdout"] + result["stderr"]).splitlines():
|
||||
print("PASTE ", line)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,52 @@
|
||||
"""W1: where does the QMP tablet put the pointer with two displays?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_pointer2 GOLDEN OUT
|
||||
|
||||
Adds a second display, moves the absolute tablet to a few fractions of its
|
||||
range and asks Windows where the cursor is. A probe: it prints what it saw.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from .guest import Guest
|
||||
from .qmp import POINTER_MAX
|
||||
from .windows_platform import WindowsPlatform
|
||||
|
||||
CURSOR = (
|
||||
"Add-Type -AssemblyName System.Windows.Forms; "
|
||||
"$p = [System.Windows.Forms.Cursor]::Position; \"$($p.X),$($p.Y)\""
|
||||
)
|
||||
|
||||
|
||||
def cursor(guest: Guest) -> str:
|
||||
return guest.agent.exec(
|
||||
"powershell", "-NoProfile", "-Command", CURSOR
|
||||
)["stdout"].strip()
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, out = (Path(a) for a in argv[:2])
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
with Guest(golden, out / "guest") as guest:
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out)
|
||||
platform.add_display()
|
||||
time.sleep(3)
|
||||
for d in guest.agent.displays():
|
||||
print("PASTE display", d["monitor"],
|
||||
"primary" if d["primary"] else "")
|
||||
for fraction in (0.0, 0.25, 0.5, 0.75, 1.0):
|
||||
value = int(POINTER_MAX * fraction)
|
||||
guest.qmp.execute("input-send-event", events=[
|
||||
{"type": "abs", "data": {"axis": "x", "value": value}},
|
||||
{"type": "abs", "data": {"axis": "y", "value": 8000}},
|
||||
])
|
||||
time.sleep(0.5)
|
||||
print(f"PASTE tablet x {fraction:.2f} ({value}) -> cursor",
|
||||
cursor(guest))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,71 @@
|
||||
"""W1: does QMP pointer input drive a Windows guest, and is there a second
|
||||
display?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_probe GOLDEN BIN_DIR OUT
|
||||
|
||||
Prints a PASTE block. Draft of a probe, not a test: it records what it saw.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from .guest import Guest
|
||||
|
||||
|
||||
def _frame(agent, title):
|
||||
for w in agent.os_windows():
|
||||
if w["title"] == title:
|
||||
return w["frame"]
|
||||
return None
|
||||
|
||||
|
||||
def pointer(golden: Path, bin_dir: Path, out: Path) -> None:
|
||||
with Guest(golden, out / "pointer") as guest:
|
||||
guest.upload(bin_dir, ["komorebi-testwin.exe"])
|
||||
agent, qmp = guest.agent, guest.qmp
|
||||
agent.spawn("C:\\e2e\\bin\\komorebi-testwin.exe", "--title", "w1")
|
||||
time.sleep(3)
|
||||
before = _frame(agent, "w1")
|
||||
print("PASTE pointer before", before)
|
||||
display = agent.displays()[0]["monitor"]
|
||||
w, h = display["right"], display["bottom"]
|
||||
# the middle of the title bar, 15 px below the frame's top edge
|
||||
x = before["left"] + before["right"] // 2
|
||||
y = before["top"] + 15
|
||||
qmp.pointer_move(x, y, w, h)
|
||||
time.sleep(0.3)
|
||||
qmp.pointer_button(True)
|
||||
for step in range(1, 11):
|
||||
qmp.pointer_move(x + 20 * step, y + 10 * step, w, h)
|
||||
time.sleep(0.05)
|
||||
qmp.pointer_button(False)
|
||||
time.sleep(1)
|
||||
after = _frame(agent, "w1")
|
||||
print("PASTE pointer after", after)
|
||||
moved = (after["left"] - before["left"], after["top"] - before["top"])
|
||||
print("PASTE pointer drag moved the window by", moved,
|
||||
"(asked for (200, 100))")
|
||||
qmp.screendump(out / "pointer-after.png")
|
||||
|
||||
|
||||
def second_display(golden: Path, out: Path) -> None:
|
||||
extra = ["-device", "secondary-vga,id=vga2"]
|
||||
with Guest(golden, out / "display", extra=extra) as guest:
|
||||
time.sleep(5)
|
||||
shown = guest.agent.displays()
|
||||
print("PASTE displays seen by Windows with a second VGA:", len(shown))
|
||||
for d in shown:
|
||||
print("PASTE ", d)
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, bin_dir, out = (Path(a) for a in argv)
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
pointer(golden, bin_dir, out)
|
||||
second_display(golden, out)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,72 @@
|
||||
"""W1: a second monitor from a second QXL device, with Red Hat's signed
|
||||
`qxldod` display driver from virtio-win.
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_qxl GOLDEN QXL_ISO OUT [BIN_DIR]
|
||||
|
||||
QXL_ISO holds the files of virtio-win's qxldod/w10/amd64. Prints what it
|
||||
saw; a probe, not a test.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from .guest import Guest
|
||||
from .windows_platform import WindowsPlatform
|
||||
|
||||
QXL = "qxl,id=qxl2,ram_size_mb=64,vram_size_mb=64,vgamem_mb=16"
|
||||
POWERSHELL = ["powershell", "-NoProfile", "-Command"]
|
||||
|
||||
|
||||
def show(guest: Guest, label: str) -> None:
|
||||
print(f"PASTE {label}: displays", len(guest.agent.displays()))
|
||||
for d in guest.agent.displays():
|
||||
print("PASTE ", d)
|
||||
video = guest.agent.exec(
|
||||
*POWERSHELL,
|
||||
"Get-CimInstance Win32_VideoController | "
|
||||
"ForEach-Object { '{0} | {1} | code {2}' -f "
|
||||
"$_.Name, $_.Status, $_.ConfigManagerErrorCode }",
|
||||
)
|
||||
print(f"PASTE {label}: video controllers\n{video['stdout']}")
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, qxl_iso, out = (Path(a) for a in argv[:3])
|
||||
bin_dir = Path(argv[3]) if len(argv) > 3 else None
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
extra = [
|
||||
"-device", QXL,
|
||||
"-drive", f"if=none,id=qd,file={qxl_iso},media=cdrom,readonly=on",
|
||||
"-device", "ide-cd,drive=qd,bus=ide.0",
|
||||
]
|
||||
with Guest(golden, out / "guest", extra=extra) as guest:
|
||||
time.sleep(5)
|
||||
show(guest, "before the driver")
|
||||
found = guest.agent.exec(
|
||||
*POWERSHELL,
|
||||
"(Get-PSDrive -PSProvider FileSystem | Where-Object "
|
||||
"{ Test-Path (Join-Path $_.Root 'qxldod.inf') }).Root",
|
||||
)["stdout"].strip()
|
||||
print("PASTE driver CD at", repr(found))
|
||||
added = guest.agent.exec("pnputil", "/add-driver", f"{found}qxldod.inf",
|
||||
"/install")
|
||||
print("PASTE pnputil /add-driver:", added["status"],
|
||||
added["stdout"][-600:], added["stderr"][-300:])
|
||||
guest.agent.exec("pnputil", "/scan-devices")
|
||||
time.sleep(15)
|
||||
show(guest, "after the driver")
|
||||
guest.qmp.screendump(out / "after.png")
|
||||
if bin_dir:
|
||||
guest.upload(bin_dir, ["komorebi.exe", "komorebic.exe"])
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out)
|
||||
platform.start_komorebi()
|
||||
state = platform.state()
|
||||
print("PASTE komorebi monitors:", len(state.monitors))
|
||||
for m in state.monitors:
|
||||
print("PASTE ", m.id, m.size, m.work_area)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,46 @@
|
||||
"""Does kfw lose a window that is sent to a monitor that does not exist?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_sendmon GOLDEN BIN_DIR OUT
|
||||
|
||||
One display, three tiled windows, then `komorebic send-to-monitor 1`; prints
|
||||
the daemon's window count and the OS's before and after. A probe.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from komorebi_vm.core.checks import Checks
|
||||
from komorebi_vm.core.scenarios import tiling
|
||||
|
||||
from .guest import Guest
|
||||
from .windows_platform import WindowsPlatform
|
||||
|
||||
|
||||
def counts(platform: WindowsPlatform, titles: list[str]) -> str:
|
||||
managed = platform.state().managed()
|
||||
visible = [t for t in titles if platform.os_window_by_title(t)]
|
||||
return f"daemon manages {managed}, OS has {len(visible)}: {visible}"
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, bin_dir, out = (Path(a) for a in argv)
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
with Guest(golden, out / "guest") as guest:
|
||||
guest.upload(bin_dir, ["komorebi.exe", "komorebic.exe",
|
||||
"komorebi-testwin.exe"])
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out)
|
||||
platform.start_komorebi()
|
||||
clients = tiling.run(platform, Checks())
|
||||
titles = [c.title for c in clients]
|
||||
print("PASTE before:", counts(platform, titles))
|
||||
status, text = platform.komorebic_status("send-to-monitor", "1")
|
||||
print("PASTE send-to-monitor 1 ->", status, repr(text.strip()))
|
||||
time.sleep(3)
|
||||
print("PASTE after: ", counts(platform, titles))
|
||||
platform.screenshot("after")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,73 @@
|
||||
"""W1: what does `komorebic stop` do to windows that kfw has put away?
|
||||
|
||||
usage: python -m platforms.qemu_windows.w1_stop_hidden GOLDEN BIN_DIR OUT
|
||||
|
||||
Opens the tiling windows, sends one to workspace 1 (kfw cloaks it) and
|
||||
minimizes another, stops the daemon, and prints for each window whether it
|
||||
is cloaked or minimized and where it is; then starts the daemon again and
|
||||
prints the same, with the workspace the daemon has each on. A probe: it
|
||||
records what it saw, and the lifecycle scenario asks for none of this.
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
|
||||
def show(platform: WindowsPlatform, clients: list, label: str) -> None:
|
||||
print(f"PASTE {label}")
|
||||
for c in clients:
|
||||
w = platform.os_window_by_title(c.title)
|
||||
if w is None:
|
||||
print(f"PASTE {c.title}: no window")
|
||||
continue
|
||||
print(f"PASTE {c.title}: cloaked={w['cloaked']} "
|
||||
f"minimized={w.get('minimized')} frame={w['frame']}")
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
golden, bin_dir, out = (Path(a) for a in argv[:3])
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
tiling = importlib.import_module("komorebi_vm.core.scenarios.tiling")
|
||||
with Guest(golden, out / "guest") as guest:
|
||||
guest.upload(bin_dir, BINARIES)
|
||||
platform = WindowsPlatform(guest.qmp, guest.agent, out)
|
||||
platform.start_komorebi()
|
||||
clients = tiling.run(platform, Checks())
|
||||
away, minimized = clients[-1], clients[0]
|
||||
|
||||
platform.activate(away)
|
||||
platform.wait_for(lambda: True, 1)
|
||||
platform.komorebic("send-to-workspace", "1")
|
||||
platform.wait_for(lambda: platform.hidden(away))
|
||||
window = platform.os_window_by_title(minimized.title)
|
||||
guest.agent.call("minimize", hwnd=window["hwnd"])
|
||||
time.sleep(2)
|
||||
show(platform, clients, "before the stop (win1 minimized, "
|
||||
f"{away.title} on workspace 1)")
|
||||
|
||||
platform.komorebic("stop")
|
||||
platform.wait_for(
|
||||
lambda: platform.komorebic_status("state")[0] != 0, 20
|
||||
)
|
||||
time.sleep(2)
|
||||
show(platform, clients, "after the stop")
|
||||
|
||||
platform.start_komorebi()
|
||||
time.sleep(3)
|
||||
show(platform, clients, "after the start")
|
||||
state = platform.state()
|
||||
# workspace 1 is gone after a start without state, so ask for 0 only
|
||||
print(f"PASTE workspace 0 holds {state.containers(0)}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
Reference in new issue
Block a user