Fix CMake unit test race condition#5093
Merged
LeStarch merged 9 commits intonasa:develfrom May 5, 2026
Merged
Conversation
Two test targets (`_test_autocode` and `_test_chained_autocode`) both
invoke the `test_target_autocoder`, which registers an
`add_custom_command(OUTPUT ${BASENAME}.test-target.generated.txt
COMMAND ${CMAKE_COMMAND} -E copy ...)` for each module. CMake emits the
same copy rule into each custom target's submakefile, so under
`make -jN` the two rules can fire simultaneously and race on the
destination file, intermittently producing:
Error copying file "...test1.test-target.txt" to
"...test1.test-target.generated.txt".
Make the chained-autocode custom target depend on the `_test_autocode`
sibling. Make then serializes the two, ensuring the copy fires once and
the second build.make sees the destination as up-to-date.
Co-Authored-By: thomas.boyer.chammard <thomas.boyer.chammard@jpl.nasa.gov>
Co-Authored-By: thomas.boyer.chammard <thomas.boyer.chammard@jpl.nasa.gov>
Co-Authored-By: thomas.boyer.chammard <thomas.boyer.chammard@jpl.nasa.gov>
Added manual dependency to prevent race condition between test targets.
… filenames Both target/test_autocoder and target/test_chained_autocoder used to invoke autocoder/test_target_autocoder on the same module, so CMake emitted the same `cmake -E copy` rule for *.test-target.generated.txt into both targets' sub-makefiles. Under `make -jN` the two copies of the rule could fire in parallel and race on the destination file, producing intermittent 'Error copying file' failures in CI. Give the chained test its own input suffix (.chained-input.txt) and a dedicated first-stage autocoder (autocoder/test_chained_input_autocoder) that emits .chained-input.generated.txt. The standalone test_target_autocoder now only matches files in TestTargetAutocoder, so no two test targets produce the same output filename and the race is eliminated at the source.
LeStarch
requested changes
May 5, 2026
Collaborator
LeStarch
left a comment
There was a problem hiding this comment.
This isn't right either. A chained AC should use input from the first autocoder, so creating input files defeats the purpose of the test.
…e output filenames" This reverts commit d4df7f9.
Both targets are registered globally and applied to every module, and both
invoke test_target_autocoder. CMake's Makefile generator then emits the same
`cmake -E copy` rule into both submakefiles for any module reached by both
targets, causing make -jN to race on the destination file ("Error copying
file ...").
Each test fixture only needs one of the two targets, so opt out of the other
via a CMake variable read inside the target's add_module_target hook:
- TestChainedAutocoderModule sets SKIP_TEST_AUTOCODER_TARGET. The chained
target still runs test_target_autocoder as the genuine first stage.
- TestTargetAutocoderModule sets SKIP_TEST_CHAINED_AUTOCODER_TARGET. The
standalone target keeps testing test_target_autocoder by itself.
The flags must be set before register_fprime_module since custom targets are
attached inside that call.
Each cmake -E copy rule is now emitted into exactly one submakefile, so the
race cannot occur.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
LeStarch
previously approved these changes
May 5, 2026
LeStarch
approved these changes
May 5, 2026
Collaborator
LeStarch
left a comment
There was a problem hiding this comment.
My understanding is that this is the appropriate fix in this scenario.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Description
We've seen intermittent failures in the CMake UTs. Devin says this should fix it.
AI Usage (see policy)
Devin. See JPL-Devin#40