docker: the test stage's parallelism and CPU budgets apart from the compile (build.sh -J, -B)

The per-binary CPU budgets are set on a fast machine. A VM on an EPYC 7302 spends 4.6x the quoted
CPU time on tokenizer_test's reference pass, so the image's test stage failed there on a correct
tree, and -j sized for the compile also sized the tests: twelve at once on a 24-thread host put
tests on busy SMT siblings, which costs CPU seconds too.

RAD_TEST_CPU_BUDGET_SCALE multiplies the budget where rad_test.h reads it, at run time, so a
direct ctest takes it as well and the build layer is untouched by it. The stage takes it as
TEST_CPU_BUDGET_SCALE (build.sh -B) and its parallelism as TEST_JOBS (build.sh -J), each empty by
default, which is the stage as before. harness_test checks the factor and keeps it out of its
fixture's environment; docs/DOCKER.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Opus 5.5 committed 2026-10-19 13:37:01 +02:00
1 parent 44aecb0ab8
commit 748f63637e
5 files changed
+33 -6

No files matched your search

+7 -1
View File
@@ -23,7 +23,7 @@ struct Run {
* inherited from ctest. */
Run fixture(const std::string& args, const std::string& env = "") {
const std::string cmd = "env -u RAD_TEST_FILTER -u RAD_TEST_STRICT -u RAD_TEST_LEVEL "
"-u RAD_TEST_CPU_BUDGET " + env + " '" RAD_HARNESS_FIXTURE "' " +
"-u RAD_TEST_CPU_BUDGET -u RAD_TEST_CPU_BUDGET_SCALE " + env + " '" RAD_HARNESS_FIXTURE "' " +
args + " 2>&1";
Run r;
FILE* p = popen(cmd.c_str(), "r");
@@ -194,6 +194,12 @@ TEST(a_binary_over_its_cpu_budget_fails) {
CHECK(has(r.out, "slowest: burns_cpu "));
r = fixture("passes_one", "RAD_TEST_CPU_BUDGET=60");
CHECK_EQ(r.status, 0);
/* A slower host scales every budget by one factor. */
r = fixture("burns_cpu passes_one", "RAD_TEST_CPU_BUDGET=0.05 RAD_TEST_CPU_BUDGET_SCALE=2");
CHECK_EQ(r.status, 1);
CHECK(has(r.out, "over its budget of 0.1 s"));
r = fixture("burns_cpu passes_one", "RAD_TEST_CPU_BUDGET=0.05 RAD_TEST_CPU_BUDGET_SCALE=100");
CHECK_EQ(r.status, 0);
}
/* A command line the harness does not understand is refused rather than read as a filter. */
+5 -1
View File
@@ -14,6 +14,8 @@
* RAD_TEST_TMPDIR where tmpdir() is made, before $TMPDIR and /tmp
* RAD_TEST_CPU_BUDGET seconds of process CPU time the binary may spend; over it, it fails
* tests/CMakeLists.txt sets the last three for every ctest entry.
* RAD_TEST_CPU_BUDGET_SCALE a factor on that budget, for a host slower per thread than the
* one the budgets were set on; unset or 0 is 1
*
* Exit status: 1 when a check failed (an exception escaping a case is a failed check), 77 when
* nothing failed and no check ran, 2 for a command line it does not understand, else 0. 77 is
@@ -288,7 +290,9 @@ inline int run_all(int argc, char** argv) {
* so a slow case or a spinning thread pool is caught when it lands. CPU time rather than wall
* time, so a loaded machine does not fail a correct binary. */
if (const char* b = std::getenv("RAD_TEST_CPU_BUDGET")) {
const double budget = std::atof(b);
double budget = std::atof(b);
if (const char* s = std::getenv("RAD_TEST_CPU_BUDGET_SCALE"); s && std::atof(s) > 0)
budget *= std::atof(s);
if (budget > 0 && cpu > budget && rc != 1) {
fprintf(stderr, " FAIL the binary spent %.2f s of CPU, over its budget of %g s "
"(RAD_TEST_CPU_BUDGET)\n", cpu, budget);