Skip to content

Commit

Permalink
Use the cmake ExternalData module to manage test data (#508)
Browse files Browse the repository at this point in the history
* Use the cmake ExternalData to manage test data

* Remove the macro and script to download files
  • Loading branch information
jmcarcell authored Nov 2, 2023
1 parent e44af47 commit 01e1d05
Show file tree
Hide file tree
Showing 25 changed files with 51 additions and 74 deletions.
24 changes: 0 additions & 24 deletions cmake/podioTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,3 @@ function(CREATE_PODIO_TEST sourcefile additional_libs)
target_link_libraries(${name} PRIVATE TestDataModel ExtensionDataModel ${additional_libs})
PODIO_SET_TEST_ENV(${name})
endfunction()

#--- utility macro to facilitate the downloading of legacy input data
macro(PODIO_DOWNLOAD_LEGACY_INPUTS legacy_versions)
# Avoid fetching these everytime cmake is run by caching the directory the first
# time the inputs are fetched or if the expected file does not exist in the
# expected directory
if (NOT DEFINED CACHE{PODIO_TEST_INPUT_DATA_DIR} OR NOT EXISTS ${PODIO_TEST_INPUT_DATA_DIR}/v00-16-05/example_frame.root)
message(STATUS "Getting test input files")
execute_process(
COMMAND bash ${PROJECT_SOURCE_DIR}/tests/scripts/get_test_inputs.sh ${legacy_versions}
OUTPUT_VARIABLE podio_test_input_data_dir
RESULT_VARIABLE test_inputs_available
)
if (NOT "${test_inputs_available}" STREQUAL "0")
message(WARNING "Could not get test input files. Will skip some tests that depend on these")
# Catch cases where the variable is cached but the file no longer exists
unset(PODIO_TEST_INPUT_DATA_DIR CACHE)
else()
message(STATUS "Test inputs stored in: " ${podio_test_input_data_dir})
set(PODIO_TEST_INPUT_DATA_DIR ${podio_test_input_data_dir} CACHE INTERNAL "input dir for test inputs fetched from remote sources")
mark_as_advanced(PODIO_TEST_INPUT_DATA_DIR)
endif()
endif()
endmacro()
8 changes: 6 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ set(legacy_test_versions
v00-16-06
)

### Define the actual tests
PODIO_DOWNLOAD_LEGACY_INPUTS("${legacy_test_versions}")
include(ExternalData)
list(APPEND ExternalData_URL_TEMPLATES
"https://key4hep.web.cern.ch:443/testFiles/podio/%(hash)"
)

add_executable(check_benchmark_outputs check_benchmark_outputs.cpp)
target_link_libraries(check_benchmark_outputs PRIVATE ROOT::Tree)
Expand All @@ -63,3 +65,5 @@ CREATE_PODIO_TEST(write_ascii.cpp "")

# Customize CTest to potentially disable some of the tests with known problems
configure_file(CTestCustom.cmake ${PROJECT_BINARY_DIR}/CTestCustom.cmake @ONLY)

ExternalData_Add_Target(legacy_test_cases)
1 change: 1 addition & 0 deletions tests/input_files/v00-13-example.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
86a33a765483c6e9f0babe798ef5a8c5
1 change: 1 addition & 0 deletions tests/input_files/v00-16-02-example.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
153ca8cc2f6110076c16319f425e214d
1 change: 1 addition & 0 deletions tests/input_files/v00-16-02-example.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2b38723420c408517ab34449efdab8f6
1 change: 1 addition & 0 deletions tests/input_files/v00-16-02-example_frame.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
44fded47f2b01b168d3aece05a52fd43
1 change: 1 addition & 0 deletions tests/input_files/v00-16-02-example_frame.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
616ca9ed47a64e34840ad8e77f75b8e1
1 change: 1 addition & 0 deletions tests/input_files/v00-16-04-example.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3c31525e669e0d278826409f08eba48a
1 change: 1 addition & 0 deletions tests/input_files/v00-16-04-example.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6a9096303a61e3a09ef99dbf60af4568
1 change: 1 addition & 0 deletions tests/input_files/v00-16-04-example_frame.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8bd4fa838c6165a6539be86edc5c31ca
1 change: 1 addition & 0 deletions tests/input_files/v00-16-04-example_frame.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7f1895b8ee5c6e8030038cf525018274
1 change: 1 addition & 0 deletions tests/input_files/v00-16-05-example.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dc6181be4825cd49225e17d655134dba
1 change: 1 addition & 0 deletions tests/input_files/v00-16-05-example.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c308cef481593063212b4f0d763129ec
1 change: 1 addition & 0 deletions tests/input_files/v00-16-05-example_frame.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4851c2cd392d2dff52d0c0804640a581
1 change: 1 addition & 0 deletions tests/input_files/v00-16-05-example_frame.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d9b999a6184e0e8649a732b049c9109a
1 change: 1 addition & 0 deletions tests/input_files/v00-16-06-example.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db390543bab1a89f52968516a2648af7
1 change: 1 addition & 0 deletions tests/input_files/v00-16-06-example.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c74b9634b1fa1305d3813ed23c30cc27
1 change: 1 addition & 0 deletions tests/input_files/v00-16-06-example_frame.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e64e8720a2746ae30c363aa0d4f5935e
1 change: 1 addition & 0 deletions tests/input_files/v00-16-06-example_frame.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22504d7cd722cde81202c1bdfbe44308
1 change: 1 addition & 0 deletions tests/input_files/v00-16-example.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fc47e06f8c42b249dc0fbcbff09ef562
1 change: 1 addition & 0 deletions tests/input_files/v00-16-example.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8146876f0121a8d07fdfd80c2408ed48
1 change: 1 addition & 0 deletions tests/input_files/v00-16-example_frame.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a1065876927fa04f70687ed507dba5a2
1 change: 1 addition & 0 deletions tests/input_files/v00-16-example_frame.sio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c3a6ef4d13499c4ac5f1249a40d03e9c
49 changes: 24 additions & 25 deletions tests/root_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ foreach( sourcefile ${root_dependent_tests} )
endforeach()



#--- set some dependencies between the different tests to ensure input generating ones are run first
set_property(TEST read PROPERTY DEPENDS write)
set_property(TEST read-multiple PROPERTY DEPENDS write)
Expand All @@ -51,34 +50,34 @@ endif()
add_test(NAME check_benchmark_outputs COMMAND check_benchmark_outputs write_benchmark_root.root read_benchmark_root.root)
set_property(TEST check_benchmark_outputs PROPERTY DEPENDS read_timed write_timed)

message(STATUS "Test inputs will be stored in: ${ExternalData_OBJECT_STORES} if they are not already present")
add_executable(read-legacy-files-root read-legacy-files-root.cpp)
target_link_libraries(read-legacy-files-root PRIVATE TestDataModel TestDataModelDict podio::podioRootIO)

# If the variable is cached and defined now, we have inputs and can add the
# legacy file read test
if (DEFINED CACHE{PODIO_TEST_INPUT_DATA_DIR})
message(STATUS "Using test inputs stored in: " ${PODIO_TEST_INPUT_DATA_DIR})
add_executable(read-legacy-files-root read-legacy-files-root.cpp)
target_link_libraries(read-legacy-files-root PRIVATE TestDataModel TestDataModelDict podio::podioRootIO)
# Add a legacy test case based on a base executable and a version for which an
# input file exists
macro(ADD_PODIO_LEGACY_TEST version base_test input_file)
ExternalData_Add_Test(legacy_test_cases
NAME ${base_test}_${version}
COMMAND ${base_test} ${CMAKE_CURRENT_BINARY_DIR}/../input_files/${input_file}
DATA{${PROJECT_SOURCE_DIR}/tests/input_files/${input_file}}
)
set_property(TEST ${base_test}_${version} PROPERTY ENVIRONMENT
LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/tests:${PROJECT_BINARY_DIR}/src:$ENV{LD_LIBRARY_PATH}
# Clear the ROOT_INCLUDE_PATH for the tests, to avoid potential conflicts
# with existing headers from other installations
ROOT_INCLUDE_PATH=
)

# Add a legacy test case based on a base executable and a version for which an
# input file exists
macro(ADD_PODIO_LEGACY_TEST version base_test input_file)
add_test(NAME ${base_test}_${version} COMMAND ${base_test} ${PODIO_TEST_INPUT_DATA_DIR}/${version}/${input_file})
set_property(TEST ${base_test}_${version} PROPERTY ENVIRONMENT
LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/tests:${PROJECT_BINARY_DIR}/src:$ENV{LD_LIBRARY_PATH}
# Clear the ROOT_INCLUDE_PATH for the tests, to avoid potential conflicts
# with existing headers from other installations
ROOT_INCLUDE_PATH=
)
endmacro()
endmacro()

ADD_PODIO_LEGACY_TEST(v00-13 read-legacy-files-root example.root legacy_test_cases)
ADD_PODIO_LEGACY_TEST(v00-13 read-legacy-files-root v00-13-example.root legacy_test_cases)

foreach(version IN LISTS legacy_test_versions)
ADD_PODIO_LEGACY_TEST(${version} read-legacy-files-root example.root legacy_test_cases)
ADD_PODIO_LEGACY_TEST(${version} read_frame_root example_frame.root legacy_test_cases)
ADD_PODIO_LEGACY_TEST(${version} read_frame_legacy_root example.root legacy_test_cases)
endforeach()
endif()
foreach(version IN LISTS legacy_test_versions)
ADD_PODIO_LEGACY_TEST(${version} read-legacy-files-root ${version}-example.root legacy_test_cases)
ADD_PODIO_LEGACY_TEST(${version} read_frame_root ${version}-example_frame.root legacy_test_cases)
ADD_PODIO_LEGACY_TEST(${version} read_frame_legacy_root ${version}-example.root legacy_test_cases)
endforeach()

#--- Write via python and the ROOT backend and see if we can read it back in in
#--- c++
Expand Down
23 changes: 0 additions & 23 deletions tests/scripts/get_test_inputs.sh

This file was deleted.

0 comments on commit 01e1d05

Please sign in to comment.