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
|
|
@ -95,23 +95,29 @@ namespace Crafter {
|
|||
};
|
||||
// A new directory in `parent`, named `prefix` and six random characters,
|
||||
// that only this user may enter (mkdtemp), removed with everything in it
|
||||
// when this ends. A process that is killed runs no destructor, so this
|
||||
// also holds an flock on the directory, which the OS drops with the
|
||||
// process, and making one removes the directories of `prefix` in
|
||||
// `parent` that nobody holds and that have not changed for a minute:
|
||||
// left behind by a process that is gone. The minute covers one that is
|
||||
// being made at that moment, between mkdtemp and its lock. Throws when
|
||||
// the directory cannot be made.
|
||||
// when this ends, unless it is kept. A process that is killed runs no
|
||||
// destructor, so this also holds an flock on the directory, which the OS
|
||||
// drops with the process, and making one removes the directories of
|
||||
// `prefix` in `parent` that nobody holds and that have not changed for a
|
||||
// minute: left behind by a process that is gone, or kept. The minute
|
||||
// covers one that is being made at that moment, between mkdtemp and its
|
||||
// lock. Throws when the directory cannot be made.
|
||||
// Exported for the tests that make a directory of their own outside the
|
||||
// temp directory.
|
||||
export class PrivateDirectory {
|
||||
std::int32_t fd = -1;
|
||||
std::atomic<bool> kept{false};
|
||||
public:
|
||||
const fs::path path;
|
||||
PrivateDirectory(const fs::path& parent, std::string_view prefix);
|
||||
~PrivateDirectory();
|
||||
PrivateDirectory(const PrivateDirectory&) = delete;
|
||||
PrivateDirectory& operator=(const PrivateDirectory&) = delete;
|
||||
// The destructor leaves the directory where it is, unlocked and
|
||||
// dated as it lets go of it, so that what is in it can be looked at
|
||||
// for a minute at least, until it is removed as one that nobody
|
||||
// holds. Several threads may call it at once.
|
||||
void Keep() { kept = true; }
|
||||
};
|
||||
// The link flags that record `dir` as a run path, with -Xlinker rather
|
||||
// than -Wl,: clang splits a -Wl, value at every comma, and `dir` may be a
|
||||
|
|
|
|||
Loading…
Reference in a new issue