diff --git a/README.md b/README.md index 0c68e1a..6e8c085 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,7 @@ crafter-build test --target=x86_64-w64-mingw32 # only tests for crafter-build test --target=x86_64-w64-mingw32 --runner=cmd:wine crafter-build test --jobs=1 # one test at a time crafter-build test --timeout=5 # override per-test timeout +crafter-build test --compositor=host # Wayland tests on this session's display ``` Outcomes: ✅ pass, ❌ fail, 💥 crash (with signal name), ⏱ timeout, ⏭ skipped. The runner exits 0 only if every non-skipped test passed. @@ -375,6 +376,24 @@ cmd: # cmd:wine, cmd:qemu-aarch64, cmd:valgrind, ... Each runner carries a `probe` command (e.g. `which wine`), if it fails, every test using that runner is reported as ⏭ skipped and the rest of the suite continues. Skipped tests count toward the summary but don't fail the suite (`AllPassed()` returns true on skip-only runs). +### Tests that open windows + +A test that talks to a Wayland compositor sets `Test::wayland`, and every run of it gets a headless compositor of its own instead of your session's display, so the windows it opens through `WAYLAND_DISPLAY` show up there and not on your desktop: + +```cpp +cfg.AddTest("Swapchain").Wayland(); // or, on a Test you build yourself: test.wayland = true; +``` + +Before the test, crafter-build starts the compositor with `XDG_RUNTIME_DIR` set to a directory made for it (in your `XDG_RUNTIME_DIR`, else in `/tmp`) and without `WAYLAND_DISPLAY`, `WAYLAND_SOCKET` or `DISPLAY`, and waits up to 30 s for a `wayland-` socket to appear there. The test then runs with `WAYLAND_DISPLAY` set to that socket's full path and with `DISPLAY` and `WAYLAND_SOCKET` unset; its `XDG_RUNTIME_DIR` stays yours. Afterwards the compositor's process group is sent SIGTERM, what is left of the group SIGKILL once the compositor has ended or 5 s have passed, and the directory is removed. No two tests share a compositor, so tests that run at once cannot cover each other's windows or take each other's focus. + +The compositor is `weston --backend=headless --renderer=gl --no-config --idle-time=0` unless `CRAFTER_BUILD_COMPOSITOR` names another, and `--compositor=` wins over both. The Flatpak ships weston 16.0.2; outside it, install weston 12 or newer, the first release to take `--renderer=`. Its GL renderer takes the GPU buffers (dmabufs) that a GPU's Vulkan driver presents, as Mesa's and NVIDIA's do, and which the headless backend's default, a renderer that draws nothing, and pixman take none of; `--no-config` keeps your `weston.ini` out, and `--idle-time=0` keeps the output from going idle after 5 minutes, which would stop frame callbacks. Another compositor is any command, run through `sh`, that listens on a `wayland-` socket in the `XDG_RUNTIME_DIR` it is given. `host` starts none and gives these tests your own display, to watch what they draw: + +```bash +crafter-build test --compositor=host 'Swapchain*' +``` + +A compositor that ends before it listens, `sh` not finding it included, or does not listen within 30 s fails the test with what it printed. A test that may run where weston is missing declares it with `.Requires("tool:weston")`, and is then skipped there before it is built, as for any tool it declares. When a test that ran fails, crashes or times out, what its compositor printed, if anything, goes to `build/test-logs/.compositor.log`, and the test's output says so, and also when the compositor ended before the test did; what a compositor that did not start printed is in the test's own failure, in `build/test-logs/.log`. A crafter-build that is killed takes its compositors with it; the directories it leaves behind are removed by a test that starts a compositor after they have gone a minute unchanged. + ### Linking the parent project's library A test fixture can depend on the project's own library so it can `import` and exercise its API: diff --git a/examples/tests/README.md b/examples/tests/README.md index 6dcbf5c..8f46338 100644 --- a/examples/tests/README.md +++ b/examples/tests/README.md @@ -37,6 +37,7 @@ builder methods overlay overrides: - `.Dependencies({ &otherCfg, ... })` - `.Path(p)` — rebase the test's source-resolution path - `.LinkFlag(s)` / `.CompileFlag(s)` +- `.Wayland()` — a headless Wayland compositor of the test's own, so that the windows it opens stay off your desktop ([Tests that open windows](../../README.md#tests-that-open-windows)) ## Test conventions