diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c131fe..ab8c084 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,15 +7,9 @@ on: pull_request: jobs: - # Crates that must compile on every supported host platform. - cross-platform: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - - windows-latest + # Crates that build without Wayland or other Linux system libraries. + portable: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -24,14 +18,14 @@ jobs: components: rustfmt, clippy - name: cargo fmt run: cargo fmt --all --check - - name: cargo clippy (cross-platform crates) + - name: cargo clippy (portable crates) run: > cargo clippy --workspace --exclude weft-compositor --exclude weft-servo-shell --exclude weft-app-shell --all-targets -- -D warnings - - name: cargo test (cross-platform crates) + - name: cargo test (portable crates) run: > cargo test --workspace --exclude weft-compositor diff --git a/README.md b/README.md index 1371951..45c6bd5 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ See `docs/building.md` for full instructions including Wasm component builds, Ni Three jobs on every push and pull request: -- `cross-platform` — fmt, clippy, tests on Ubuntu and Windows +- `portable` — fmt, clippy and tests for the crates that need no Linux system libraries - `linux-only` — clippy and tests for compositor and shell crates - `servo-embed-linux` — `cargo check --features servo-embed` for both servo crates diff --git a/crates/weft-compositor/src/backend/winit.rs b/crates/weft-compositor/src/backend/winit.rs index 087b04c..7575211 100644 --- a/crates/weft-compositor/src/backend/winit.rs +++ b/crates/weft-compositor/src/backend/winit.rs @@ -157,10 +157,8 @@ pub fn run() -> anyhow::Result<()> { false } }; - if render_ok { - if let Err(e) = backend.submit(Some(&[full_damage])) { - tracing::warn!(?e, "backend submit failed"); - } + if render_ok && let Err(e) = backend.submit(Some(&[full_damage])) { + tracing::warn!(?e, "backend submit failed"); } state.space.elements().for_each(|window| { diff --git a/crates/weft-servo-shell/SERVO_PIN.md b/crates/weft-servo-shell/SERVO_PIN.md index 928d56f..3b1ebfd 100644 --- a/crates/weft-servo-shell/SERVO_PIN.md +++ b/crates/weft-servo-shell/SERVO_PIN.md @@ -116,9 +116,16 @@ exercised is listed as unverified. the software path (Ubuntu 24.04, x86_64; `check_frame.py --host system`, `--host app` and `--host app --slow-style 3`, five runs each). The EGL path, DRM sessions, resize, output scale and idle wakeup are unverified. -- **Input:** keyboard and pointer events are forwarded through - `WebView::notify_input_event`; delivery through the compositor is - unverified. +- **Input:** `tests/frame/check_input.py` verifies, on the same nested + setup, that left clicks 6 px either side of a boundary reach the element + under the pointer, and that `a` and `Shift+a` key presses reach the page with + the right key value and modifier, using real X input that `weft-compositor` + routes to `weft-servo-shell` (three runs). The harness gives the compositor's + X window input focus, as a window manager would; the client's keyboard focus + comes from the compositor's click-to-focus. Unverified: key release and + repeat, pointer motion, enter/leave and button release events, other buttons, + wheel, focus loss, non-US layouts, non-ASCII text, scale changes and + `weft-app-shell` input. - **`backdrop-filter`**: the parsing (Stylo `f1ba496`) and rendering (Servo `8e7dc40`, `f0bb1aa`) patches are selected by the lockfile; rendering is unverified. diff --git a/docs/building.md b/docs/building.md index a6b8af0..a721037 100644 --- a/docs/building.md +++ b/docs/building.md @@ -2,7 +2,7 @@ ## Prerequisites -Linux (x86_64 or aarch64). Building on Windows is supported for workspace validation only; runtime components require Linux kernel interfaces. +Linux (x86_64 or aarch64). WEFT OS is built and validated on Linux only; runtime components require Linux kernel interfaces. System packages (openSUSE): @@ -67,6 +67,16 @@ reveals the page so premature readiness becomes visible. Logs and the last capture are written to `target/frame-check`. +`tests/frame/check_input.py` uses the same nested desktop to send real X +pointer and keyboard input (with `xdotool`) through `weft-compositor` to +`weft-servo-shell` showing `tests/frame/input.html`, and checks that the +page reacts to clicks on either side of a boundary and to the `a` and +`Shift+a` keys. Logs and the last capture are written to `target/input-check`. + +```sh +python3 tests/frame/check_input.py +``` + ## Demo apps (wasm32-wasip2) Each demo is a standalone crate in `examples/`. Pre-built `app.wasm` binaries are committed. To rebuild: @@ -114,6 +124,6 @@ See `infra/nixos/weft-packages.nix` for the package derivations. Its `outputHash Three jobs run on every push to `main` and on pull requests: -- `cross-platform` — fmt, clippy, tests on Ubuntu and Windows (excludes Wayland crates) +- `portable` — fmt, clippy, tests for the crates that need no Linux system libraries (excludes Wayland crates) - `linux-only` — clippy and tests for `weft-compositor`, `weft-servo-shell`, `weft-app-shell` - `servo-embed-linux` — `cargo check --features servo-embed` for servo-shell and app-shell diff --git a/infra/vm/linux-dev-environment.md b/infra/vm/linux-dev-environment.md index 22784b5..877ef94 100644 --- a/infra/vm/linux-dev-environment.md +++ b/infra/vm/linux-dev-environment.md @@ -22,7 +22,7 @@ The guest is the validation target for: ## Host versus target boundary -The Windows host is acceptable for editing, documentation, and workspace validation. +The Windows host is acceptable for editing and documentation. Builds and tests are validated on Linux only; CI does not build on Windows. The Linux guest is authoritative for: diff --git a/tests/frame/check_frame.py b/tests/frame/check_frame.py index eacce3f..8fd89a0 100644 --- a/tests/frame/check_frame.py +++ b/tests/frame/check_frame.py @@ -17,27 +17,22 @@ early readiness observable: the page stays hidden until a stylesheet that a local HTTP server delivers after the delay reveals it, so a host that reports READY before the document has loaded shows no page within the grace period. -Requires Xvfb, xwd and ImageMagick's convert. Processes are started from -argument arrays and are always terminated before the harness exits. +Requires Xvfb, xwd and ImageMagick's convert; see session.py. """ import argparse import http.server -import os -import re import shutil -import signal -import subprocess import sys -import tempfile import threading import time from pathlib import Path +sys.dont_write_bytecode = True +from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402 + HERE = Path(__file__).resolve().parent -ROOT = HERE.parents[1] -SCREEN = (1024, 768) COLORS = { "red": (255, 0, 0), "green": (0, 255, 0), @@ -46,52 +41,6 @@ COLORS = { } MIN_SIDE = 40 MIN_TEXT_PIXELS = 30 -ANSI_ESCAPE = re.compile(r"\x1b\[[0-9;]*m") - - -def parse_ppm(data): - """Decode a binary P6 PPM into (width, height, bytes).""" - tokens = [] - index = 0 - while len(tokens) < 4: - while data[index:index + 1].isspace(): - index += 1 - if data[index:index + 1] == b"#": - index = data.index(b"\n", index) + 1 - continue - end = index - while not data[end:end + 1].isspace(): - end += 1 - tokens.append(data[index:end]) - index = end - magic, width, height, maxval = tokens - if magic != b"P6" or int(maxval) != 255: - raise ValueError("expected an 8-bit P6 image") - width, height = int(width), int(height) - pixels = data[index + 1:index + 1 + width * height * 3] - if len(pixels) != width * height * 3: - raise ValueError("truncated image") - return width, height, pixels - - -def bounding_box(width, height, pixels, color): - """Return (x0, y0, x1, y1) of pixels exactly matching color, or None.""" - target = bytes(color) - xs, ys = [], [] - for y in range(0, height, 2): - row = pixels[y * width * 3:(y + 1) * width * 3] - start = row.find(target) - while start != -1: - if start % 3 == 0: - xs.append(start // 3) - ys.append(y) - start = row.find(target, start + 3) - else: - # A match spanning two pixels; realign on the next byte. - start = row.find(target, start + 1) - if not xs: - return None - return min(xs), min(ys), max(xs), max(ys) def dark_pixels(width, pixels, box): @@ -183,57 +132,6 @@ def hidden_until_styled(page, destination, port): return destination -def capture(display): - xwd = subprocess.run(["xwd", "-root", "-silent", "-display", display], - capture_output=True, check=True, timeout=20) - ppm = subprocess.run(["convert", "xwd:-", "ppm:-"], input=xwd.stdout, - capture_output=True, check=True, timeout=20) - return ppm.stdout - - -def free_display(): - for number in range(90, 140): - if not Path(f"/tmp/.X11-unix/X{number}").exists() and \ - not Path(f"/tmp/.X{number}-lock").exists(): - return f":{number}" - raise RuntimeError("no free X display number") - - -def start(command, log, env): - return subprocess.Popen(command, stdout=log, stderr=subprocess.STDOUT, env=env, - start_new_session=True) - - -def signal_group(process, signum): - try: - os.killpg(process.pid, signum) - except ProcessLookupError: - pass - - -def stop(process): - """Terminate the process and everything left in its process group.""" - if process is None: - return - signal_group(process, signal.SIGTERM) - try: - process.wait(timeout=10) - except subprocess.TimeoutExpired: - signal_group(process, signal.SIGKILL) - process.wait(timeout=10) - signal_group(process, signal.SIGKILL) - - -def wait_for(predicate, timeout, interval=0.5): - deadline = time.monotonic() + timeout - while time.monotonic() < deadline: - result = predicate() - if result: - return result - time.sleep(interval) - return None - - def main(argv=None): parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) @@ -255,115 +153,68 @@ def main(argv=None): name = "weft-servo-shell" if args.host == "system" else "weft-app-shell" args.shell = ROOT / "target/debug" / name - for tool in ("Xvfb", "xwd", "convert"): - if shutil.which(tool) is None: - print(f"missing required tool: {tool}", file=sys.stderr) - return 2 - for binary in (args.compositor, args.shell): - if not binary.is_file(): - print(f"missing binary: {binary}", file=sys.stderr) - return 2 + missing = missing_tools() + [str(b) for b in (args.compositor, args.shell) if not b.is_file()] + if missing: + print("missing: " + ", ".join(missing), file=sys.stderr) + return 2 - args.output.mkdir(parents=True, exist_ok=True) - runtime = Path(tempfile.mkdtemp(prefix="weft-frame-")) - runtime.chmod(0o700) - display = free_display() - base_env = {key: value for key, value in os.environ.items() - if key not in ("DISPLAY", "WAYLAND_DISPLAY", "WAYLAND_SOCKET")} - base_env["XDG_RUNTIME_DIR"] = str(runtime) - base_env.setdefault("RUST_LOG", "info") - - page = args.page style_server = None - if args.slow_style: - style_server = slow_style_server(args.slow_style) - page = hidden_until_styled(args.page, runtime / "page.html", - style_server.server_address[1]) - - processes = [] - logs = {name: open(args.output / f"{name}.log", "w", encoding="utf-8") - for name in ("xvfb", "compositor", "shell")} try: - xvfb = start(["Xvfb", display, "-screen", "0", f"{SCREEN[0]}x{SCREEN[1]}x24", - "-nolisten", "tcp"], logs["xvfb"], base_env) - processes.append(xvfb) - if not wait_for(lambda: Path(f"/tmp/.X11-unix/X{display[1:]}").exists(), 15): - print("Xvfb did not start", file=sys.stderr) - return 1 - - compositor_env = dict(base_env, DISPLAY=display) - compositor = start([str(args.compositor), "--winit"], logs["compositor"], - compositor_env) - processes.append(compositor) - compositor_log = args.output / "compositor.log" - - def socket_name(): - if compositor.poll() is not None: - return "exited" - text = ANSI_ESCAPE.sub("", compositor_log.read_text(encoding="utf-8", - errors="replace")) - match = re.search(r'socket_name="([^"]+)"', text) - return match and match.group(1) - - socket = wait_for(socket_name, 30) - if socket in (None, "exited"): - print(f"compositor did not open a Wayland socket; see {compositor_log}", - file=sys.stderr) - return 1 - - shell_env = dict(base_env, WAYLAND_DISPLAY=socket) - if args.host == "system": - shell_env["WEFT_SYSTEM_UI_HTML"] = str(page.resolve()) - command = [str(args.shell)] - else: - shell_env["WEFT_APP_STORE"] = str(install_app(runtime / "store", page)) - command = [str(args.shell), APP_ID, "1"] - shell = start(command, logs["shell"], shell_env) - processes.append(shell) - shell_log = args.output / "shell.log" - - def ready_printed(): - text = shell_log.read_text(encoding="utf-8", errors="replace") - return any(line.strip() == "READY" for line in text.splitlines()) - - problems = ["no frame captured"] - screenshot = None - ready_at = None - deadline = time.monotonic() + args.timeout - while time.monotonic() < deadline: - if shell.poll() is not None: - problems = [f"shell exited with status {shell.returncode}"] - break - if args.host == "app" and ready_at is None and ready_printed(): - ready_at = time.monotonic() - ready = ready_at is not None - screenshot = capture(display) - problems = evaluate(*parse_ppm(screenshot)) - if ready and problems and time.monotonic() - ready_at > COMPOSITE_GRACE: - problems = [f"page not on screen {COMPOSITE_GRACE:g} s after READY"] + problems - break - if not problems and (args.host == "system" or ready): - break - if not problems: - problems = ["frame presented but READY not printed"] - time.sleep(1) - - if screenshot is not None: - (args.output / "frame.ppm").write_bytes(screenshot) - if problems: - print("frame check failed: " + "; ".join(problems), file=sys.stderr) - print(f"logs and last capture in {args.output}", file=sys.stderr) - return 1 - print(f"frame check passed; capture in {args.output / 'frame.ppm'}") - return 0 + with Desktop(args.compositor, args.output, outputs=["frame.ppm"]) as desktop: + page = args.page + if args.slow_style: + style_server = slow_style_server(args.slow_style) + page = hidden_until_styled(args.page, desktop.runtime / "page.html", + style_server.server_address[1]) + if args.host == "system": + shell = desktop.launch_client( + "shell", [args.shell], {"WEFT_SYSTEM_UI_HTML": str(page.resolve())}) + else: + store = install_app(desktop.runtime / "store", page) + shell = desktop.launch_client( + "shell", [args.shell, APP_ID, "1"], {"WEFT_APP_STORE": str(store)}) + problems, screenshot = watch(desktop, shell, args) + except SessionError as error: + print(error, file=sys.stderr) + return 1 finally: - for process in reversed(processes): - stop(process) if style_server is not None: style_server.shutdown() - for log in logs.values(): - log.close() - shutil.rmtree(runtime, ignore_errors=True) + + if screenshot is not None: + (args.output / "frame.ppm").write_bytes(screenshot) + if problems: + print("frame check failed: " + "; ".join(problems), file=sys.stderr) + print(f"logs and last capture in {args.output}", file=sys.stderr) + return 1 + print(f"frame check passed; capture in {args.output / 'frame.ppm'}") + return 0 + + +def watch(desktop, shell, args): + """Capture until the frame matches, the host exits or the time runs out.""" + def ready_printed(): + return any(line.strip() == "READY" for line in desktop.log_text("shell").splitlines()) + + problems = ["no frame captured"] + screenshot = None + ready_at = None + deadline = time.monotonic() + args.timeout + while time.monotonic() < deadline: + if shell.poll() is not None: + return [f"shell exited with status {shell.returncode}"], screenshot + if args.host == "app" and ready_at is None and ready_printed(): + ready_at = time.monotonic() + screenshot = desktop.capture() + problems = evaluate(*parse_ppm(screenshot)) + if ready_at is not None and problems and time.monotonic() - ready_at > COMPOSITE_GRACE: + return [f"page not on screen {COMPOSITE_GRACE:g} s after READY"] + problems, screenshot + if not problems and (args.host == "system" or ready_at is not None): + return [], screenshot + if not problems: + problems = ["frame presented but READY not printed"] + time.sleep(1) + return problems, screenshot if __name__ == "__main__": diff --git a/tests/frame/check_input.py b/tests/frame/check_input.py new file mode 100644 index 0000000..950d989 --- /dev/null +++ b/tests/frame/check_input.py @@ -0,0 +1,140 @@ +"""Check that native pointer and keyboard input reaches a page through weft-compositor. + +The harness runs weft-servo-shell with `input.html` on a nested desktop (see +session.py) and injects real X input into the compositor's window with +xdotool (after giving that window X input focus, since Xvfb runs without a +window manager), which weft-compositor's winit backend receives and routes to +the focused Wayland client. Each step must change the page as the page's script +defines, as seen in the presented pixels: + +1. A click 6 px inside the left half's right edge turns only the left half + green; the right half must stay blue. +2. Typing `a` turns the right half yellow. +3. Typing `Shift+a` turns the right half magenta, which checks the modifier. +4. A click 6 px inside the right half's left edge turns the right half white. + +The two clicks straddle the boundary between the halves, so a pointer +position that is scaled or offset by more than a few pixels fails. + +Requires Xvfb, xwd, ImageMagick's convert and xdotool. +""" + +import argparse +import shutil +import subprocess +import sys +import time +from pathlib import Path + +sys.dont_write_bytecode = True +from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402 + + +HERE = Path(__file__).resolve().parent +RED, GREEN, BLUE = (255, 0, 0), (0, 255, 0), (0, 0, 255) +WHITE, YELLOW, MAGENTA = (255, 255, 255), (255, 255, 0), (255, 0, 255) +MIN_SIDE = 40 + + +def region(screenshot, color): + """Bounding box of `color` if it covers a page half, else None.""" + box = bounding_box(*parse_ppm(screenshot), color) + if box and box[2] - box[0] >= MIN_SIDE and box[3] - box[1] >= MIN_SIDE: + return box + return None + + +STARTUP_TIMEOUT = 120.0 +EDGE_INSET = 6 + + +class Steps: + def __init__(self, desktop, shell, timeout): + self.desktop = desktop + self.shell = shell + self.timeout = timeout + self.screenshot = None + self.xdotool_path = shutil.which("xdotool") + + def expect(self, description, present, absent=(), timeout=None): + """Wait until every colour in `present` and none in `absent` is shown.""" + deadline = time.monotonic() + (self.timeout if timeout is None else timeout) + while time.monotonic() < deadline: + if self.shell.poll() is not None: + raise AssertionError(f"shell exited with status {self.shell.returncode}") + self.screenshot = self.desktop.capture() + boxes = {color: region(self.screenshot, color) for color in present} + if all(boxes.values()) and not any(region(self.screenshot, c) for c in absent): + return boxes + time.sleep(0.5) + raise AssertionError(f"{description}: expected page state not shown") + + def xdotool(self, *arguments): + subprocess.run([self.xdotool_path, *arguments], env={"DISPLAY": self.desktop.display}, + check=True, timeout=20) + + def click(self, x, y): + self.xdotool("mousemove", "--sync", str(x), str(y)) + self.xdotool("click", "1") + + +def run(steps): + boxes = steps.expect("initial page", [RED, BLUE], timeout=STARTUP_TIMEOUT) + # Xvfb runs without a window manager, so give the compositor's window the + # X input focus that a real session's window manager would. + steps.xdotool("search", "--class", "weft-compositor", "windowfocus", "--sync") + left, right = boxes[RED], boxes[BLUE] + middle = (left[1] + left[3]) // 2 + steps.click(left[2] - EDGE_INSET, middle) + steps.expect("click near the right edge of the left half", [GREEN, BLUE], + absent=[RED, WHITE]) + steps.xdotool("key", "a") + steps.expect("key a", [GREEN, YELLOW], absent=[BLUE]) + steps.xdotool("key", "shift+a") + steps.expect("key Shift+a", [GREEN, MAGENTA], absent=[YELLOW]) + steps.click(right[0] + EDGE_INSET, middle) + steps.expect("click near the left edge of the right half", [GREEN, WHITE], + absent=[MAGENTA, RED]) + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--compositor", type=Path, default=ROOT / "target/debug/weft-compositor") + parser.add_argument("--shell", type=Path, default=ROOT / "target/debug/weft-servo-shell") + parser.add_argument("--page", type=Path, default=HERE / "input.html") + parser.add_argument("--timeout", type=float, default=30.0, + help="seconds to wait for each expected page state") + parser.add_argument("--output", type=Path, default=ROOT / "target/input-check", + help="directory for logs and the last capture") + args = parser.parse_args(argv) + + missing = missing_tools() + [tool for tool in ("xdotool",) if shutil.which(tool) is None] + missing += [str(b) for b in (args.compositor, args.shell) if not b.is_file()] + if missing: + print("missing: " + ", ".join(missing), file=sys.stderr) + return 2 + + try: + with Desktop(args.compositor, args.output, outputs=["input.ppm"]) as desktop: + shell = desktop.launch_client("shell", [args.shell], + {"WEFT_SYSTEM_UI_HTML": str(args.page.resolve())}) + steps = Steps(desktop, shell, args.timeout) + try: + run(steps) + except AssertionError as failure: + print(f"input check failed: {failure}", file=sys.stderr) + print(f"logs and last capture in {args.output}", file=sys.stderr) + return 1 + finally: + if steps.screenshot is not None: + (args.output / "input.ppm").write_bytes(steps.screenshot) + except SessionError as error: + print(error, file=sys.stderr) + return 1 + print("input check passed") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/frame/input.html b/tests/frame/input.html new file mode 100644 index 0000000..b0bf76c --- /dev/null +++ b/tests/frame/input.html @@ -0,0 +1,31 @@ + + +
+ +