feat(test): give a test that sets Test::wayland a compositor of its own
A test that opens a window opened it on the display of whoever ran the suite: every `crafter-build test` of Crafter.Graphics put the windows of its window tests on the desktop, and its other GPU tests connect to the session's compositor too, since Device::Initialize calls wl_display_connect whether a window follows or not. A test that sets the new Test::wayland (TestBuilder::Wayland) now runs with a headless compositor started for it alone. RunSingleTest starts the compositor through sh, with XDG_RUNTIME_DIR naming a directory made for it and without WAYLAND_DISPLAY, WAYLAND_SOCKET or DISPLAY, waits up to 30 s for a wayland-<n> socket in that directory, runs the test with WAYLAND_DISPLAY set to the socket's path and with DISPLAY and WAYLAND_SOCKET unset, then stops the compositor's process group and removes the directory. The test's command is env with those changes, and env's command is sh, which execs the test's words: env takes every word with an '=' in it ahead of its command for an assignment, a binary's path among them. The compositor runs under timeout(1) as long as the test may, the wait and 30 s more, and with no limit for a test that has none, a timeout of 0. It is weston on its headless backend with its GL renderer, unless CRAFTER_BUILD_COMPOSITOR or the new --compositor= names another command; `host` gives the tests the session's own display instead, to watch them. A compositor that ends before it listens, sh not finding it included, or does not listen in time fails the test with what it printed. A test that may run where its compositor is missing declares it in requires_ (tool:weston for the default), the check RunTests makes before the build, so no skip of its own is added, and no probe of the command: the command is any sh command, whose first word need not be the compositor. A test that fails, crashes or times out keeps what its compositor printed (TestResult::compositorLog), which RunTests writes to build/test-logs/<name>.compositor.log, and says when the compositor ended while it ran. One compositor per test rather than one per run: no two tests share one, so tests that run at once cannot cover each other's windows or take each other's focus, for weston's start-up on every test. weston's GL renderer, because it imports the dmabufs that a GPU's Vulkan driver presents, as Mesa's and NVIDIA's do, and the headless backend's default renderer and pixman import none: against pixman, the NVIDIA driver reports no format for a window's surface, and Crafter.Graphics's FrameLoopSync stops at its formatCount > 0 assertion. weston cannot run the test itself, as `weston -- <test>` exits 0 whatever the test returned, so crafter-build runs the compositor beside it. :Platform gains BackgroundCommand, the compositor's process, and PrivateDirectory, its directory. The process is forked with PR_SET_PDEATHSIG and runs under `timeout`, which passes the SIGTERM it gets when crafter-build dies on to the compositor's group, so a crafter-build killed by Ctrl-C leaves no compositor running. The directory is made in $XDG_RUNTIME_DIR, or in /tmp where that is not a directory, rather than in the temp directory, since a socket's path holds 107 bytes, and is flocked while in use; one that a killed crafter-build left is removed when the next is made beside it, once it has not changed for a minute. New members and a parameter with a default, nothing removed: a minor release.
This commit is contained in:
parent
cb8914d387
commit
dc8e9e6f9e
7 changed files with 418 additions and 13 deletions
|
|
@ -53,6 +53,9 @@ export namespace Crafter {
|
|||
TestBuilder& LinkFlag(std::string f);
|
||||
// Append a single compile flag.
|
||||
TestBuilder& CompileFlag(std::string f);
|
||||
// Sets Test::wayland: the test runs with a headless Wayland
|
||||
// compositor of its own.
|
||||
TestBuilder& Wayland(bool w = true);
|
||||
};
|
||||
|
||||
struct RunTestsOptions {
|
||||
|
|
@ -75,6 +78,10 @@ export namespace Crafter {
|
|||
// Target scoping is unnecessary because targetFilter ensures the run
|
||||
// contains only one target's tests.
|
||||
std::optional<std::string> runnerOverride;
|
||||
// From --compositor=: the compositor every test of the run that sets
|
||||
// Test::wayland runs with, in place of CRAFTER_BUILD_COMPOSITOR and
|
||||
// the default. See RunSingleTest.
|
||||
std::optional<std::string> compositorOverride;
|
||||
};
|
||||
|
||||
struct TestSummary {
|
||||
|
|
@ -98,7 +105,27 @@ export namespace Crafter {
|
|||
// compiled alike are, both fail without being built and name the
|
||||
// configurations. A configuration the list names twice counts once.
|
||||
TestSummary RunTests(std::span<Configuration* const> configurations, const RunTestsOptions& opts, std::span<const std::string_view> projectArgs = {});
|
||||
TestResult RunSingleTest(const Test& test, const std::filesystem::path& binary, std::chrono::seconds timeout);
|
||||
// Runs `binary` as `test` with its runner, its arguments and `timeout`,
|
||||
// and reads the outcome from how it ended (exit 0 passes, 77 skips).
|
||||
//
|
||||
// When the test sets Test::wayland, a compositor is started for it
|
||||
// first: `compositorOverride` when it holds a command, else the one
|
||||
// CRAFTER_BUILD_COMPOSITOR names, else weston on its headless backend.
|
||||
// The command runs through sh in a process group of its own, with
|
||||
// XDG_RUNTIME_DIR naming a directory made for it alone and without
|
||||
// WAYLAND_DISPLAY, WAYLAND_SOCKET or DISPLAY, and is waited for until
|
||||
// a wayland-<n> socket appears in that directory, with a limit of the
|
||||
// test's, the wait and 30 s more, or none when `timeout` is 0, which is
|
||||
// no limit for the test either (timeout(1)). The test then runs
|
||||
// with WAYLAND_DISPLAY set to the socket's path and DISPLAY and
|
||||
// WAYLAND_SOCKET unset; afterwards the compositor's group is stopped and
|
||||
// the directory removed. 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 its compositor
|
||||
// is missing declares it in requires_ (tool:weston), which RunTests
|
||||
// checks before the build. `host` starts nothing and runs the test with
|
||||
// this process's environment as it is.
|
||||
TestResult RunSingleTest(const Test& test, const std::filesystem::path& binary, std::chrono::seconds timeout, const std::optional<std::string>& compositorOverride = std::nullopt);
|
||||
|
||||
// The configurations of the project crafter-build was pointed at, by
|
||||
// name. Run() hands SetParentProject what the project file returned,
|
||||
|
|
|
|||
Loading…
Reference in a new issue