mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-27 04:35:27 +00:00
scripts: cover D3D12, macOS keyboard events and process lifecycle in acceptance
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
This commit is contained in:
1 parent
9071321fe4
commit
14a54f8bb9
3 files changed
+272
-10
No files matched your search
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# Run the integrated-workload acceptance sequence through betterxen-hybrid on this Mac.
|
||||
# Run the integrated-workload acceptance sequence through `betterxen hybrid` on this Mac.
|
||||
# Every line printed is "ok <check>" or "FAIL <check>"; the exit status is non-zero if any
|
||||
# check failed. Raw JSON records and logs are kept under the output directory.
|
||||
#
|
||||
@@ -8,7 +8,9 @@
|
||||
#
|
||||
# Needs CrossOver, an existing win11_64 bottle, Rust 1.100.0, the pinned llvm-mingw
|
||||
# (docs/research/hybrid-toolchain.md), and for the on-screen check a GUI session with the
|
||||
# Screen Recording permission. Opens a small window; do not run on a busy machine.
|
||||
# Screen Recording and Accessibility permissions (the latter for the keyboard check, which
|
||||
# brings the test window to the front: do not type while it runs). Opens small windows; do not
|
||||
# run on a busy machine or alongside anything else using the same bottle.
|
||||
set -u
|
||||
TC=${1:?usage: $0 <llvm-mingw-dir> <bottle> [soak-frames] [repeats]}
|
||||
BOTTLE=${2:?name an existing bottle}
|
||||
@@ -22,19 +24,22 @@ failed=0
|
||||
ok() { echo "ok $1"; }
|
||||
bad() { echo "FAIL $1"; failed=1; }
|
||||
|
||||
(cd "$ROOT" && cargo build --locked --release -p betterxen-hybrid) >"$OUT/build-runner.log" 2>&1 ||
|
||||
(cd "$ROOT" && cargo build --locked --release -p betterxen -p betterxen-hybrid) >"$OUT/build-runner.log" 2>&1 ||
|
||||
{ bad "build runner"; exit 1; }
|
||||
"$ROOT/workloads/d3d11-integrated/build.sh" "$TC" "$OUT/bin" >"$OUT/build-workload.log" 2>&1 ||
|
||||
{ bad "build workload"; exit 1; }
|
||||
R="${CARGO_TARGET_DIR:-$ROOT/target}/release/betterxen-hybrid"
|
||||
"$ROOT/workloads/d3d12-integrated/build.sh" "$TC" "$OUT/bin" >"$OUT/build-workload12.log" 2>&1 ||
|
||||
{ bad "build D3D12 workload"; exit 1; }
|
||||
BX="${CARGO_TARGET_DIR:-$ROOT/target}/release/betterxen"
|
||||
EXE12="$OUT/bin/d3d12-integrated.exe"
|
||||
EXE="$OUT/bin/d3d11-integrated.exe"
|
||||
git -C "$ROOT" rev-parse HEAD >"$OUT/commit.txt"
|
||||
git -C "$ROOT" status --porcelain >>"$OUT/commit.txt"
|
||||
"$R" receipt >"$OUT/receipt.json" 2>&1
|
||||
"$BX" hybrid receipt >"$OUT/receipt.json" 2>&1
|
||||
|
||||
if "$R" doctor --bottle "$BOTTLE" >"$OUT/doctor.json" 2>&1; then ok "A environment"; else
|
||||
if "$BX" hybrid doctor --bottle "$BOTTLE" >"$OUT/doctor.json" 2>&1; then ok "A environment"; else
|
||||
bad "A environment (see doctor.json)"; exit 1; fi
|
||||
if "$R" inspect "$EXE" >"$OUT/inspect.json" 2>&1; then ok "B executable identified"; else bad "B inspect"; fi
|
||||
if "$BX" hybrid inspect "$EXE" >"$OUT/inspect.json" 2>&1; then ok "B executable identified"; else bad "B inspect"; fi
|
||||
|
||||
GATES=runtime.threads,runtime.memory,runtime.exceptions,runtime.time,runtime.files,graphics.init,shader.compile,frame.first,frame.continuous,resources.churn,input,memory.bounded,shutdown
|
||||
|
||||
@@ -45,7 +50,7 @@ run() {
|
||||
while [ $# -gt 0 ] && [ "$1" != -- ]; do opts="$opts $1"; shift; done
|
||||
shift
|
||||
# shellcheck disable=SC2086 # options are fixed words from this script
|
||||
"$R" run --bottle "$BOTTLE" --expect "PASS integrated" $opts -- "$EXE" "$@" \
|
||||
"$BX" hybrid run --bottle "$BOTTLE" --expect "PASS integrated" $opts -- "$EXE" "$@" \
|
||||
>"$OUT/$name.json" 2>"$OUT/$name.log"
|
||||
got=$(sed -n 's/^ "classification": "\(.*\)",$/\1/p' "$OUT/$name.json")
|
||||
case "$got" in
|
||||
@@ -65,10 +70,10 @@ if pgrep -f 'd3d11-integrated\.exe' >/dev/null; then bad "hung workload still ru
|
||||
else ok "hung workload removed"; fi
|
||||
run recovery-after-hang passed --require-gates "$GATES" --timeout 120 -- --frames 128
|
||||
|
||||
if python3 "$ROOT/workloads/d3d11-integrated/check_window.py" "$R" "$BOTTLE" "$EXE" \
|
||||
if python3 "$ROOT/workloads/d3d11-integrated/check_window.py" "${CARGO_TARGET_DIR:-$ROOT/target}/release/betterxen-hybrid" "$BOTTLE" "$EXE" \
|
||||
--keep "$OUT/window.png" >"$OUT/window.log" 2>&1; then ok "F on-screen frame"; else
|
||||
bad "F on-screen frame: $(cat "$OUT/window.log")"; fi
|
||||
if python3 "$ROOT/workloads/d3d11-integrated/check_window.py" "$R" "$BOTTLE" "$EXE" \
|
||||
if python3 "$ROOT/workloads/d3d11-integrated/check_window.py" "${CARGO_TARGET_DIR:-$ROOT/target}/release/betterxen-hybrid" "$BOTTLE" "$EXE" \
|
||||
--fault depth >"$OUT/window-negative.log" 2>&1; then bad "on-screen check accepted a wrong image";
|
||||
else
|
||||
if grep -q 'samples differ' "$OUT/window-negative.log"; then ok "on-screen negative control";
|
||||
@@ -80,6 +85,55 @@ while [ "$i" -le "$REPEATS" ]; do
|
||||
run "I-repeat-$i" passed --require-gates "$GATES" --timeout 180 -- --frames 600
|
||||
i=$((i + 1))
|
||||
done
|
||||
# Direct3D 12. Under D3DMetal (CrossOver 26.3) a destroyed D3D12 swapchain leaves a device
|
||||
# reference, so the `shutdown` gate fails. That is reported as KNOWN only when it is the sole
|
||||
# failing gate; any other failure is a failure.
|
||||
d12_summary() {
|
||||
python3 - "$1" <<'PY'
|
||||
import json, re, sys
|
||||
j = json.load(open(sys.argv[1]))
|
||||
failed = sorted(g["name"] for g in j["gates"] if not g["passed"])
|
||||
digest = "".join(re.findall(r"digest=([0-9a-f]+)", " ".join(g["detail"] for g in j["gates"])))
|
||||
backend = j["backend_detected"].split(" ")[0]
|
||||
print(j["classification"], backend, ",".join(failed) or "-", digest or "-")
|
||||
PY
|
||||
}
|
||||
digest11=$(sed -n 's/.*digest=\([0-9a-f]*\).*/\1/p' "$OUT/C-F-G-H-full.json" | head -1)
|
||||
BX_SECRET_PROBE=1 "$BX" hybrid run --bottle "$BOTTLE" --timeout 180 --stall-timeout 60 -- "$EXE12" \
|
||||
--expect-absent-env BX_SECRET_PROBE >"$OUT/d3d12-full.json" 2>"$OUT/d3d12-full.log"
|
||||
read -r class backend failed12 digest12 <<EOT
|
||||
$(d12_summary "$OUT/d3d12-full.json")
|
||||
EOT
|
||||
case "$class:$backend:$failed12" in
|
||||
passed:*:-) ok "D3D12 all gates (backend $backend)" ;;
|
||||
failed_exit_1:d3dmetal:shutdown)
|
||||
ok "D3D12 all gates but shutdown"
|
||||
echo "KNOWN D3D12 shutdown: D3DMetal retains a device reference per swapchain" ;;
|
||||
*) bad "D3D12: $class backend=$backend failed=$failed12" ;;
|
||||
esac
|
||||
if [ -n "$digest11" ] && [ "$digest11" = "$digest12" ]; then ok "D3D11 and D3D12 pixel digests equal ($digest12)";
|
||||
else bad "pixel digests differ: d3d11=$digest11 d3d12=$digest12"; fi
|
||||
for fault in color blank stale input depth upload; do
|
||||
"$BX" hybrid run --bottle "$BOTTLE" --timeout 90 -- "$EXE12" --frames 128 --fault "$fault" \
|
||||
>"$OUT/d3d12-negative-$fault.json" 2>/dev/null
|
||||
read -r class backend failed12 digest12 <<EOT
|
||||
$(d12_summary "$OUT/d3d12-negative-$fault.json")
|
||||
EOT
|
||||
# the fault must break a gate other than the known shutdown one
|
||||
case "$class:${failed12%shutdown}" in
|
||||
failed_exit_1:?*) ok "D3D12 negative-$fault ($failed12)" ;;
|
||||
*) bad "D3D12 negative-$fault: $class failed=$failed12" ;;
|
||||
esac
|
||||
done
|
||||
if python3 "$ROOT/workloads/d3d12-integrated/send_keys.py" "$BX" "$BOTTLE" "$EXE12" >"$OUT/keys.log" 2>&1;
|
||||
then ok "H macOS keyboard events"; else bad "H keyboard: $(tail -1 "$OUT/keys.log")"; fi
|
||||
if python3 "$ROOT/workloads/d3d12-integrated/send_keys.py" "$BX" "$BOTTLE" "$EXE12" --keys up,up \
|
||||
--expect fail >"$OUT/keys-negative.log" 2>&1; then ok "keyboard negative control";
|
||||
else bad "keyboard negative control"; fi
|
||||
if python3 "$ROOT/scripts/hybrid/accept-lifecycle.py" "$BX" "$BOTTLE" "$EXE" >"$OUT/lifecycle.log" 2>&1;
|
||||
then ok "lifecycle: signals, kill and stop, repeated launch"; else
|
||||
bad "lifecycle (see lifecycle.log)"; grep FAIL "$OUT/lifecycle.log"; fi
|
||||
|
||||
run I-soak passed --require-gates "$GATES" --timeout 1800 --stall-timeout 60 -- --frames "$SOAK" --verify-every 500
|
||||
|
||||
echo "records: $OUT"
|
||||
|
||||
Executable
+123
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Process lifecycle checks for the hybrid runner against an installed CrossOver.
|
||||
|
||||
Uses the Direct3D 11 workload: `--fault hang` makes a program that never exits, and a normal
|
||||
run shows recovery. Prints "ok"/"FAIL" per check and exits non-zero on any failure. Do not
|
||||
run anything else in the same bottle meanwhile: stopping a run stops the whole bottle.
|
||||
|
||||
usage: accept-lifecycle.py RUNNER BOTTLE D3D11_EXE [--launches N]
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
failed = False
|
||||
|
||||
|
||||
def check(ok, what):
|
||||
global failed
|
||||
failed |= not ok
|
||||
print(("ok " if ok else "FAIL ") + what, flush=True)
|
||||
|
||||
|
||||
def workload_pids(exe_name):
|
||||
out = subprocess.run(["/bin/ps", "-axo", "pid=,command="], capture_output=True, text=True).stdout
|
||||
pids = []
|
||||
for line in out.splitlines():
|
||||
pid, _, command = line.strip().partition(" ")
|
||||
command = command.strip()
|
||||
# the Windows program appears with a drive-letter command line
|
||||
if command[1:3] == ":\\" and exe_name.lower() in command.lower():
|
||||
pids.append(int(pid))
|
||||
return pids
|
||||
|
||||
|
||||
def wait_for(predicate, seconds):
|
||||
end = time.time() + seconds
|
||||
while time.time() < end:
|
||||
if predicate():
|
||||
return True
|
||||
time.sleep(0.2)
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("runner")
|
||||
p.add_argument("bottle")
|
||||
p.add_argument("exe")
|
||||
p.add_argument("--launches", type=int, default=20)
|
||||
a = p.parse_args()
|
||||
name = os.path.basename(a.exe)
|
||||
base = [a.runner, "hybrid", "run", "--bottle", a.bottle, "--timeout", "120"]
|
||||
if workload_pids(name):
|
||||
print(f"FAIL precondition: {name} is already running")
|
||||
return 1
|
||||
|
||||
def start(extra, out):
|
||||
return subprocess.Popen(base + ["--", a.exe] + extra, stdout=out, stderr=subprocess.DEVNULL,
|
||||
start_new_session=True)
|
||||
|
||||
def healthy(label):
|
||||
with tempfile.TemporaryFile("w+") as out:
|
||||
run = start(["--frames", "64"], out)
|
||||
code = run.wait(timeout=150)
|
||||
check(code == 0, f"{label}: next run passes")
|
||||
check(not workload_pids(name), f"{label}: nothing left running")
|
||||
|
||||
for sig, to_group in ((signal.SIGINT, True), (signal.SIGTERM, False), (signal.SIGHUP, False)):
|
||||
label = sig.name + (" to the process group" if to_group else "")
|
||||
with tempfile.TemporaryFile("w+") as out:
|
||||
run = start(["--frames", "64", "--fault", "hang"], out)
|
||||
if not wait_for(lambda: workload_pids(name), 60):
|
||||
check(False, f"{label}: workload never started")
|
||||
run.kill()
|
||||
continue
|
||||
time.sleep(2)
|
||||
began = time.time()
|
||||
(os.killpg if to_group else os.kill)(run.pid, sig)
|
||||
try:
|
||||
code = run.wait(timeout=40)
|
||||
except subprocess.TimeoutExpired:
|
||||
run.kill()
|
||||
check(False, f"{label}: supervisor did not exit")
|
||||
continue
|
||||
out.seek(0)
|
||||
try:
|
||||
record = json.load(out)
|
||||
except json.JSONDecodeError:
|
||||
record = {}
|
||||
check(code == 1 and record.get("classification") == "interrupted",
|
||||
f"{label}: classified {record.get('classification')} in {time.time() - began:.1f}s")
|
||||
check(wait_for(lambda: not workload_pids(name), 10), f"{label}: workload stopped")
|
||||
healthy(label)
|
||||
|
||||
with tempfile.TemporaryFile("w+") as out:
|
||||
run = start(["--frames", "64", "--fault", "hang"], out)
|
||||
started = wait_for(lambda: workload_pids(name), 60)
|
||||
time.sleep(2)
|
||||
run.kill()
|
||||
run.wait()
|
||||
# SIGKILL cannot be handled: the program is expected to survive until `stop`.
|
||||
check(started and bool(workload_pids(name)), "SIGKILL: program survives, as documented")
|
||||
subprocess.run([a.runner, "hybrid", "stop", "--bottle", a.bottle], timeout=60)
|
||||
check(wait_for(lambda: not workload_pids(name), 15), "SIGKILL: `hybrid stop` removes it")
|
||||
healthy("after stop")
|
||||
|
||||
passed = 0
|
||||
for _ in range(a.launches):
|
||||
with tempfile.TemporaryFile("w+") as out:
|
||||
passed += start(["--frames", "64"], out).wait(timeout=150) == 0
|
||||
check(passed == a.launches, f"repeated launch: {passed} of {a.launches} passed")
|
||||
check(not workload_pids(name), "repeated launch: nothing left running")
|
||||
return 1 if failed else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Drive the D3D12 workload with macOS keyboard events.
|
||||
|
||||
Starts the workload through `betterxen hybrid run` with `--external-input`, finds its window,
|
||||
brings that process to the front and posts key events to that process only
|
||||
(CGEventPostToPid), so nothing is typed into any other application. The events travel macOS
|
||||
-> Wine's Mac driver -> the Windows message queue. They are synthesized, not typed on a
|
||||
keyboard. Needs the Accessibility permission, `swiftc` and a logged-in GUI session.
|
||||
|
||||
usage: send_keys.py RUNNER BOTTLE EXE [--keys right,right,down,left,down] [--expect pass|fail]
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
CODES = {"left": 123, "right": 124, "down": 125, "up": 126}
|
||||
SENDER = r"""
|
||||
import AppKit
|
||||
let title = "BetterXen D3D12 workload"
|
||||
guard CGPreflightPostEventAccess() else { print("no event-posting permission"); exit(3) }
|
||||
var pid: pid_t = 0
|
||||
for _ in 0..<120 {
|
||||
let all = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as? [[String: Any]] ?? []
|
||||
if let w = all.first(where: { ($0[kCGWindowName as String] as? String) == title }) {
|
||||
pid = pid_t(w[kCGWindowOwnerPID as String] as! Int32); break
|
||||
}
|
||||
usleep(250_000)
|
||||
}
|
||||
guard pid > 0 else { print("window not found"); exit(4) }
|
||||
sleep(2)
|
||||
NSRunningApplication(processIdentifier: pid)?.activate(options: [])
|
||||
sleep(1)
|
||||
for code in CommandLine.arguments.dropFirst().compactMap({ UInt16($0) }) {
|
||||
for down in [true, false] {
|
||||
CGEvent(keyboardEventSource: nil, virtualKey: code, keyDown: down)?.postToPid(pid)
|
||||
usleep(60_000)
|
||||
}
|
||||
usleep(250_000)
|
||||
}
|
||||
print("posted to pid \(pid)")
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("runner")
|
||||
p.add_argument("bottle")
|
||||
p.add_argument("exe")
|
||||
p.add_argument("--keys", default="right,right,down,left,down")
|
||||
p.add_argument("--expect", choices=["pass", "fail"], default="pass")
|
||||
a = p.parse_args()
|
||||
codes = [str(CODES[k]) for k in a.keys.split(",") if k]
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
source, binary = Path(tmp) / "send.swift", Path(tmp) / "send"
|
||||
source.write_text(SENDER)
|
||||
subprocess.run(["swiftc", "-O", str(source), "-o", str(binary)], check=True)
|
||||
record = open(Path(tmp) / "run.json", "w+")
|
||||
run = subprocess.Popen(
|
||||
[a.runner, "hybrid", "run", "--bottle", a.bottle, "--timeout", "90", "--",
|
||||
a.exe, "--external-input", "--input-timeout-s", "20"],
|
||||
stdout=record, stderr=subprocess.DEVNULL)
|
||||
sent = subprocess.run([str(binary)] + codes, capture_output=True, text=True, timeout=60)
|
||||
print(sent.stdout.strip())
|
||||
run.wait(timeout=120)
|
||||
record.seek(0)
|
||||
gates = {g["name"]: g for g in json.load(record)["gates"]}
|
||||
if sent.returncode != 0 or "input" not in gates:
|
||||
print("FAIL keyboard: the events were not sent or the workload reported no input gate")
|
||||
return 1
|
||||
print("workload:", gates["input"]["detail"])
|
||||
passed = gates["input"]["passed"]
|
||||
if passed == (a.expect == "pass"):
|
||||
print(f"PASS keyboard: input gate {'passed' if passed else 'failed'} as expected")
|
||||
return 0
|
||||
print(f"FAIL keyboard: input gate {'passed' if passed else 'failed'}, expected {a.expect}")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user