From e643f83c005560106faf2d24919f8492503c8414 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Fri, 27 Nov 2026 09:18:05 +0100 Subject: [PATCH] docs: the TMPDIR each test's command runs with The README's test conventions say that each test runs with TMPDIR naming a directory of its own, made for the run, so that fs::temp_directory_path() in it is the test's alone while another run goes on, where its runner hands it TMPDIR, which wine does not, a Windows test's TMP, TEMP and temp directory being the Wine prefix's whatever the environment gives, and wasmtime, which hands a test no environment, does not either; how much longer its path is, which a test that binds a socket there has to leave room for; that what it leaves there is removed when it passes or skips and kept, with its place in its log, when it does not; that a later run removes what was kept once the run's directory has gone a minute unchanged, a minute after that run ended or, where it was killed, after its last change to it; and that a test that builds against a sysroot it stages there, or has crafter-build fetch a repository it stages there, whose path keys crafter-build's cache and is a new one every run, points XDG_CACHE_HOME into its TMPDIR as well. AGENTS.template.md's testing conventions say why the fixed staging name is safe now, that a test that writes to /tmp by name makes a directory of its own there, a PrivateDirectory, and that a test that builds against what it stages keeps its cache in its scratch directory. --- AGENTS.template.md | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AGENTS.template.md b/AGENTS.template.md index 91de608..6e4b9f7 100644 --- a/AGENTS.template.md +++ b/AGENTS.template.md @@ -90,7 +90,7 @@ Conventions the existing tests follow: - Open `main.cpp` with a comment that states the behaviour under test and the failure it guards against. `tests/CompilerWarning/main.cpp` shows the shape. - Collect failures with a `Check(cond, msg)` helper that prints `FAIL: ...` to stderr and counts, then return nonzero at the end. Do not stop at the first failure unless later steps are meaningless without it. - Drive the engine in-process: `Build(cfg, depResults, depMutex)`, `RunTests`, the lint driver. Do not shell out to `bin/crafter-build` and grep its stdout. -- Fixtures under `tests//fixture/` are inputs. A test that edits or touches files first stages a copy under `fs::temp_directory_path() / "crafter-build-"`, after removing what an earlier run left there, which matters where the test runs by hand: under `crafter-build test` the copy is in the test's own `TMPDIR`, which goes when the test ends unless the test failed, crashed or timed out and left something in it: then it is kept until a later run removes it, a minute after the run that kept it ended, or, where that run was killed, a minute after its last change to the run's directory. Most tests here remove their copy themselves before they report, and so leave nothing to keep. Variant sources are checked in as `*.in` files and copied over the original inside the staged copy. +- Fixtures under `tests//fixture/` are inputs. A test that edits or touches files first stages a copy under `fs::temp_directory_path() / "crafter-build-"`, after removing what an earlier run left there, which matters where the test runs by hand: under `crafter-build test` the copy is in the test's own `TMPDIR`, which goes when the test ends unless the test failed, crashed or timed out and left something in it: then it is kept until a later run removes it, a minute after the run that kept it ended, or, where that run was killed, a minute after its last change to the run's directory. Most tests here remove their copy themselves before they report, and so leave nothing to keep. Variant sources are checked in as `*.in` files and copied over the original inside the staged copy. The fixed name is safe because `RunTests` gives every test a `TMPDIR` of its own for the run, so two runs at once, natively or in the Flatpak, whose sandboxes all share the app's `/tmp`, stage into different directories. A test that writes to `/tmp` by name, as `HostFlatpak` has to, makes a directory of its own there, a `PrivateDirectory`, which a later run removes, where a killed run left it, once it has not changed for a minute. A test that builds against a sysroot it stages, or has crafter-build fetch a repository it stages, points `XDG_CACHE_HOME` into its scratch directory too, as `SysrootStdModule` and the external-dependency tests do: the cache's key holds that path or URL, which is a new one every run. - Use a fresh `depResults` map per build pass: the map memoises each configuration's result, and each external dependency's fetch and build, for one pass, so reusing it skips rebuilds and pulls you meant to observe. `Build()` itself is safe to call repeatedly on the same `Configuration`. - Set `cfg.path` before calling `GetInterfacesAndImplementations`, and spell `cFiles` as absolute paths: both resolve against the working directory, not the configuration. - `GetInterfacesAndImplementations` only lists the sources. A configuration's `interfaces` and `implementations`, its modules and units with what each imports, are made by `Build()` from what it reads in them, so a test that looks at them builds first. diff --git a/README.md b/README.md index ec26f89..3dc7f20 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,7 @@ Test conventions: - **Exit codes**: `0` = ✅ pass, nonzero = ❌ fail, **`77`** = ⏭ skipped (autoconf convention; use it for runtime opt-outs like "tool not on PATH"). - Each test runs in its own subprocess — a segfault doesn't take the runner down. +- Each test runs with `TMPDIR` naming a directory of its own, `/` in a directory made for the run in the temp directory, or, where the run has given that name out already, the first of `-2`, `-3` and on that it has not, so `fs::temp_directory_path()` in a test is the test's alone, even with another run going at the same time. Its path is longer than the temp directory's by 28 bytes and the name of the test's own directory, room a test that binds a Unix socket there has to leave: a socket's path holds 107 bytes. That takes a runner that hands the test `TMPDIR`, as running it directly and qemu-user do: under wine a Windows test does not get `TMPDIR`, and its `TMP`, `TEMP` and temp directory are the Wine prefix's, which every run in that prefix shares; wasmtime gives a test no environment at all. What a test leaves in its `TMPDIR` is removed when it passes or skips. When it fails, crashes or times out, what it left is kept, and its log in `build/test-logs/` says where, as does what is printed of a test that fails or crashes. A later run removes it once the run's directory has gone a minute unchanged: a minute after the run that kept it ended, or, where that run was killed, a minute after it last made or removed a test's directory there. A test that builds against a sysroot or mingw prefix it stages there, or has crafter-build fetch a repository it stages there (an `ExternalDependency` or a `GitProject` of it), keys crafter-build's cache on that path or URL, which is a new one every run: point `XDG_CACHE_HOME` into its `TMPDIR` as well, or every run leaves an entry of its own in the cache. - Default timeout is 60 s per test, runs in parallel up to `hardware_concurrency()` tests (`--jobs=`). The steps of their builds share one limit, a build's: as many at once as there are hardware threads. - Stdout+stderr is captured and printed atomically on completion. A test that fails, crashes or times out once it is built also writes what it printed, and what crafter-build said of it, to `build/test-logs/.log`, when that is anything, and, where it sets `Test::wayland` and ran, what its compositor printed, if anything, to `.compositor.log` beside it (what a compositor that did not start printed is in `.log`); one that failed to build, or did not get that far, writes neither. `` is the test's name with `-2`, `-3` and on after it where the run has given that name out already, as two configurations or two targets may each declare a test of one name. - A broken fixture `project.cpp` is reported as a single failed test, not a fatal error — other tests still run.