Skip to content

Commit

Permalink
[SimCI] Revise tests
Browse files Browse the repository at this point in the history
* standalone AnalysisQC test has been remobved in favor of developments
  in workflow test

* generators
  * do not blindly test all INI files when run_generator_tests.sh changes
  * find files correctly when there are other changed files not related
    to generator testing

* workflows
  revised logic such that
  * if MC/bin changes
    --> run anchored,
    --> check correct creation of workflows implemented by PWGs,
    --> test AnalysisQC and QC
  * if MC/analysis_testing or MC-related QC configurations change
    --> test AnalysisQC and QC,
    --> test O2DPG AnalysisQC CLI
  * if anchored-related shell scripts change
    --> run anchored
  • Loading branch information
Benedikt Volkel committed Mar 1, 2024
1 parent 928d82f commit c42a3d2
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 347 deletions.
34 changes: 33 additions & 1 deletion test/common/utils/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@
# Test utility functionality
#

# a global counter for tests
TEST_COUNTER=0

# Prepare some colored output
SRED="\033[0;31m"
SGREEN="\033[0;32m"
SYELLOW="\033[0;33m"
SEND="\033[0m"

echo_green()
{
echo -e "${SGREEN}${*}${SEND}"
}


echo_red()
{
echo -e "${SRED}${*}${SEND}"
}


echo_yellow()
{
echo -e "${SYELLOW}${*}${SEND}"
}


remove_artifacts()
{
[[ "${KEEP_ONLY_LOGS}" == "1" ]] && find . -type f ! -name '*.log' -and ! -name "*serverlog*" -and ! -name "*mergerlog*" -and ! -name "*workerlog*" -delete
Expand All @@ -25,7 +52,12 @@ get_changed_files()
[[ ! -z "$(git diff)" && -z ${ALIBUILD_HEAD_HASH+x} && -z ${O2DPG_TEST_HASH_HEAD+x} ]] && hash_head=""
# if there are unstaged changes and no base from user, set to HEAD
[[ ! -z "$(git diff)" && -z ${ALIBUILD_HEAD_HASH+x} && -z ${O2DPG_TEST_HASH_BASE+x} ]] && hash_base="HEAD"
git diff --diff-filter=AMR --name-only ${hash_base} ${hash_head}
local paths=$(git diff --diff-filter=AMR --name-only ${hash_base} ${hash_head})
local absolute_paths=
for p in ${paths} ; do
absolute_paths+="$(realpath ${p}) "
done
echo "${absolute_paths}"
}


Expand Down
158 changes: 1 addition & 157 deletions test/run_analysisqc_tests.sh
Original file line number Diff line number Diff line change
@@ -1,160 +1,4 @@
#!/bin/bash

# The test parent dir to be cretaed in current directory
TEST_PARENT_DIR="o2dpg_tests/analysisqc"

# unified names of log files
LOG_FILE="o2dpg-test-analysisqc.log"

# Prepare some colored output
SRED="\033[0;31m"
SGREEN="\033[0;32m"
SEND="\033[0m"


echo_green()
{
echo -e "${SGREEN}${*}${SEND}"
}


echo_red()
{
echo -e "${SRED}${*}${SEND}"
}


get_git_repo_directory()
{
local repo=
if [[ -d .git ]] ; then
pwd
else
repo=$(git rev-parse --git-dir 2> /dev/null)
fi
[[ "${repo}" != "" ]] && repo=${repo%%/.git}
echo ${repo}
}


test_analysisqc()
{
echo "### Testing AnalysisQC creation for MC ###" > ${LOG_FILE}
${O2DPG_ROOT}/MC/analysis_testing/o2dpg_analysis_test_workflow.py -f AO2D.root --is-mc -o wokflow_test_mc.json >> ${LOG_FILE} 2>&1
local ret=${?}
[[ "${ret}" != "0" ]] && echo "[FATAL]: O2DPG_TEST failed" >> ${LOG_FILE}
echo "### Testing AnalysisQC creation for data ###" >> ${LOG_FILE}
${O2DPG_ROOT}/MC/analysis_testing/o2dpg_analysis_test_workflow.py -f AO2D.root -o wokflow_test_data.json >> ${LOG_FILE} 2>&1
local ret_data=${?}
[[ "${ret_data}" != "0" ]] && { echo "[FATAL]: O2DPG_TEST failed" >> ${LOG_FILE} ; ret=${ret_data} ; }
return ${ret}
}


print_usage()
{
echo
echo "usage: run_workflow_tests.sh"
echo
echo " ENVIRONMENT VARIABLES:"
echo
echo " O2DPG_TEST_REPO_DIR : Point to the source repository you want to test."
echo " O2DPG_TEST_HASH_BASE : The base hash you want to use for comparison (optional)"
echo " O2DPG_TEST_HASH_HEAD : The head hash you want to use for comparison (optional)"
echo
echo " If O2DPG_TEST_HASH_BASE is not set, it will be looked for ALIBUILD_BASE_HASH."
echo " If also not set, this will be set to HEAD~1. However, if there are unstaged"
echo " changes, it will be set to HEAD."
echo
echo " If O2DPG_TEST_HASH_HEAD is not set, it will be looked for ALIBUILD_HEAD_HASH."
echo " If also not set, this will be set to HEAD. However, if there are unstaged"
echo " changes, it will left blank."
echo
}

while [ "$1" != "" ] ; do
case $1 in
--help|-h ) print_usage
exit 1
;;
* ) echo "Unknown argument ${1}"
exit 1
;;
esac
done

echo
echo "################################"
echo "# Run O2DPG AnalysisQC testing #"
echo "################################"
echo

REPO_DIR=${O2DPG_TEST_REPO_DIR:-$(get_git_repo_directory)}
if [[ ! -d ${REPO_DIR}/.git ]] ; then
echo_red "Directory \"${REPO_DIR}\" is not a git repository."
exit 1
fi

if [[ -z ${O2DPG_ROOT+x} ]] ; then
echo_red "O2DPG is not loaded, probably other packages are missing as well in this environment."
exit 1
fi

# source the utilities
source ${REPO_DIR}/test/common/utils/utils.sh

# Do the initial steps in the source dir where we have the full git repo
pushd ${REPO_DIR} > /dev/null

# flag if anything changed for AnalysisQC
need_testing=$(get_changed_files | grep "MC/.*analysis_testing")

# go back to where we came from
popd > /dev/null
REPO_DIR=$(realpath ${REPO_DIR})

# Now, do the trick:
# We just use the source dir since O2DPG's installation is basically just a copy of the whole repo.
# This makes sense in particular for local testing but also in the CI it works in the same way. We could do
# [[ -z {ALIBUILD_HEAD_HASH+x} ]] && export O2DPG_ROOT=${REPO_DIR}
# but let's do the same for both local and CI consistently
export O2DPG_ROOT=${REPO_DIR}


###############
# Let's do it #
###############
ret_global=0
# prepare our local test directory for PWG tests
rm -rf ${TEST_PARENT_DIR} 2>/dev/null
mkdir -p ${TEST_PARENT_DIR} 2>/dev/null
pushd ${TEST_PARENT_DIR} > /dev/null

# Test what we found
if [[ "${need_testing}" != "" ]] ; then
test_analysisqc
ret_global=${?}
else
echo "Nothing to test"
exit 0
fi

# return to where we came from
popd > /dev/null

# However, if a central test fails, exit code will be !=0
if [[ "${ret_global}" != "0" ]] ; then
echo
echo "########################"
echo "# ERROR for AnalysisQC #"
echo "########################"
echo
print_error_logs ${TEST_PARENT_DIR}
exit ${ret_global}
fi

echo
echo_green "AnalysisQC tests successful"
echo

# for now, obsolete
exit 0
48 changes: 20 additions & 28 deletions test/run_generator_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,43 +250,40 @@ add_ini_files_from_tests()
done
}

add_ini_files_from_all_tests()
{
# Collect also those INI files for which the test has been changed
local all_tests=$(find ${REPO_DIR} -name "*.C" | grep "MC/.*/ini/tests")
local repo_dir_head=${REPO_DIR}
for t in ${all_tests} ; do
local this_test=$(realpath ${t})
this_test=${this_test##${repo_dir_head}/}
local tc=$(basename ${this_test})
this_test=${this_test%%/tests/*}
tc=${tc%.C}.ini
tc=${this_test}/${tc}
[[ "${INI_FILES}" == *"${tc}"* ]] && continue
INI_FILES+=" ${tc} "
done
}


collect_ini_files()
{
# Collect all INI files which have changed
local ini_files=$(get_changed_files | grep ".ini$" | grep "MC/config")
for ini in ${ini_files} ; do
local changed_files=$(get_changed_files)
for ini in ${changed_files} ; do
[[ "${ini}" != *"MC/config"*".ini" ]] && continue
[[ "${INI_FILES}" == *"${ini}"* ]] && continue || INI_FILES+=" ${ini} "
done

# this relies on INI_FILES and MACRO_FILES_POTENTIALLY_INCLUDED
# collect all INI files that might include some changed macros
add_ini_files_from_macros $(get_changed_files | grep ".C$" | grep "MC/config")
changed_files=$(get_changed_files)
local macros=
for m in ${changed_files} ; do
[[ "${m}" != *"MC/config"*".C" ]] && continue
macros+=" ${m} "
done

add_ini_files_from_macros ${macros}

# this relies on MACRO_FILES_POTENTIALLY_INCLUDED
# collect all INI files that might contain macros which in turn include changed macros
# for now, just go one level deeper, in principal we could do this fully recursively
add_ini_files_from_macros $(find_including_macros)

# also tests might have changed in which case we run them
add_ini_files_from_tests $(get_changed_files | grep ".C$" | grep "MC/.*/ini/tests")
changed_files=$(get_changed_files)
local macros=
for m in ${changed_files} ; do
[[ "${m}" != *"MC/"*"ini/tests"*".C" ]] && continue
macros+=" ${m} "
done
add_ini_files_from_tests ${macros}
}


Expand Down Expand Up @@ -361,12 +358,12 @@ echo

REPO_DIR=${O2DPG_TEST_REPO_DIR:-$(get_git_repo_directory)}
if [[ ! -d ${REPO_DIR}/.git ]] ; then
echo_red "Directory \"${REPO_DIR}\" is not a git repository."
echo "ERROR: Directory \"${REPO_DIR}\" is not a git repository."
exit 1
fi

if [[ -z ${O2DPG_ROOT+x} ]] ; then
echo_red "O2DPG is not loaded, probably other packages are missing as well in this environment."
echo "ERROR: O2DPG is not loaded, probably other packages are missing as well in this environment."
exit 1
fi

Expand All @@ -376,11 +373,6 @@ source ${REPO_DIR}/test/common/utils/utils.sh
# Do the initial steps in the source dir where we have the full git repo
pushd ${REPO_DIR} > /dev/null

# First check, if testing itself has changed. In that case this will add INI files
# for which a test can be found
global_testing_changed=$(get_changed_files | grep -E "common/kine_tests/test_generic_kine.C|run_generator_tests.sh" | grep "^test/")
[[ "${global_testing_changed}" != "" ]] && add_ini_files_from_all_tests

# Then add the ini files that have changed as well. We need to do that so we get information
# about missing tests etc.
collect_ini_files
Expand Down
Loading

0 comments on commit c42a3d2

Please sign in to comment.