COMP: Auto-remove transient single-owner test outputs in itk_add_test#6414
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
3c69730 to
00ff40a
Compare
00ff40a to
09a7404
Compare
|
Rebased on top of main, to keep this PR one commit only. |
dzenanz
left a comment
There was a problem hiding this comment.
Why were these test outputs selected for cleanup, and not the other ~3000?
They are exactly the set of tests touched by the merged race fix #6413. #6413 found 13 write-write output collisions among 2719 tests and renamed one side of each colliding pair. This PR wires itk_add_file_test_cleanup() for precisely those same tests, in the same CMake scopes #6413 had already edited. The scope is "the tests we just de-raced," not "the best ~13 of 3000." The other ~3000 were originally deliberately deferred: the mechanism (itk_add_file_test_cleanup, gated by the default-ON ITK_REMOVE_TEST_FILES_ON_SUCCESS) will be fully general across all tests. I will apply more broadly soon, but originall thought it would be too much for single PR. This initial PR proves the mechanism on the recently-touched test cases. ** I'll make an update to this PR that includes all the cases. |
09a7404 to
be61143
Compare
|
@dzenanz Re: "why these and not the other ~3000?" — addressed by instrumenting all of them. The PR now wires Selection was deterministic (a parser over all 2692 |
|
Sorry I got to looking this over late. Consider adding a "CLEANUP" argument to add these that takes a list of files to delete on success. |
be61143 to
735262c
Compare
|
Done — adopted in 735262c. Added a Verified behavior-preserving: the generated CTest |
735262c to
5bf52bb
Compare
dzenanz
left a comment
There was a problem hiding this comment.
I like this approach better. Some in-line suggestions.
blowekamp
left a comment
There was a problem hiding this comment.
Thank you for stream linking into the one function. It looks good. updating the stub file will get gersemi to format the call correctly.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
5bf52bb to
c676e1d
Compare
|
Pushed
Local validationRebuilt affected drivers; all 1068 |
|
Re-triggering |
|
/azp run ITK.macOS.Python |
dzenanz
left a comment
There was a problem hiding this comment.
Thank you for addressing my feedback (and co-authorship).
c676e1d to
873212e
Compare
|
Some |
Why both .raw and .zraw are there: it was me being overly optimistic/defensive, not because both files exist. When I expanded each .mhd entry, I added both companions without checking which one each test actually writes, relying on the fact that file(GLOB) simply no-ops on the non-existent one. So nothing extra is deleted (a .zraw that isn't generated can't match), but the source lists a companion the code never generates. This was easier to implement. I'm now doing a full build/test/experiment to validate what is actually written to disk, limiting the patterns to only what is actually written, not what could be written under the same input name. |
Wire transient-output cleanup into every test whose ${ITK_TEST_OUTPUT_DIR}/
${TEMP} outputs are owned by a single test. Each such test lists its outputs
with an ITK_REMOVE_TEMPORARY_TEST_FILES <file>... argument to itk_add_test,
which registers a FIXTURES_CLEANUP companion that removes them. Gated by the
ITK_REMOVE_TEMPORARY_TEST_FILES option (ON by default); set OFF to retain
outputs for debugging.
The argument keeps each test's cleanup file list co-located with the
itk_add_test call that produces them, rather than a separate
itk_add_file_test_cleanup() companion call. It is the only parsed keyword, so
it must appear last. The gersemi stub declares it so call sites format
correctly.
Detached-header outputs (.mhd, .nhdr) also remove their companion raw data
files, and the cleanup command uses rm -rf so directory outputs (DICOM
series, FileTools dirs) are removed as well as plain files.
1355 tests instrumented across 126 test/CMakeLists.txt. 42 multi-consumer
shared outputs are excluded so the file persists for the consuming test.
Co-authored-by: Bradley Lowekamp <blowekamp@mail.nih.gov>
Co-authored-by: Dženan Zukić <dzenan.zukic@kitware.com>
873212e to
b2a774f
Compare
|
Good catch — that double-listing was me being defensive, not evidence-based. Fixed in b2a774f. I built ITK with full ExternalData + BrainWeb + examples and ran the suite with cleanup OFF to record exactly which data file each detached-header test writes. No test writes both: each So each shared stem is now a single brace entry listing only the extensions actually produced:
|
Add an optional
ITK_REMOVE_TEMPORARY_TEST_FILES <file>...argument toitk_add_test()so a test can list the transient${ITK_TEST_OUTPUT_DIR}/${TEMP}outputs it owns; each such test gets aFIXTURES_CLEANUPcompanion that deletes them. Gated by theITK_REMOVE_TEMPORARY_TEST_FILESoption (ONby default); configure-DITK_REMOVE_TEMPORARY_TEST_FILES=OFFto retain outputs for debugging.1355 tests instrumented across 126
test/CMakeLists.txt. Supersedes the original 12-file scope after a reviewer asked why only a subset was cleaned.Scope: how the test set was selected
A deterministic parser over all
Modules/**/test/CMakeLists.txtgroups every writable${ITK_TEST_OUTPUT_DIR}/${TEMP}output by the tests referencing it:.dot→*Plot, IOScanco read-written.isq/.aim, etc.). NoDEPENDS-based consumer chains exist, so no shared file is missed.Commented-out
itk_add_testblocks and tests whoseNAMEis an unresolved${var}are skipped.Default behavior (default-ON is intentional)
Removing transient outputs is the intended default. Per CMake, a
FIXTURES_CLEANUPtest runs unconditionally after its fixture — pass, fail, or skip — so outputs are removed even on failure. A developer who needs to inspect outputs opts out with-DITK_REMOVE_TEMPORARY_TEST_FILES=OFF. The option documentation inCMake/ITKModuleTest.cmakestates this explicitly.Helper details
itk_add_test, so it must appear last; this is documented in the helper, andCMake/stubs/itk_add_test.cmakedeclares it so gersemi formats call sites correctly.cmake -E rm -rf, so directory outputs (DICOM series,FileToolsdirs) are removed as well as plain files..mhd→.raw/.zraw,.nhdr→.raw/.raw.gz.Local validation
upstream/main;pre-commit run --all-filesclean._cleanuptests in the default build config pass (0 failures)..nhdrtest + a comma-list Video test: pass, with the actual outputs (dirs, files, companions) confirmed removed.