Commit ce501e0
Fix CMake unit test race condition (#5093)
* Fix race in CMake chained autocoder test target
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>
* Expand comment explaining the parallel-build race fix
Co-Authored-By: thomas.boyer.chammard <thomas.boyer.chammard@jpl.nasa.gov>
* Tighten comment on test_chained_autocoder serialization
Co-Authored-By: thomas.boyer.chammard <thomas.boyer.chammard@jpl.nasa.gov>
* Clarify comment
Added manual dependency to prevent race condition between test targets.
* fix spelling
* Differentiate chained-autocoder test inputs to avoid duplicate output 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.
* Revert "Differentiate chained-autocoder test inputs to avoid duplicate output filenames"
This reverts commit d4df7f9.
* Make test_autocoder and test_chained_autocoder targets non-overlapping
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>
* fix spelling
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin <devin@cognition.ai>1 parent e7ac9e5 commit ce501e0
4 files changed
Lines changed: 24 additions & 1 deletion
File tree
- cmake/test/data
- TestDeployment
- TestChainedAutocoder
- TestTargetAutocoder
- cmake/target
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
1 | 6 | | |
2 | 7 | | |
3 | 8 | | |
| |||
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
| 14 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
6 | 12 | | |
7 | 13 | | |
8 | 14 | | |
| 15 | + | |
9 | 16 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | | - | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
0 commit comments