From 01e1d05256b924873492e5903402961e9f3362c7 Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Thu, 2 Nov 2023 09:15:38 +0100 Subject: [PATCH] Use the cmake ExternalData module to manage test data (#508) * Use the cmake ExternalData to manage test data * Remove the macro and script to download files --- cmake/podioTest.cmake | 24 --------- tests/CMakeLists.txt | 8 ++- tests/input_files/v00-13-example.root.md5 | 1 + tests/input_files/v00-16-02-example.root.md5 | 1 + tests/input_files/v00-16-02-example.sio.md5 | 1 + .../v00-16-02-example_frame.root.md5 | 1 + .../v00-16-02-example_frame.sio.md5 | 1 + tests/input_files/v00-16-04-example.root.md5 | 1 + tests/input_files/v00-16-04-example.sio.md5 | 1 + .../v00-16-04-example_frame.root.md5 | 1 + .../v00-16-04-example_frame.sio.md5 | 1 + tests/input_files/v00-16-05-example.root.md5 | 1 + tests/input_files/v00-16-05-example.sio.md5 | 1 + .../v00-16-05-example_frame.root.md5 | 1 + .../v00-16-05-example_frame.sio.md5 | 1 + tests/input_files/v00-16-06-example.root.md5 | 1 + tests/input_files/v00-16-06-example.sio.md5 | 1 + .../v00-16-06-example_frame.root.md5 | 1 + .../v00-16-06-example_frame.sio.md5 | 1 + tests/input_files/v00-16-example.root.md5 | 1 + tests/input_files/v00-16-example.sio.md5 | 1 + .../input_files/v00-16-example_frame.root.md5 | 1 + .../input_files/v00-16-example_frame.sio.md5 | 1 + tests/root_io/CMakeLists.txt | 49 +++++++++---------- tests/scripts/get_test_inputs.sh | 23 --------- 25 files changed, 51 insertions(+), 74 deletions(-) create mode 100644 tests/input_files/v00-13-example.root.md5 create mode 100644 tests/input_files/v00-16-02-example.root.md5 create mode 100644 tests/input_files/v00-16-02-example.sio.md5 create mode 100644 tests/input_files/v00-16-02-example_frame.root.md5 create mode 100644 tests/input_files/v00-16-02-example_frame.sio.md5 create mode 100644 tests/input_files/v00-16-04-example.root.md5 create mode 100644 tests/input_files/v00-16-04-example.sio.md5 create mode 100644 tests/input_files/v00-16-04-example_frame.root.md5 create mode 100644 tests/input_files/v00-16-04-example_frame.sio.md5 create mode 100644 tests/input_files/v00-16-05-example.root.md5 create mode 100644 tests/input_files/v00-16-05-example.sio.md5 create mode 100644 tests/input_files/v00-16-05-example_frame.root.md5 create mode 100644 tests/input_files/v00-16-05-example_frame.sio.md5 create mode 100644 tests/input_files/v00-16-06-example.root.md5 create mode 100644 tests/input_files/v00-16-06-example.sio.md5 create mode 100644 tests/input_files/v00-16-06-example_frame.root.md5 create mode 100644 tests/input_files/v00-16-06-example_frame.sio.md5 create mode 100644 tests/input_files/v00-16-example.root.md5 create mode 100644 tests/input_files/v00-16-example.sio.md5 create mode 100644 tests/input_files/v00-16-example_frame.root.md5 create mode 100644 tests/input_files/v00-16-example_frame.sio.md5 delete mode 100644 tests/scripts/get_test_inputs.sh diff --git a/cmake/podioTest.cmake b/cmake/podioTest.cmake index 5230af7a3..fb92ddce7 100644 --- a/cmake/podioTest.cmake +++ b/cmake/podioTest.cmake @@ -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() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b09c6efa6..9a1583f47 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) @@ -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) diff --git a/tests/input_files/v00-13-example.root.md5 b/tests/input_files/v00-13-example.root.md5 new file mode 100644 index 000000000..23d937ff7 --- /dev/null +++ b/tests/input_files/v00-13-example.root.md5 @@ -0,0 +1 @@ +86a33a765483c6e9f0babe798ef5a8c5 diff --git a/tests/input_files/v00-16-02-example.root.md5 b/tests/input_files/v00-16-02-example.root.md5 new file mode 100644 index 000000000..9c7491c84 --- /dev/null +++ b/tests/input_files/v00-16-02-example.root.md5 @@ -0,0 +1 @@ +153ca8cc2f6110076c16319f425e214d diff --git a/tests/input_files/v00-16-02-example.sio.md5 b/tests/input_files/v00-16-02-example.sio.md5 new file mode 100644 index 000000000..5bde6daa1 --- /dev/null +++ b/tests/input_files/v00-16-02-example.sio.md5 @@ -0,0 +1 @@ +2b38723420c408517ab34449efdab8f6 diff --git a/tests/input_files/v00-16-02-example_frame.root.md5 b/tests/input_files/v00-16-02-example_frame.root.md5 new file mode 100644 index 000000000..9ff725c82 --- /dev/null +++ b/tests/input_files/v00-16-02-example_frame.root.md5 @@ -0,0 +1 @@ +44fded47f2b01b168d3aece05a52fd43 diff --git a/tests/input_files/v00-16-02-example_frame.sio.md5 b/tests/input_files/v00-16-02-example_frame.sio.md5 new file mode 100644 index 000000000..8a29ef9d5 --- /dev/null +++ b/tests/input_files/v00-16-02-example_frame.sio.md5 @@ -0,0 +1 @@ +616ca9ed47a64e34840ad8e77f75b8e1 diff --git a/tests/input_files/v00-16-04-example.root.md5 b/tests/input_files/v00-16-04-example.root.md5 new file mode 100644 index 000000000..162b877af --- /dev/null +++ b/tests/input_files/v00-16-04-example.root.md5 @@ -0,0 +1 @@ +3c31525e669e0d278826409f08eba48a diff --git a/tests/input_files/v00-16-04-example.sio.md5 b/tests/input_files/v00-16-04-example.sio.md5 new file mode 100644 index 000000000..784ea3d16 --- /dev/null +++ b/tests/input_files/v00-16-04-example.sio.md5 @@ -0,0 +1 @@ +6a9096303a61e3a09ef99dbf60af4568 diff --git a/tests/input_files/v00-16-04-example_frame.root.md5 b/tests/input_files/v00-16-04-example_frame.root.md5 new file mode 100644 index 000000000..0fb43e947 --- /dev/null +++ b/tests/input_files/v00-16-04-example_frame.root.md5 @@ -0,0 +1 @@ +8bd4fa838c6165a6539be86edc5c31ca diff --git a/tests/input_files/v00-16-04-example_frame.sio.md5 b/tests/input_files/v00-16-04-example_frame.sio.md5 new file mode 100644 index 000000000..eea5e2339 --- /dev/null +++ b/tests/input_files/v00-16-04-example_frame.sio.md5 @@ -0,0 +1 @@ +7f1895b8ee5c6e8030038cf525018274 diff --git a/tests/input_files/v00-16-05-example.root.md5 b/tests/input_files/v00-16-05-example.root.md5 new file mode 100644 index 000000000..0d7473a29 --- /dev/null +++ b/tests/input_files/v00-16-05-example.root.md5 @@ -0,0 +1 @@ +dc6181be4825cd49225e17d655134dba diff --git a/tests/input_files/v00-16-05-example.sio.md5 b/tests/input_files/v00-16-05-example.sio.md5 new file mode 100644 index 000000000..b96e9569a --- /dev/null +++ b/tests/input_files/v00-16-05-example.sio.md5 @@ -0,0 +1 @@ +c308cef481593063212b4f0d763129ec diff --git a/tests/input_files/v00-16-05-example_frame.root.md5 b/tests/input_files/v00-16-05-example_frame.root.md5 new file mode 100644 index 000000000..27f3d1077 --- /dev/null +++ b/tests/input_files/v00-16-05-example_frame.root.md5 @@ -0,0 +1 @@ +4851c2cd392d2dff52d0c0804640a581 diff --git a/tests/input_files/v00-16-05-example_frame.sio.md5 b/tests/input_files/v00-16-05-example_frame.sio.md5 new file mode 100644 index 000000000..9d0aedb51 --- /dev/null +++ b/tests/input_files/v00-16-05-example_frame.sio.md5 @@ -0,0 +1 @@ +d9b999a6184e0e8649a732b049c9109a diff --git a/tests/input_files/v00-16-06-example.root.md5 b/tests/input_files/v00-16-06-example.root.md5 new file mode 100644 index 000000000..df926199f --- /dev/null +++ b/tests/input_files/v00-16-06-example.root.md5 @@ -0,0 +1 @@ +db390543bab1a89f52968516a2648af7 diff --git a/tests/input_files/v00-16-06-example.sio.md5 b/tests/input_files/v00-16-06-example.sio.md5 new file mode 100644 index 000000000..0dc78675b --- /dev/null +++ b/tests/input_files/v00-16-06-example.sio.md5 @@ -0,0 +1 @@ +c74b9634b1fa1305d3813ed23c30cc27 diff --git a/tests/input_files/v00-16-06-example_frame.root.md5 b/tests/input_files/v00-16-06-example_frame.root.md5 new file mode 100644 index 000000000..310c3f7a1 --- /dev/null +++ b/tests/input_files/v00-16-06-example_frame.root.md5 @@ -0,0 +1 @@ +e64e8720a2746ae30c363aa0d4f5935e diff --git a/tests/input_files/v00-16-06-example_frame.sio.md5 b/tests/input_files/v00-16-06-example_frame.sio.md5 new file mode 100644 index 000000000..aea3f2634 --- /dev/null +++ b/tests/input_files/v00-16-06-example_frame.sio.md5 @@ -0,0 +1 @@ +22504d7cd722cde81202c1bdfbe44308 diff --git a/tests/input_files/v00-16-example.root.md5 b/tests/input_files/v00-16-example.root.md5 new file mode 100644 index 000000000..9155b356e --- /dev/null +++ b/tests/input_files/v00-16-example.root.md5 @@ -0,0 +1 @@ +fc47e06f8c42b249dc0fbcbff09ef562 diff --git a/tests/input_files/v00-16-example.sio.md5 b/tests/input_files/v00-16-example.sio.md5 new file mode 100644 index 000000000..a422c9463 --- /dev/null +++ b/tests/input_files/v00-16-example.sio.md5 @@ -0,0 +1 @@ +8146876f0121a8d07fdfd80c2408ed48 diff --git a/tests/input_files/v00-16-example_frame.root.md5 b/tests/input_files/v00-16-example_frame.root.md5 new file mode 100644 index 000000000..daa114f0c --- /dev/null +++ b/tests/input_files/v00-16-example_frame.root.md5 @@ -0,0 +1 @@ +a1065876927fa04f70687ed507dba5a2 diff --git a/tests/input_files/v00-16-example_frame.sio.md5 b/tests/input_files/v00-16-example_frame.sio.md5 new file mode 100644 index 000000000..6fcad659f --- /dev/null +++ b/tests/input_files/v00-16-example_frame.sio.md5 @@ -0,0 +1 @@ +c3a6ef4d13499c4ac5f1249a40d03e9c diff --git a/tests/root_io/CMakeLists.txt b/tests/root_io/CMakeLists.txt index 509749643..598046e3a 100644 --- a/tests/root_io/CMakeLists.txt +++ b/tests/root_io/CMakeLists.txt @@ -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) @@ -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++ diff --git a/tests/scripts/get_test_inputs.sh b/tests/scripts/get_test_inputs.sh deleted file mode 100644 index 523c3d0cc..000000000 --- a/tests/scripts/get_test_inputs.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# Create a temporay folder to get the data to -PODIO_TEST_INPUT_DATA_DIR=$(mktemp -d -p $(pwd) test_input_data_XXXXXXXX) -export PODIO_TEST_INPUT_DATA_DIR - -# Get a legacy file with the oldest version that we still support -cd ${PODIO_TEST_INPUT_DATA_DIR} -mkdir v00-13 && cd v00-13 -wget https://key4hep.web.cern.ch:443/testFiles/podio/v00-13/example.root > /dev/null 2>&1 - -for version in $@; do - cd ${PODIO_TEST_INPUT_DATA_DIR} - mkdir ${version} && cd ${version} - for fileName in example.root example_frame.root; do - wget https://key4hep.web.cern.ch:443/testFiles/podio/${version}/${fileName} > /dev/null 2>&1 - done -done - -# Announce where we store variables to the outside -echo -n ${PODIO_TEST_INPUT_DATA_DIR}