fix(test): run each test's command with a TMPDIR of its own
Tests stage their fixtures under fixed names in the temp directory, fs::temp_directory_path() / "crafter-build-<name>", and two runs at once staged into the same ones: natively every process shares the machine's /tmp, and every sandbox of crafter-build's Flatpak shares the one the app has, whatever checkout it runs in. A test of one run could find what it had staged removed or written over by the same test of the other run, which removes the directory as it starts and stages its copy anew. RunTests now makes a directory for the run in the temp directory, a PrivateDirectory, and runs each test with TMPDIR naming <run>/<name>, so that fs::temp_directory_path() in the test names it and the fixed names are the run's alone. The second test of one name in a run, as two configurations or two targets may each have one, gets <name>-2, so that removing one's directory does not take the other's. RunSingleTest takes the directory as a new last parameter and puts TMPDIR into the env prefix of the test's command, beside a Wayland test's WAYLAND_DISPLAY. env's command is sh, which execs the test's words, as for a Wayland test's: env takes a word with an '=' in it ahead of its command for an assignment, a binary's path among them, and with no command left it printed its environment and exited 0, a pass for a test that never ran. What a test that passes or skips leaves is removed when it ends. What one that fails, crashes or times out leaves is kept for a look, its log says where, as does what is printed of a test that fails or crashes, and the run's directory then outlives the run, unlocked, for a later run to remove a minute after, or, where the run was killed, a minute after its last change to it; PrivateDirectory gains Keep() for that. A test's logs, build/test-logs/<name>.log and <name>.compositor.log, are named as its TMPDIR is, <name>-2 for a later test of one name, so that two failing tests of one name each keep their own, and with it where what each left is kept: with one log for both, the second's was written over the first's. The README's line on the logs says so. The directory is dated as it is let go of, since the removal of abandoned directories goes by its date, which is that of what was last made or removed in it: for the run of a test that fails after a minute, as one that times out at the default 60 s does, a minute old already, and the next run would remove it at once. The removal now reads a directory's date only once it holds the directory's lock: a date read before could be one the holder replaced as it let go. The directory is the run's, not a pass's: every pass of a sweep over targets shares it, so it is made and its surroundings swept once, and let go of once the last pass is done. A pass that made one of its own would have made it once the passes before had let go of theirs, and making it would have removed any of those that had not changed for a minute: a kept one, after a pass of that long, while its test's output said where it was. RunTests becomes the wrapper that holds the run's directory around RunTestsWith, the passes it recurses into, and the directory is kept the moment a test keeps something in it, by the worker that ran the test, so that a later pass that throws, as one does for a target whose runner CRAFTER_BUILD_RUNNER_ gives wrong, or a worker that cannot be started does not take it with it; Keep() may be called from several workers at once. TMPDIR reaches the test where its runner hands it on, as running it directly and qemu-user do. Under wine a Windows test does not get TMPDIR, and takes the Wine prefix's TMP, TEMP and temp directory, and wasmtime gives a test no environment at all; RunSingleTest's comment says so. A test under `host` gets its TMPDIR as any test does, so that comment and HostDisplay's now say that `host` leaves the test the display, not the whole environment, as it is. In the runner rather than in each of the 74 tests whose main.cpp uses the temp directory at this commit: a project's own tests are covered the same way, where their runner hands them TMPDIR. Of the 74 only SysrootStdModule has to change. It builds against a sysroot it stages there, and the std module's cache directory is keyed on the sysroot's path, which is a new one every run now, so every run left one more directory, with its lock, in the real cache; it keeps its cache in its scratch directory now, as the tests that have crafter-build fetch a repository they stage do. AGENTS.template.md says what changes for the tests: HostFlatpak, whose /tmp is no longer the temp directory a test is given, is a second test that writes elsewhere, and under `crafter-build test` a staged copy goes with the test's TMPDIR rather than at the test's next run.
This commit is contained in:
parent
fcfac0d9cf
commit
93f1c8d9b9
7 changed files with 140 additions and 33 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
#include <stdlib.h>
|
||||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
|
@ -52,6 +53,11 @@ int main() {
|
|||
std::error_code ec;
|
||||
fs::remove_all(scratch, ec);
|
||||
fs::create_directories(scratch);
|
||||
// The cache the build below makes its std module's directory in, which
|
||||
// is keyed on the sysroot's path: one under the temp directory, which
|
||||
// is a new one every run of the suite, so the real cache would keep one
|
||||
// more directory each run. Set while this is the only thread.
|
||||
setenv("XDG_CACHE_HOME", (scratch / "cache").c_str(), 1);
|
||||
|
||||
{
|
||||
StageHeaders(scratch / "headers", 230102);
|
||||
|
|
@ -126,8 +132,8 @@ int main() {
|
|||
{
|
||||
// End to end with the real toolchain: a sysroot on a libc++ release
|
||||
// that does not exist fails the build with the one-line explanation
|
||||
// before clang is run. The target is the host's so the std PCM cache
|
||||
// directory is the one every other test already uses.
|
||||
// before clang is run, for the host's target. The std module's cache
|
||||
// directory is made in the scratch cache (above).
|
||||
const Toolchain& real = GetToolchain();
|
||||
Check(real.libcxxVersion != 0, "the running toolchain's libc++ release is read from its headers");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue