Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions CMake/ITKModuleTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(<test_name> <output_file> [<output_file2> ...])
#
# Adds a cleanup test that removes the given output files after <test_name>
# completes. Uses CTest fixtures: the main test is declared FIXTURES_SETUP
# and the companion <test_name>_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 "^<test_name>$"),
# the *_cleanup test does not match; omit the anchors (ctest -R <test_name>)
# 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"
)
Comment thread
hjmjohnson marked this conversation as resolved.
endfunction()
29 changes: 17 additions & 12 deletions Modules/IO/ImageBase/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Comment thread
blowekamp marked this conversation as resolved.

itk_add_test(
NAME itkLargeImageWriteReadTest_2D
Expand All @@ -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
Expand All @@ -83,11 +71,28 @@ 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"
)

# 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()

Expand Down
19 changes: 9 additions & 10 deletions Modules/IO/Meta/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -532,7 +536,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
Expand All @@ -542,6 +546,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
MEMORY_SIZE
COST
30
RUN_SERIAL
True
)
set_property(
TEST
Expand All @@ -551,12 +557,5 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
LABELS
RUNS_LONG
)
set_property(
TEST
itkLargeMetaImageWriteReadTest4
APPEND
PROPERTY
RUN_SERIAL
True
)
itk_add_file_test_cleanup(itkLargeMetaImageWriteReadTest4 ${ITK_TEST_OUTPUT_DIR}/LargeImage04.mhd)
endif()
45 changes: 11 additions & 34 deletions Modules/IO/TIFF/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -496,6 +496,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
BigIO
RESOURCE_LOCK
MEMORY_SIZE
RUN_SERIAL
True
)
set_property(
TEST
Expand All @@ -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
Expand All @@ -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
Expand All @@ -537,14 +523,10 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
LABELS
RUNS_LONG
)
set_property(
TEST
itkLargeTIFFImageWriteReadTest3
APPEND
PROPERTY
RUN_SERIAL
True
)
# 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)
Expand All @@ -558,7 +540,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
Expand All @@ -568,6 +550,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
MEMORY_SIZE
COST
30
RUN_SERIAL
True
)
set_property(
TEST
Expand All @@ -577,14 +561,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
LABELS
RUNS_LONG
)
set_property(
TEST
itkLargeTIFFImageWriteReadTest4
APPEND
PROPERTY
RUN_SERIAL
True
)
itk_add_file_test_cleanup(itkLargeTIFFImageWriteReadTest4 ${ITK_TEST_OUTPUT_DIR}/LargeImage04.tif)
endif()

# expand + RGB image
Expand Down
Loading