Skip to content

Commit 519bb41

Browse files
hjmjohnsonclaude
andcommitted
ENH: Auto-cleanup BigIO test outputs and enforce serial execution
Add ITK_REMOVE_BIGIO_FILES_ON_SUCCESS (advanced, default ON) that automatically removes multi-gigabyte BigIO test output files after test completion using CTest fixtures. Files are removed after the test finishes regardless of pass or fail — set the option OFF to always retain output files for debugging. NOTE: FIXTURES_CLEANUP tests run unconditionally per CMake semantics: "Cleanup tests will execute even if setup or regular tests for that fixture fail or are skipped." The option name reflects the historical intent; the description clarifies the actual runtime behavior. Additionally ensure all BigIO tests (>1 GB output) run serially via RUN_SERIAL to prevent concurrent disk exhaustion. New CMake function itk_add_bigio_test_cleanup() uses CTest FIXTURES to wire up SETUP (main test) and CLEANUP (file removal) phases. For .mhd files, companion .raw/.zraw files are also removed. The companion cleanup test is named <test_name>_cleanup; to include it in filtered reruns omit strict anchors (ctest -R <test_name> rather than ctest -R "^<test_name>$"). Affected modules: - IO/Meta: LargeMetaImageWriteReadTest 1-4 (.mhd + .raw) - IO/TIFF: LargeTIFFImageWriteReadTest 1-4 (.tif) - IO/ImageBase: LargeImageWriteReadTest 2D/3D, WriteConvertRead (.mha) These 11 tests produce up to 47 GB of temporary files total. Without cleanup, they can exhaust disk space on CI runners (GitHub Actions ubuntu-22.04 has 146 GB total). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b94cca5 commit 519bb41

File tree

4 files changed

+117
-56
lines changed

4 files changed

+117
-56
lines changed

CMake/ITKModuleTest.cmake

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,79 @@ function(itk_memcheck_ignore)
337337
${ARGN}
338338
)
339339
endfunction()
340+
341+
#-----------------------------------------------------------------------------
342+
# Option to automatically remove BigIO test output files on success.
343+
# BigIO write-read tests can produce multi-gigabyte temporary files
344+
# that exhaust disk space on CI runners and local builds.
345+
option(
346+
ITK_REMOVE_BIGIO_FILES_ON_SUCCESS
347+
"Remove BigIO test output files after test completion (pass or fail). Set OFF to retain files for debugging."
348+
ON
349+
)
350+
mark_as_advanced(ITK_REMOVE_BIGIO_FILES_ON_SUCCESS)
351+
352+
#-----------------------------------------------------------------------------
353+
# itk_add_bigio_test_cleanup(<test_name> <output_file> [<output_file2> ...])
354+
#
355+
# Adds a cleanup test that removes the given output files after <test_name>
356+
# completes. Uses CTest fixtures: the main test is declared FIXTURES_SETUP
357+
# and the companion <test_name>_cleanup test is declared FIXTURES_CLEANUP.
358+
#
359+
# NOTE: Per CMake documentation, FIXTURES_CLEANUP tests execute
360+
# unconditionally after their fixture — they run regardless of whether the
361+
# SETUP test passed, failed, or was skipped. To retain output files for
362+
# debugging after a failure, set ITK_REMOVE_BIGIO_FILES_ON_SUCCESS=OFF.
363+
#
364+
# NOTE: In a full unfiltered run all tests (including *_cleanup variants)
365+
# are in the active set and fixture ordering is respected. When rerunning
366+
# a single test with a strict filter (e.g. ctest -R "^<test_name>$"),
367+
# the *_cleanup test does not match; omit the anchors (ctest -R <test_name>)
368+
# so both the main test and its cleanup are selected.
369+
#
370+
# When ITK_REMOVE_BIGIO_FILES_ON_SUCCESS is OFF, no cleanup test is added
371+
# and the output files are retained for manual inspection.
372+
#
373+
function(itk_add_bigio_test_cleanup TEST_NAME)
374+
if(NOT ITK_REMOVE_BIGIO_FILES_ON_SUCCESS)
375+
return()
376+
endif()
377+
378+
set(FIXTURE_NAME "BigIO_${TEST_NAME}")
379+
380+
# Make the main test the SETUP of this fixture
381+
set_tests_properties(
382+
${TEST_NAME}
383+
PROPERTIES
384+
FIXTURES_SETUP
385+
${FIXTURE_NAME}
386+
)
387+
388+
# Build the removal command for all output files
389+
set(RM_ARGS "")
390+
foreach(OUTPUT_FILE ${ARGN})
391+
# For .mhd files, also remove the companion .raw/.zraw
392+
get_filename_component(EXT "${OUTPUT_FILE}" LAST_EXT)
393+
get_filename_component(NAME_WLE "${OUTPUT_FILE}" NAME_WLE)
394+
get_filename_component(DIR "${OUTPUT_FILE}" DIRECTORY)
395+
list(APPEND RM_ARGS "${OUTPUT_FILE}")
396+
if("${EXT}" STREQUAL ".mhd")
397+
list(APPEND RM_ARGS "${DIR}/${NAME_WLE}.raw")
398+
list(APPEND RM_ARGS "${DIR}/${NAME_WLE}.zraw")
399+
endif()
400+
endforeach()
401+
402+
add_test(
403+
NAME ${TEST_NAME}_cleanup
404+
COMMAND
405+
${CMAKE_COMMAND} -E rm -f ${RM_ARGS}
406+
)
407+
set_tests_properties(
408+
${TEST_NAME}_cleanup
409+
PROPERTIES
410+
FIXTURES_CLEANUP
411+
${FIXTURE_NAME}
412+
LABELS
413+
"BigIO;CLEANUP"
414+
)
415+
endfunction()

Modules/IO/ImageBase/test/CMakeLists.txt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 16)
5252
${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteConvertReadTest.mha
5353
30000L
5454
)
55-
set_tests_properties(
56-
itkLargeImageWriteConvertReadTest
57-
PROPERTIES
58-
RESOURCE_LOCK
59-
MEMORY_SIZE
60-
)
6155

6256
itk_add_test(
6357
NAME itkLargeImageWriteReadTest_2D
@@ -67,12 +61,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 16)
6761
${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteReadTest_2D.mha
6862
30000L
6963
)
70-
set_tests_properties(
71-
itkLargeImageWriteReadTest_2D
72-
PROPERTIES
73-
RESOURCE_LOCK
74-
MEMORY_SIZE
75-
)
7664

7765
itk_add_test(
7866
NAME itkLargeImageWriteReadTest_3D
@@ -83,11 +71,30 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 16)
8371
30000L
8472
4L
8573
)
74+
75+
# BigIO tests produce multi-gigabyte files and must run serially
8676
set_tests_properties(
77+
itkLargeImageWriteConvertReadTest
78+
itkLargeImageWriteReadTest_2D
8779
itkLargeImageWriteReadTest_3D
8880
PROPERTIES
8981
RESOURCE_LOCK
9082
MEMORY_SIZE
83+
LABELS
84+
"BigIO;RUNS_LONG"
85+
RUN_SERIAL
86+
True
87+
)
88+
89+
# Clean up BigIO output files after successful completion
90+
itk_add_bigio_test_cleanup(
91+
itkLargeImageWriteConvertReadTest ${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteConvertReadTest.mha
92+
)
93+
itk_add_bigio_test_cleanup(
94+
itkLargeImageWriteReadTest_2D ${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteReadTest_2D.mha
95+
)
96+
itk_add_bigio_test_cleanup(
97+
itkLargeImageWriteReadTest_3D ${ITK_TEST_OUTPUT_DIR}/itkLargeImageWriteReadTest_3D.mha
9198
)
9299
endif()
93100

Modules/IO/Meta/test/CMakeLists.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
482482
50000L
483483
)
484484

485-
# Due to the large memory requirements this tests must be run one by one
485+
# Due to the large memory requirements these tests must be run one by one
486486
set_tests_properties(
487487
itkLargeMetaImageWriteReadTest1
488488
itkLargeMetaImageWriteReadTest2
@@ -494,6 +494,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
494494
MEMORY_SIZE
495495
COST
496496
10
497+
RUN_SERIAL
498+
True
497499
)
498500
set_property(
499501
TEST
@@ -519,6 +521,10 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
519521
LABELS
520522
RUNS_LONG
521523
)
524+
# Clean up BigIO output files after successful completion
525+
itk_add_bigio_test_cleanup(itkLargeMetaImageWriteReadTest1 ${ITK_TEST_OUTPUT_DIR}/LargeImage01.mhd)
526+
itk_add_bigio_test_cleanup(itkLargeMetaImageWriteReadTest2 ${ITK_TEST_OUTPUT_DIR}/LargeImage02.mhd)
527+
itk_add_bigio_test_cleanup(itkLargeMetaImageWriteReadTest3 ${ITK_TEST_OUTPUT_DIR}/LargeImage03.mhd)
522528
endif()
523529

524530
if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
@@ -532,7 +538,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
532538
70000L
533539
)
534540

535-
# Due to the large memory requirements this tests must be run one by one
541+
# Due to the large memory requirements this test must be run serially
536542
set_tests_properties(
537543
itkLargeMetaImageWriteReadTest4
538544
PROPERTIES
@@ -542,6 +548,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
542548
MEMORY_SIZE
543549
COST
544550
30
551+
RUN_SERIAL
552+
True
545553
)
546554
set_property(
547555
TEST
@@ -551,12 +559,5 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
551559
LABELS
552560
RUNS_LONG
553561
)
554-
set_property(
555-
TEST
556-
itkLargeMetaImageWriteReadTest4
557-
APPEND
558-
PROPERTY
559-
RUN_SERIAL
560-
True
561-
)
562+
itk_add_bigio_test_cleanup(itkLargeMetaImageWriteReadTest4 ${ITK_TEST_OUTPUT_DIR}/LargeImage04.mhd)
562563
endif()

Modules/IO/TIFF/test/CMakeLists.txt

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
486486
50000L
487487
)
488488

489-
# Due to the large memory requirements this tests must be run one by one
489+
# Due to the large memory requirements these tests must be run one by one
490490
set_tests_properties(
491491
itkLargeTIFFImageWriteReadTest1
492492
itkLargeTIFFImageWriteReadTest2
@@ -496,6 +496,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
496496
BigIO
497497
RESOURCE_LOCK
498498
MEMORY_SIZE
499+
RUN_SERIAL
500+
True
499501
)
500502
set_property(
501503
TEST
@@ -505,14 +507,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
505507
LABELS
506508
RUNS_LONG
507509
)
508-
set_property(
509-
TEST
510-
itkLargeTIFFImageWriteReadTest1
511-
APPEND
512-
PROPERTY
513-
RUN_SERIAL
514-
True
515-
)
516510
set_property(
517511
TEST
518512
itkLargeTIFFImageWriteReadTest2
@@ -521,14 +515,6 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
521515
LABELS
522516
RUNS_LONG
523517
)
524-
set_property(
525-
TEST
526-
itkLargeTIFFImageWriteReadTest2
527-
APPEND
528-
PROPERTY
529-
RUN_SERIAL
530-
True
531-
)
532518
set_property(
533519
TEST
534520
itkLargeTIFFImageWriteReadTest3
@@ -537,14 +523,10 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 5)
537523
LABELS
538524
RUNS_LONG
539525
)
540-
set_property(
541-
TEST
542-
itkLargeTIFFImageWriteReadTest3
543-
APPEND
544-
PROPERTY
545-
RUN_SERIAL
546-
True
547-
)
526+
# Clean up BigIO output files after successful completion
527+
itk_add_bigio_test_cleanup(itkLargeTIFFImageWriteReadTest1 ${ITK_TEST_OUTPUT_DIR}/LargeImage01.tif)
528+
itk_add_bigio_test_cleanup(itkLargeTIFFImageWriteReadTest2 ${ITK_TEST_OUTPUT_DIR}/LargeImage02.tif)
529+
itk_add_bigio_test_cleanup(itkLargeTIFFImageWriteReadTest3 ${ITK_TEST_OUTPUT_DIR}/LargeImage03.tif)
548530
endif()
549531

550532
if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
@@ -558,7 +540,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
558540
70000L
559541
)
560542

561-
# Due to the large memory requirements this tests must lock the memory size resource
543+
# Due to the large memory requirements this test must be run serially
562544
set_tests_properties(
563545
itkLargeTIFFImageWriteReadTest4
564546
PROPERTIES
@@ -568,6 +550,8 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
568550
MEMORY_SIZE
569551
COST
570552
30
553+
RUN_SERIAL
554+
True
571555
)
572556
set_property(
573557
TEST
@@ -577,14 +561,7 @@ if("${ITK_COMPUTER_MEMORY_SIZE}" GREATER 12)
577561
LABELS
578562
RUNS_LONG
579563
)
580-
set_property(
581-
TEST
582-
itkLargeTIFFImageWriteReadTest4
583-
APPEND
584-
PROPERTY
585-
RUN_SERIAL
586-
True
587-
)
564+
itk_add_bigio_test_cleanup(itkLargeTIFFImageWriteReadTest4 ${ITK_TEST_OUTPUT_DIR}/LargeImage04.tif)
588565
endif()
589566

590567
# expand + RGB image

0 commit comments

Comments
 (0)