Skip to content

Commit

Permalink
Use ExternalData and remove some scripts for testing (#167)
Browse files Browse the repository at this point in the history
* Use ExternalData and remove some scripts for testing

* Add test files

* Use bash -c

* Make them all executable

* Fix tests

* Remove import sys

* Remove comments

* Fix the clicRec test

* Add missing quotes

* Use path from arguments

---------

Co-authored-by: jmcarcell <[email protected]>
  • Loading branch information
jmcarcell and jmcarcell authored Feb 13, 2024
1 parent c490e39 commit 0735c0d
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 344 deletions.
151 changes: 75 additions & 76 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ gaudi_add_module(GaudiTestAlgorithms
EDM4HEP::edm4hep
)

find_program(K4RUN k4run)

include(ExternalData)
set(ExternalData_URL_TEMPLATES
"https://key4hep.web.cern.ch:443/testFiles/ddsimOutput/%(hash)"
)

# Compile the Marlin test processors into a shared library
find_package(Marlin REQUIRED)
Expand All @@ -35,82 +41,75 @@ add_library(MarlinTestProcessors SHARED src/PseudoRecoProcessor.cc src/TrivialMC
target_link_libraries(MarlinTestProcessors PUBLIC ${Marlin_LIBRARIES})
target_include_directories(MarlinTestProcessors PUBLIC ${Marlin_INCLUDE_DIRS})

# Add test scripts

find_program(BASH_PROGRAM bash)

if (BASH_PROGRAM)
# Test simple processors
add_test( simple_processors ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/simple_processors.sh )

# Test simple_processors2
add_test( simple_processors2 ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/simple_processors2.sh )

# CLICPerformance setup is added as a simple test that will always succeed, on
# which other tests that need it can depend, in order to make concurrent
# running of those more easily possible
add_test( CLICPerformance_setup ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/setup_clic_performance.sh )

# Test clicReconstruction
add_test( clicRec ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicRec.sh )

# Test converter constants
add_test( converter_constants ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/converter_constants.sh )

# Test indicating -1 to go over all events
add_test( all_events_bounds ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/all_events_bounds.sh )
set_tests_properties ( all_events_bounds
PROPERTIES
PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop")

# Test putting more events than available, stopping on last available event gracefully
add_test( over_total_events ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/over_total_events.sh )
set_tests_properties ( over_total_events
PROPERTIES
PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop")

# Test putting more events than available, stopping on last available event gracefully
add_test( same_num_io ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/same_num_io.sh )
set_tests_properties ( same_num_io
PROPERTIES
PASS_REGULAR_EXPRESSION "Input and output have same number of events")

# Test clicReconstruction with EDM4hep input and output
add_test( clicRec_edm4hep_input ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicRec_e4h_input.sh )

# Run clicReconstruction sequence with LCIO input and output, no converters, with inter-event parallelism
add_test( clicRec_lcio_mt ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicRec_lcio_mt.sh )

# Test the GeoSvc and TrackingCellIDEncodingSvc
add_test( clic_geo_test ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicGeoTest.sh )

# Test for checking whether the converters can resolve relations accross
# multiple processors
add_test( global_converter_maps ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/global_converter_maps.sh )

add_test( event_header_conversion ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/event_header.sh )

set_tests_properties (
simple_processors
simple_processors2
clicRec
converter_constants
all_events_bounds
over_total_events
same_num_io
clicRec_lcio_mt
clicRec_edm4hep_input
clic_geo_test
global_converter_maps
event_header_conversion
# Test simple processors
ExternalData_Add_Test( marlinwrapper_tests NAME simple_processors COMMAND ${K4RUN} ${CMAKE_CURRENT_SOURCE_DIR}/gaudi_opts/simple_processors.py --LcioEvent.Files DATA{${PROJECT_SOURCE_DIR}/test/input_files/muons.slcio})

# Test simple_processors2
ExternalData_Add_Test( marlinwrapper_tests NAME simple_processors2 COMMAND ${K4RUN} ${CMAKE_CURRENT_SOURCE_DIR}/gaudi_opts/simple_processors2.py --LcioEvent.Files DATA{${PROJECT_SOURCE_DIR}/test/input_files/testSimulation.slcio})

# CLICPerformance setup is added as a simple test that will always succeed, on
# which other tests that need it can depend, in order to make concurrent
# running of those more easily possible
add_test( CLICPerformance_setup bash -c "test -d CLICPerformance || git clone --depth=1 https://github.com/iLCSoft/CLICPerformance")

# Test clicReconstruction
ExternalData_Add_Test( marlinwrapper_tests NAME clicRec COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicRec.sh DATA{${PROJECT_SOURCE_DIR}/test/input_files/testSimulation.slcio}" )
# Test converter constants
add_test( converter_constants bash -c ${CMAKE_CURRENT_SOURCE_DIR}/scripts/converter_constants.sh )

# Test indicating -1 to go over all events
ExternalData_Add_Test( marlinwrapper_tests NAME all_events_bounds COMMAND ${K4RUN} ${CMAKE_CURRENT_SOURCE_DIR}/gaudi_opts/simple_processors.py --num-events=1 --LcioEvent.Files DATA{${PROJECT_SOURCE_DIR}/test/input_files/muons.slcio})

# Test putting more events than available, stopping on last available event gracefully
ExternalData_Add_Test( marlinwrapper_tests NAME over_total_events COMMAND ${K4RUN} ${CMAKE_CURRENT_SOURCE_DIR}/gaudi_opts/simple_processors.py --num-events=15 --LcioEvent.Files DATA{${PROJECT_SOURCE_DIR}/test/input_files/muons.slcio})
set_tests_properties ( over_total_events
PROPERTIES
PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop")

# Test putting more events than available, stopping on last available event gracefully
add_test( same_num_io bash -c ${CMAKE_CURRENT_SOURCE_DIR}/scripts/same_num_io.sh )
set_tests_properties ( same_num_io
PROPERTIES
PASS_REGULAR_EXPRESSION "Input and output have same number of events")

# Test clicReconstruction with EDM4hep input and output
ExternalData_Add_Test( marlinwrapper_tests NAME clicRec_edm4hep_input COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicRec_e4h_input.sh DATA{${PROJECT_SOURCE_DIR}/test/input_files/ttbar_podio230830_edm4hep_frame.root}")

# Run clicReconstruction sequence with LCIO input and output, no converters, with inter-event parallelism
ExternalData_Add_Test( marlinwrapper_tests NAME clicRec_lcio_mt COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicRec_lcio_mt.sh DATA{${PROJECT_SOURCE_DIR}/test/input_files/testSimulation.slcio}")

# Test the GeoSvc and TrackingCellIDEncodingSvc
add_test( clic_geo_test ${K4RUN} ${CMAKE_CURRENT_SOURCE_DIR}/gaudi_opts/geoTest_cld.py )

# Test for checking whether the converters can resolve relations accross
# multiple processors
ExternalData_Add_Test( marlinwrapper_tests NAME global_converter_maps COMMAND ${K4RUN} ${CMAKE_CURRENT_SOURCE_DIR}/gaudi_opts/test_global_converter_maps.py --EventDataSvc.input DATA{${PROJECT_SOURCE_DIR}/test/input_files/ttbar_podio230830_edm4hep_frame.root})

add_test( event_header_conversion bash -c "k4run ${CMAKE_CURRENT_SOURCE_DIR}/gaudi_opts/createEventHeader.py && anajob test.slcio | grep 'EVENT: 42'" )

ExternalData_Add_Target(marlinwrapper_tests)

set_tests_properties (
simple_processors
simple_processors2
clicRec
converter_constants
all_events_bounds
over_total_events
same_num_io
clicRec_lcio_mt
clicRec_edm4hep_input
clic_geo_test
global_converter_maps
event_header_conversion
PROPERTIES
ENVIRONMENT "TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:$ENV{LD_LIBRARY_PATH};PYTHONPATH=${CMAKE_INSTALL_PREFIX}/python:$ENV{PYTHONPATH};EXAMPLE_DIR=${PROJECT_SOURCE_DIR}/k4MarlinWrapper/examples;MARLIN_DLL=$ENV{MARLIN_DLL}:${CMAKE_CURRENT_BINARY_DIR}/libMarlinTestProcessors.so"
)

set_tests_properties(
clicRec clicRec_lcio_mt clicRec_edm4hep_input
PROPERTIES
ENVIRONMENT "TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:$ENV{LD_LIBRARY_PATH};PYTHONPATH=${CMAKE_INSTALL_PREFIX}/python:$ENV{PYTHONPATH};EXAMPLE_DIR=${PROJECT_SOURCE_DIR}/k4MarlinWrapper/examples;MARLIN_DLL=$ENV{MARLIN_DLL}:${CMAKE_CURRENT_BINARY_DIR}/libMarlinTestProcessors.so"
)
DEPENDS CLICPerformance_setup
)

set_tests_properties(
clicRec clicRec_lcio_mt clicRec_edm4hep_input
PROPERTIES
DEPENDS CLICPerformance_setup
)

endif(BASH_PROGRAM)
4 changes: 2 additions & 2 deletions test/gaudi_opts/simple_processors2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#
import os

from Gaudi.Configuration import *
from Gaudi.Configuration import DEBUG
from Configurables import ApplicationMgr

from Configurables import LcioEvent, EventDataSvc, MarlinProcessorWrapper
algList = []
Expand Down Expand Up @@ -90,7 +91,6 @@
}
algList.append(digiVxd2)

from Configurables import ApplicationMgr
ApplicationMgr( TopAlg = algList,
EvtSel = 'NONE',
EvtMax = 4,
Expand Down
6 changes: 1 addition & 5 deletions test/gaudi_opts/test_global_converter_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
# limitations under the License.
#

import os

from Gaudi.Configuration import *
from Gaudi.Configuration import INFO, DEBUG

from Configurables import (
PodioInput,
Expand All @@ -33,9 +32,6 @@
)

evtsvc = k4DataSvc("EventDataSvc")
evtsvc.input = os.path.join(
"$TEST_DIR/inputFiles/", "ttbar_podio230830_edm4hep_frame.root"
)

podioInput = PodioInput("InputReader")
podioInput.collections = ["MCParticles"]
Expand Down
1 change: 1 addition & 0 deletions test/input_files/muons.slcio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b2c1b2bdd37882c7232404e3b12c740d
1 change: 1 addition & 0 deletions test/input_files/testSimulation.slcio.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
44dd47683d708b090a9e7bb9eea1be2c
1 change: 1 addition & 0 deletions test/input_files/ttbar_podio230830_edm4hep_frame.root.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b1100c5d6e20766216bc47cda9786dbe
31 changes: 0 additions & 31 deletions test/scripts/all_events_bounds.sh

This file was deleted.

24 changes: 0 additions & 24 deletions test/scripts/clicGeoTest.sh

This file was deleted.

12 changes: 1 addition & 11 deletions test/scripts/clicRec.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,18 @@
# exit if command or variable fails
set -eu

# Clone CLICPerformance for input files
bash $TEST_DIR/scripts/setup_clic_performance.sh

cd CLICPerformance/clicConfig

python \
$TEST_DIR/../k4MarlinWrapper/scripts/convertMarlinSteeringToGaudi.py \
clicReconstruction.xml \
clicReconstruction.py

# Generate slcio file if not present
if [ ! -f $TEST_DIR/inputFiles/testSimulation.slcio ]; then
echo "Input file not found. Getting it from key4hep..."
wget https://key4hep.web.cern.ch/testFiles/ddsimOutput/testSimulation.slcio -P $TEST_DIR/inputFiles/
fi


echo "Modifying clicReconstruction.py file..."
# Replace SLCIO file path
# sed -i 's|/run/simulation/with/ctest/to/create/a/file.slcio|testSimulation.slcio|g' clicReconstruction.py
sed -i '1s/^/import os\n/' clicReconstruction.py
sed -i 's|/run/simulation/with/ctest/to/create/a/file.slcio|$TEST_DIR/inputFiles/testSimulation.slcio|g' clicReconstruction.py
sed -i "s|/run/simulation/with/ctest/to/create/a/file.slcio|$1|g" clicReconstruction.py
# Uncomment selected optional processors
sed -i 's;EvtMax = 10,;EvtMax = 3,;' clicReconstruction.py
sed -i 's;"MaxRecordNumber": ["10"],;"MaxRecordNumber": ["3"],;' clicReconstruction.py
Expand Down
15 changes: 2 additions & 13 deletions test/scripts/clicRec_e4h_input.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,11 @@
# exit if command or variable fails
set -eu

# Clone CLICPerformance for input files
bash $TEST_DIR/scripts/setup_clic_performance.sh

cd CLICPerformance/clicConfig

export INPUTFILE=ttbar_podio230830_edm4hep_frame.root

# Download root file if not present
if [ ! -f $TEST_DIR/inputFiles/$INPUTFILE ]; then
echo "Input file not found. Getting it from key4hep..."
wget https://key4hep.web.cern.ch/testFiles/ddsimOutput/$INPUTFILE -P $TEST_DIR/inputFiles/
fi

k4run $EXAMPLE_DIR/clicRec_e4h_input.py
k4run $EXAMPLE_DIR/clicRec_e4h_input.py --EventDataSvc.input=$1

input_num_events=$(python $TEST_DIR/python/root_num_events.py $TEST_DIR/inputFiles/$INPUTFILE)
input_num_events=$(python $TEST_DIR/python/root_num_events.py $1)
output_num_events=$(python $TEST_DIR/python/root_num_events.py my_output.root)

# First check do we have the same number of events in input and output
Expand Down
13 changes: 2 additions & 11 deletions test/scripts/clicRec_lcio_mt.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,15 @@
# exit if command or variable fails
set -eu

# Clone CLICPerformance for input files
bash $TEST_DIR/scripts/setup_clic_performance.sh

cd CLICPerformance/clicConfig

# Generate slcio file if not present
if [ ! -f $TEST_DIR/inputFiles/testSimulation.slcio ]; then
echo "Input file not found. Getting it from key4hep..."
wget https://key4hep.web.cern.ch/testFiles/ddsimOutput/testSimulation.slcio -P $TEST_DIR/inputFiles/
fi

if [ ! -f clicReconstruction_mt.py ]; then
ln -s $TEST_DIR/gaudi_opts/clicReconstruction_mt.py clicReconstruction_mt.py
fi

k4run clicReconstruction_mt.py
k4run clicReconstruction_mt.py --LcioEvent.Files $1

input_num_events=$(lcio_event_counter $TEST_DIR/inputFiles/testSimulation.slcio)
input_num_events=$(lcio_event_counter $1)
output_num_events=$(lcio_event_counter Output_REC_mt_lcio.slcio)

echo $input_num_events
Expand Down
Empty file modified test/scripts/converter_constants.sh
100644 → 100755
Empty file.
24 changes: 0 additions & 24 deletions test/scripts/event_header.sh

This file was deleted.

Loading

0 comments on commit 0735c0d

Please sign in to comment.