|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Single entrypoint for the O2DPG tests. Runs the generator, workflow and |
| 4 | +# RelVal sub-tests, aggregates their exit codes and prints the collected log. |
| 5 | + |
| 6 | +set -u |
| 7 | + |
| 8 | +SUBTEST_DIR=${O2DPG_TEST_SUBTEST_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)} |
| 9 | + |
| 10 | +ALL_SUBTESTS="generator workflow relval" |
| 11 | + |
| 12 | +print_usage() |
| 13 | +{ |
| 14 | + echo |
| 15 | + echo "usage: run_tests.sh [--fail-immediately] [--keep-artifacts] [SUBTEST...]" |
| 16 | + echo |
| 17 | + echo " SUBTEST : one or more of: ${ALL_SUBTESTS} (default: all)" |
| 18 | + echo |
| 19 | + echo " FLAGS:" |
| 20 | + echo |
| 21 | + echo " --fail-immediately : stop after the first failing sub-test" |
| 22 | + echo " --keep-artifacts : keep simulation artifacts, not just the logs" |
| 23 | + echo |
| 24 | + echo " ENVIRONMENT VARIABLES:" |
| 25 | + echo |
| 26 | + echo " O2DPG_TEST_REPO_DIR : the source repository to test" |
| 27 | + echo " O2DPG_TEST_HASH_BASE : base hash for the changed-file diff (optional)" |
| 28 | + echo " O2DPG_TEST_HASH_HEAD : head hash for the changed-file diff (optional)" |
| 29 | + echo |
| 30 | +} |
| 31 | + |
| 32 | +fail_immediately= |
| 33 | +subtest_args=() |
| 34 | +selected=() |
| 35 | + |
| 36 | +while [ "$#" -gt 0 ] ; do |
| 37 | + case $1 in |
| 38 | + --fail-immediately ) fail_immediately=1 ; subtest_args+=("$1") ; shift ;; |
| 39 | + --keep-artifacts ) subtest_args+=("$1") ; shift ;; |
| 40 | + --help|-h ) print_usage ; exit 1 ;; |
| 41 | + generator|workflow|relval ) selected+=("$1") ; shift ;; |
| 42 | + * ) echo "Unknown argument ${1}" ; print_usage ; exit 1 ;; |
| 43 | + esac |
| 44 | +done |
| 45 | + |
| 46 | +[[ "${#selected[@]}" == "0" ]] && read -r -a selected <<< "${ALL_SUBTESTS}" |
| 47 | + |
| 48 | +# Geant4 dataset variables, if a Geant4 installation is in the environment. |
| 49 | +if [[ -n "${G4INSTALL:-}" ]] ; then |
| 50 | + eval "$("${G4INSTALL}/bin/geant4-config" --datasets | |
| 51 | + sed -e 's/[^ ]* //' -e 's/G4/export G4/' -e 's/DATA /DATA=/')" |
| 52 | +fi |
| 53 | + |
| 54 | +# LHAPDF data, needed by several generator configurations. |
| 55 | +if [[ -z "${LHAPDF_DATA_PATH:-}" && -n "${LHAPDF_ROOT:-}" ]] ; then |
| 56 | + export LHAPDF_DATA_PATH="${LHAPDF_ROOT}/share/LHAPDF:${LHAPDF_PDFSETS_ROOT:-}/share/LHAPDF" |
| 57 | + echo "Set LHAPDF_DATA_PATH to ${LHAPDF_DATA_PATH}" |
| 58 | +fi |
| 59 | + |
| 60 | +ret_global=0 |
| 61 | +for subtest in "${selected[@]}" ; do |
| 62 | + script="${SUBTEST_DIR}/run_${subtest}_tests.sh" |
| 63 | + if [[ ! -x "${script}" ]] ; then |
| 64 | + echo "ERROR: sub-test script ${script} not found or not executable" |
| 65 | + ret_global=1 |
| 66 | + [[ "${fail_immediately}" == "1" ]] && break |
| 67 | + continue |
| 68 | + fi |
| 69 | + echo |
| 70 | + echo "==> START SUBTEST: ${subtest} <==" |
| 71 | + forward=() |
| 72 | + for arg in "${subtest_args[@]:-}" ; do |
| 73 | + [[ -z "${arg}" ]] && continue |
| 74 | + grep -q -- "${arg}" "${script}" && forward+=("${arg}") |
| 75 | + done |
| 76 | + "${script}" "${forward[@]}" |
| 77 | + ret_this=$? |
| 78 | + echo "==> END SUBTEST: ${subtest} (exit ${ret_this}) <==" |
| 79 | + if [[ "${ret_this}" != "0" ]] ; then |
| 80 | + ret_global=${ret_this} |
| 81 | + [[ "${fail_immediately}" == "1" ]] && break |
| 82 | + fi |
| 83 | +done |
| 84 | + |
| 85 | +echo |
| 86 | +if [[ "${ret_global}" != "0" ]] ; then |
| 87 | + echo "error detected in O2DPG tests, see above" |
| 88 | +else |
| 89 | + echo "O2DPG tests passed" |
| 90 | +fi |
| 91 | + |
| 92 | +exit ${ret_global} |
0 commit comments