From 8d9c6cf95759907ae9674a35b67ea5223c0dd337 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 6 Apr 2026 13:52:12 -0500 Subject: [PATCH 1/2] STYLE: Consolidate BigIO test scheduling-property blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consolidate scattered set_tests_properties / set_property calls for BigIO large-image tests into unified blocks per test group. ImageBase: merge three separate RESOURCE_LOCK MEMORY_SIZE blocks into one set_tests_properties covering all three tests; add BigIO/RUNS_LONG labels for CTest filtering. TIFF: consolidate four separate set_property(... APPEND ... RUN_SERIAL) calls (one per test) into the existing set_tests_properties blocks. No behavioral change — RUN_SERIAL was already set for all four tests. Meta: consolidate test4's separate set_property(... RUN_SERIAL) into its set_tests_properties block. No behavioral change for test4. Tests 1-3 retain MEMORY_SIZE-only serialization (no RUN_SERIAL added because the MEMORY_SIZE resource lock already serializes memory- intensive tests while permitting non-memory tests to run concurrently, which matters for nightly valgrind/coverage builds). --- Modules/IO/ImageBase/test/CMakeLists.txt | 18 ++++------- Modules/IO/Meta/test/CMakeLists.txt | 14 +++------ Modules/IO/TIFF/test/CMakeLists.txt | 40 ++++-------------------- 3 files changed, 16 insertions(+), 56 deletions(-) diff --git a/Modules/IO/ImageBase/test/CMakeLists.txt b/Modules/IO/ImageBase/test/CMakeLists.txt index 9a990b499de..f4b7082e54b 100644 --- a/Modules/IO/ImageBase/test/CMakeLists.txt +++ b/Modules/IO/ImageBase/test/CMakeLists.txt @@ -52,12 +52,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 16) ${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteConvertReadTest.mha 30000L ) - set_tests_properties( - itkLargeImageWriteConvertReadTest - PROPERTIES - RESOURCE_LOCK - MEMORY_SIZE - ) itk_add_test( NAME itkLargeImageWriteReadTest_2D @@ -67,12 +61,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 16) ${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteReadTest_2D.mha 30000L ) - set_tests_properties( - itkLargeImageWriteReadTest_2D - PROPERTIES - RESOURCE_LOCK - MEMORY_SIZE - ) itk_add_test( NAME itkLargeImageWriteReadTest_3D @@ -83,11 +71,17 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 16) 30000L 4L ) + + # BigIO tests produce multi-gigabyte files; MEMORY_SIZE lock serializes them set_tests_properties( + itkLargeImageWriteConvertReadTest + itkLargeImageWriteReadTest_2D itkLargeImageWriteReadTest_3D PROPERTIES RESOURCE_LOCK MEMORY_SIZE + LABELS + "BigIO;RUNS_LONG" ) endif() diff --git a/Modules/IO/Meta/test/CMakeLists.txt b/Modules/IO/Meta/test/CMakeLists.txt index 84d87ef5e43..91492c3a8eb 100644 --- a/Modules/IO/Meta/test/CMakeLists.txt +++ b/Modules/IO/Meta/test/CMakeLists.txt @@ -482,7 +482,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5) 50000L ) - # Due to the large memory requirements this tests must be run one by one + # Due to the large memory requirements these tests must be run one by one set_tests_properties( itkLargeMetaImageWriteReadTest1 itkLargeMetaImageWriteReadTest2 @@ -532,7 +532,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) 70000L ) - # Due to the large memory requirements this tests must be run one by one + # Due to the large memory requirements this test must be run serially set_tests_properties( itkLargeMetaImageWriteReadTest4 PROPERTIES @@ -542,6 +542,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) MEMORY_SIZE COST 30 + RUN_SERIAL + True ) set_property( TEST @@ -551,12 +553,4 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) LABELS RUNS_LONG ) - set_property( - TEST - itkLargeMetaImageWriteReadTest4 - APPEND - PROPERTY - RUN_SERIAL - True - ) endif() diff --git a/Modules/IO/TIFF/test/CMakeLists.txt b/Modules/IO/TIFF/test/CMakeLists.txt index 1dd906b9508..3201e6b7a06 100644 --- a/Modules/IO/TIFF/test/CMakeLists.txt +++ b/Modules/IO/TIFF/test/CMakeLists.txt @@ -486,7 +486,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5) 50000L ) - # Due to the large memory requirements this tests must be run one by one + # Due to the large memory requirements these tests must be run one by one set_tests_properties( itkLargeTIFFImageWriteReadTest1 itkLargeTIFFImageWriteReadTest2 @@ -496,6 +496,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5) BigIO RESOURCE_LOCK MEMORY_SIZE + RUN_SERIAL + True ) set_property( TEST @@ -505,14 +507,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5) LABELS RUNS_LONG ) - set_property( - TEST - itkLargeTIFFImageWriteReadTest1 - APPEND - PROPERTY - RUN_SERIAL - True - ) set_property( TEST itkLargeTIFFImageWriteReadTest2 @@ -521,14 +515,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5) LABELS RUNS_LONG ) - set_property( - TEST - itkLargeTIFFImageWriteReadTest2 - APPEND - PROPERTY - RUN_SERIAL - True - ) set_property( TEST itkLargeTIFFImageWriteReadTest3 @@ -537,14 +523,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5) LABELS RUNS_LONG ) - set_property( - TEST - itkLargeTIFFImageWriteReadTest3 - APPEND - PROPERTY - RUN_SERIAL - True - ) endif() if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) @@ -558,7 +536,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) 70000L ) - # Due to the large memory requirements this tests must lock the memory size resource + # Due to the large memory requirements this test must be run serially set_tests_properties( itkLargeTIFFImageWriteReadTest4 PROPERTIES @@ -568,6 +546,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) MEMORY_SIZE COST 30 + RUN_SERIAL + True ) set_property( TEST @@ -577,14 +557,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) LABELS RUNS_LONG ) - set_property( - TEST - itkLargeTIFFImageWriteReadTest4 - APPEND - PROPERTY - RUN_SERIAL - True - ) endif() # expand + RGB image From eca08fff7fb8830c1f4dc8a325f108b4a6b55319 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 6 Apr 2026 13:54:14 -0500 Subject: [PATCH 2/2] ENH: Add itk_add_file_test_cleanup for automatic test output cleanup Add itk_add_file_test_cleanup() to ITKModuleTest.cmake. The function uses CTest FIXTURES_SETUP/FIXTURES_CLEANUP to register a companion _cleanup test that removes specified output files after the main test completes. Controlled by the ITK_REMOVE_TEST_FILES_ON_SUCCESS option (default ON). When OFF, no cleanup test is registered and files are retained for manual debugging. For .mhd output files the companion .raw/.zraw sidecar is automatically included in the removal list. Apply to all BigIO large-image tests in IO/ImageBase, IO/Meta, and IO/TIFF where multi-gigabyte outputs would otherwise accumulate and exhaust disk space on CI runners and local builds. The function name was chosen to be IO-format-agnostic (suggested by blowekamp during review of an earlier draft). --- CMake/ITKModuleTest.cmake | 76 ++++++++++++++++++++++++ Modules/IO/ImageBase/test/CMakeLists.txt | 11 ++++ Modules/IO/Meta/test/CMakeLists.txt | 5 ++ Modules/IO/TIFF/test/CMakeLists.txt | 5 ++ 4 files changed, 97 insertions(+) diff --git a/CMake/ITKModuleTest.cmake b/CMake/ITKModuleTest.cmake index 9e957fe9a6c..7e8b98e1a64 100644 --- a/CMake/ITKModuleTest.cmake +++ b/CMake/ITKModuleTest.cmake @@ -337,3 +337,79 @@ function(itk_memcheck_ignore) ${ARGN} ) endfunction() + +#----------------------------------------------------------------------------- +# Option to automatically remove large test output files after completion. +# BigIO write-read tests can produce multi-gigabyte temporary files +# that exhaust disk space on CI runners and local builds. +option( + ITK_REMOVE_TEST_FILES_ON_SUCCESS + "Remove large test output files after test completion. Set OFF to retain files for debugging." + ON +) +mark_as_advanced(ITK_REMOVE_TEST_FILES_ON_SUCCESS) + +#----------------------------------------------------------------------------- +# itk_add_file_test_cleanup( [ ...]) +# +# Adds a cleanup test that removes the given output files after +# completes. Uses CTest fixtures: the main test is declared FIXTURES_SETUP +# and the companion _cleanup test is declared FIXTURES_CLEANUP. +# +# NOTE: Per CMake documentation, FIXTURES_CLEANUP tests execute +# unconditionally after their fixture — they run regardless of whether the +# SETUP test passed, failed, or was skipped. To retain output files for +# debugging after a failure, set ITK_REMOVE_TEST_FILES_ON_SUCCESS=OFF. +# +# NOTE: In a full unfiltered run all tests (including *_cleanup variants) +# are in the active set and fixture ordering is respected. When rerunning +# a single test with a strict filter (e.g. ctest -R "^$"), +# the *_cleanup test does not match; omit the anchors (ctest -R ) +# so both the main test and its cleanup are selected. +# +# When ITK_REMOVE_TEST_FILES_ON_SUCCESS is OFF, no cleanup test is added +# and the output files are retained for manual inspection. +# +function(itk_add_file_test_cleanup TEST_NAME) + if(NOT ITK_REMOVE_TEST_FILES_ON_SUCCESS) + return() + endif() + + set(FIXTURE_NAME "Cleanup_${TEST_NAME}") + + # Make the main test the SETUP of this fixture + set_tests_properties( + ${TEST_NAME} + PROPERTIES + FIXTURES_SETUP + ${FIXTURE_NAME} + ) + + # Build the removal command for all output files + set(RM_ARGS "") + foreach(OUTPUT_FILE ${ARGN}) + # For .mhd files, also remove the companion .raw/.zraw + get_filename_component(EXT "${OUTPUT_FILE}" LAST_EXT) + get_filename_component(BASE_NAME "${OUTPUT_FILE}" NAME_WLE) + get_filename_component(DIR "${OUTPUT_FILE}" DIRECTORY) + list(APPEND RM_ARGS "${OUTPUT_FILE}") + if("${EXT}" STREQUAL ".mhd") + list(APPEND RM_ARGS "${DIR}/${BASE_NAME}.raw") + list(APPEND RM_ARGS "${DIR}/${BASE_NAME}.zraw") + endif() + endforeach() + + add_test( + NAME ${TEST_NAME}_cleanup + COMMAND + ${CMAKE_COMMAND} -E rm -f ${RM_ARGS} + ) + set_tests_properties( + ${TEST_NAME}_cleanup + PROPERTIES + FIXTURES_CLEANUP + ${FIXTURE_NAME} + LABELS + "CLEANUP" + ) +endfunction() diff --git a/Modules/IO/ImageBase/test/CMakeLists.txt b/Modules/IO/ImageBase/test/CMakeLists.txt index f4b7082e54b..bb9d2867113 100644 --- a/Modules/IO/ImageBase/test/CMakeLists.txt +++ b/Modules/IO/ImageBase/test/CMakeLists.txt @@ -83,6 +83,17 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 16) LABELS "BigIO;RUNS_LONG" ) + + # Clean up BigIO output files after completion + itk_add_file_test_cleanup( + itkLargeImageWriteConvertReadTest ${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteConvertReadTest.mha + ) + itk_add_file_test_cleanup( + itkLargeImageWriteReadTest_2D ${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteReadTest_2D.mha + ) + itk_add_file_test_cleanup( + itkLargeImageWriteReadTest_3D ${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteReadTest_3D.mha + ) endif() itk_add_test( diff --git a/Modules/IO/Meta/test/CMakeLists.txt b/Modules/IO/Meta/test/CMakeLists.txt index 91492c3a8eb..fbab393885e 100644 --- a/Modules/IO/Meta/test/CMakeLists.txt +++ b/Modules/IO/Meta/test/CMakeLists.txt @@ -519,6 +519,10 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5) LABELS RUNS_LONG ) + # Clean up BigIO output files after completion + itk_add_file_test_cleanup(itkLargeMetaImageWriteReadTest1 ${ITK_TEST_OUTPUT_DIR}/LargeImage01.mhd) + itk_add_file_test_cleanup(itkLargeMetaImageWriteReadTest2 ${ITK_TEST_OUTPUT_DIR}/LargeImage02.mhd) + itk_add_file_test_cleanup(itkLargeMetaImageWriteReadTest3 ${ITK_TEST_OUTPUT_DIR}/LargeImage03.mhd) endif() if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) @@ -553,4 +557,5 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) LABELS RUNS_LONG ) + itk_add_file_test_cleanup(itkLargeMetaImageWriteReadTest4 ${ITK_TEST_OUTPUT_DIR}/LargeImage04.mhd) endif() diff --git a/Modules/IO/TIFF/test/CMakeLists.txt b/Modules/IO/TIFF/test/CMakeLists.txt index 3201e6b7a06..a3b0766e5f6 100644 --- a/Modules/IO/TIFF/test/CMakeLists.txt +++ b/Modules/IO/TIFF/test/CMakeLists.txt @@ -523,6 +523,10 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5) LABELS RUNS_LONG ) + # Clean up BigIO output files after completion + itk_add_file_test_cleanup(itkLargeTIFFImageWriteReadTest1 ${ITK_TEST_OUTPUT_DIR}/LargeImage01.tif) + itk_add_file_test_cleanup(itkLargeTIFFImageWriteReadTest2 ${ITK_TEST_OUTPUT_DIR}/LargeImage02.tif) + itk_add_file_test_cleanup(itkLargeTIFFImageWriteReadTest3 ${ITK_TEST_OUTPUT_DIR}/LargeImage03.tif) endif() if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) @@ -557,6 +561,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12) LABELS RUNS_LONG ) + itk_add_file_test_cleanup(itkLargeTIFFImageWriteReadTest4 ${ITK_TEST_OUTPUT_DIR}/LargeImage04.tif) endif() # expand + RGB image