CTest tests that run a build in the build tree must share RESOURCE_LOCK build_tree
PitfallVerified 27 Sep 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
With ctest --preset tests -j8, a test that runs a build in the build tree fails at random, while it passes alone. The log of the build tree is corrupted.
Cause#
Some tests do not run a test binary but invoke a build in the same build tree: schema_class_bad_member builds a target that must fail to compile (it checks for the text "schema class members must be index::Field"), and c_abi_guard builds too. When CTest runs two of them at once, two builds write the same build tree and its log at the same time.
Fix#
Give every test that runs a build in the build tree the same resource lock, so CTest never runs two of them at once:
# Both tests run a build in this build tree; two at once corrupt its log.
set_tests_properties(
schema_class_bad_member
PROPERTIES PASS_REGULAR_EXPRESSION
"schema class members must be index::Field"
RESOURCE_LOCK build_tree)
set_tests_properties(c_abi_guard PROPERTIES RESOURCE_LOCK build_tree)
Add the lock to any new test of this kind.
Evidence#
tests/CMakeLists.txtin dftracer-utils, added in stage 7b after a concurrent build collided with a parallel ctest run.
Also found by searching
- ctest -j8 schema_class_bad_member fails randomly, passes when run alone
- tests that invoke a build inside the build tree corrupt each other in parallel
- how do I stop ctest from running compile-failure tests concurrently
- set_tests_properties RESOURCE_LOCK for try-compile style tests sharing build dir
- ctest --preset tests -j8 random failure in schema_class_bad_member, passes alone, build log corrupted
- tests that invoke cmake --build inside ctest clash when run in parallel
- how do I serialize CTest tests that run builds in the same build directory?
- RESOURCE_LOCK for ctest parallel -j tests that share build tree, c_abi_guard