Skip to content

Commit

Permalink
[wip] Add roundtrip tests for stored EDM definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Dec 22, 2022
1 parent e5f4ed1 commit 8ec13fa
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SIOBlock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ SIOBlockLibraryLoader::SIOBlockLibraryLoader() {
const auto status = loadLib(lib);
switch (status) {
case LoadStatus::Success:
std::cout << "Loaded SIOBlocks library \'" << lib << "\' (from " << dir << ")" << std::endl;
std::cerr << "Loaded SIOBlocks library \'" << lib << "\' (from " << dir << ")" << std::endl;
break;
case LoadStatus::AlreadyLoaded:
std::cerr << "SIOBlocks library \'" << lib << "\' already loaded. Not loading again from " << dir << std::endl;
Expand Down
33 changes: 33 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,36 @@ else()
)
endif()

# Add tests for storing and retrieving the EDM definitions into the produced
# files
add_test(edm_def_store_roundtrip_root ${CMAKE_CURRENT_LIST_DIR}/scripts/dumpModelRoundTrip.sh ${CMAKE_CURRENT_BINARY_DIR}/example_frame.root datamodel)
add_test(edm_def_store_roundtrip_root_extension ${CMAKE_CURRENT_LIST_DIR}/scripts/dumpModelRoundTrip.sh ${CMAKE_CURRENT_BINARY_DIR}/example_frame.root datamodel extension_datamodel)

add_test(edm_def_store_roundtrip_sio ${CMAKE_CURRENT_LIST_DIR}/scripts/dumpModelRoundTrip.sh ${CMAKE_CURRENT_BINARY_DIR}/example_frame.sio datamodel)
add_test(edm_def_store_roundtrip_sio_extension ${CMAKE_CURRENT_LIST_DIR}/scripts/dumpModelRoundTrip.sh ${CMAKE_CURRENT_BINARY_DIR}/example_frame.sio datamodel extension_datamodel)

# Need the input files that are produced by other tests
set_tests_properties(
edm_def_store_roundtrip_root
edm_def_store_roundtrip_root_extension
PROPERTIES
DEPENDS write_frame_root
)
set_tests_properties(
edm_def_store_roundtrip_sio
edm_def_store_roundtrip_sio_extension
PROPERTIES
DEPENDS write_frame_sio
)

set_tests_properties(
edm_def_store_roundtrip_root
edm_def_store_roundtrip_root_extension
edm_def_store_roundtrip_sio
edm_def_store_roundtrip_sio_extension
PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
ENVIRONMENT
"PODIO_BASE=${CMAKE_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_BINARY_DIR}/src:$ENV{LD_LIBRARY_PATH};PYTHONPATH=${CMAKE_SOURCE_DIR}/python:$ENV{PYTHONPATH};ROOT_INCLUDE_PATH=${CMAKE_SOURCE_DIR}/tests/datamodel:${CMAKE_SOURCE_DIR}/include:$ENV{ROOT_INCLUDE_PATH}"

)
36 changes: 36 additions & 0 deletions tests/scripts/dumpModelRoundTrip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Script to check that an EDM definition dumped from a file is "equivalent" to
# the original definition. Essentially does not check that the YAML file is the
# same, but rather that the generated code is the same

set -eu

INPUT_FILE=${1} # the datafile
EDM_NAME=${2} # the name of the EDM
COMP_BASE_FOLDER="" # where the source to compare against is
if [ -$# -gt 2 ]; then
COMP_BASE_FOLDER=${3}
fi

# Create a few temporary but unique files and directories to store output
DUMPED_MODEL=${INPUT_FILE}.dumped_${EDM_NAME}.yaml
OUTPUT_FOLDER=${INPUT_FILE}.dumped_${EDM_NAME}
mkdir -p ${OUTPUT_FOLDER}

# Dump the model to a yaml file
${PODIO_BASE}/tools/podio-dump --dump-edm ${EDM_NAME} ${INPUT_FILE} > ${DUMPED_MODEL}

# Regenerate the code via the class generator and the freshly dumped modl
${PODIO_BASE}/python/podio_class_generator.py \
--clangformat \
${DUMPED_MODEL} \
${OUTPUT_FOLDER} \
${EDM_NAME} \
ROOT SIO

# Compare to the originally generated code, that has been used to write the data
# file. Need to diff subfolders explitly here because $PODIO_BASE/tests contains
# more stuff
diff -ru ${OUTPUT_FOLDER}/${EDM_NAME} ${PODIO_BASE}/tests/${COMP_BASE_FOLDER}/${EDM_NAME}
diff -ru ${OUTPUT_FOLDER}/src ${PODIO_BASE}/tests/${COMP_BASE_FOLDER}/src
diff -u ${OUTPUT_FOLDER}/podio_generated_files.cmake ${PODIO_BASE}/tests/podio_generated_files.cmake

0 comments on commit 8ec13fa

Please sign in to comment.