Skip to content

Commit cf41e32

Browse files
benedikt-voelkelBenedikt Volkel
andauthored
[SimCI] Revise tests (#1517)
* 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 * relval * no changes Co-authored-by: Benedikt Volkel <benedikt.volkel@cern.ch>
1 parent 928d82f commit cf41e32

File tree

4 files changed

+207
-347
lines changed

4 files changed

+207
-347
lines changed

test/common/utils/utils.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44
# Test utility functionality
55
#
66

7+
# a global counter for tests
8+
TEST_COUNTER=0
9+
10+
# Prepare some colored output
11+
SRED="\033[0;31m"
12+
SGREEN="\033[0;32m"
13+
SYELLOW="\033[0;33m"
14+
SEND="\033[0m"
15+
16+
echo_green()
17+
{
18+
echo -e "${SGREEN}${*}${SEND}"
19+
}
20+
21+
22+
echo_red()
23+
{
24+
echo -e "${SRED}${*}${SEND}"
25+
}
26+
27+
28+
echo_yellow()
29+
{
30+
echo -e "${SYELLOW}${*}${SEND}"
31+
}
32+
33+
734
remove_artifacts()
835
{
936
[[ "${KEEP_ONLY_LOGS}" == "1" ]] && find . -type f ! -name '*.log' -and ! -name "*serverlog*" -and ! -name "*mergerlog*" -and ! -name "*workerlog*" -delete
@@ -25,7 +52,12 @@ get_changed_files()
2552
[[ ! -z "$(git diff)" && -z ${ALIBUILD_HEAD_HASH+x} && -z ${O2DPG_TEST_HASH_HEAD+x} ]] && hash_head=""
2653
# if there are unstaged changes and no base from user, set to HEAD
2754
[[ ! -z "$(git diff)" && -z ${ALIBUILD_HEAD_HASH+x} && -z ${O2DPG_TEST_HASH_BASE+x} ]] && hash_base="HEAD"
28-
git diff --diff-filter=AMR --name-only ${hash_base} ${hash_head}
55+
local paths=$(git diff --diff-filter=AMR --name-only ${hash_base} ${hash_head})
56+
local absolute_paths=
57+
for p in ${paths} ; do
58+
absolute_paths+="$(realpath ${p}) "
59+
done
60+
echo "${absolute_paths}"
2961
}
3062

3163

test/run_analysisqc_tests.sh

Lines changed: 1 addition & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,4 @@
11
#!/bin/bash
22

3-
# The test parent dir to be cretaed in current directory
4-
TEST_PARENT_DIR="o2dpg_tests/analysisqc"
5-
6-
# unified names of log files
7-
LOG_FILE="o2dpg-test-analysisqc.log"
8-
9-
# Prepare some colored output
10-
SRED="\033[0;31m"
11-
SGREEN="\033[0;32m"
12-
SEND="\033[0m"
13-
14-
15-
echo_green()
16-
{
17-
echo -e "${SGREEN}${*}${SEND}"
18-
}
19-
20-
21-
echo_red()
22-
{
23-
echo -e "${SRED}${*}${SEND}"
24-
}
25-
26-
27-
get_git_repo_directory()
28-
{
29-
local repo=
30-
if [[ -d .git ]] ; then
31-
pwd
32-
else
33-
repo=$(git rev-parse --git-dir 2> /dev/null)
34-
fi
35-
[[ "${repo}" != "" ]] && repo=${repo%%/.git}
36-
echo ${repo}
37-
}
38-
39-
40-
test_analysisqc()
41-
{
42-
echo "### Testing AnalysisQC creation for MC ###" > ${LOG_FILE}
43-
${O2DPG_ROOT}/MC/analysis_testing/o2dpg_analysis_test_workflow.py -f AO2D.root --is-mc -o wokflow_test_mc.json >> ${LOG_FILE} 2>&1
44-
local ret=${?}
45-
[[ "${ret}" != "0" ]] && echo "[FATAL]: O2DPG_TEST failed" >> ${LOG_FILE}
46-
echo "### Testing AnalysisQC creation for data ###" >> ${LOG_FILE}
47-
${O2DPG_ROOT}/MC/analysis_testing/o2dpg_analysis_test_workflow.py -f AO2D.root -o wokflow_test_data.json >> ${LOG_FILE} 2>&1
48-
local ret_data=${?}
49-
[[ "${ret_data}" != "0" ]] && { echo "[FATAL]: O2DPG_TEST failed" >> ${LOG_FILE} ; ret=${ret_data} ; }
50-
return ${ret}
51-
}
52-
53-
54-
print_usage()
55-
{
56-
echo
57-
echo "usage: run_workflow_tests.sh"
58-
echo
59-
echo " ENVIRONMENT VARIABLES:"
60-
echo
61-
echo " O2DPG_TEST_REPO_DIR : Point to the source repository you want to test."
62-
echo " O2DPG_TEST_HASH_BASE : The base hash you want to use for comparison (optional)"
63-
echo " O2DPG_TEST_HASH_HEAD : The head hash you want to use for comparison (optional)"
64-
echo
65-
echo " If O2DPG_TEST_HASH_BASE is not set, it will be looked for ALIBUILD_BASE_HASH."
66-
echo " If also not set, this will be set to HEAD~1. However, if there are unstaged"
67-
echo " changes, it will be set to HEAD."
68-
echo
69-
echo " If O2DPG_TEST_HASH_HEAD is not set, it will be looked for ALIBUILD_HEAD_HASH."
70-
echo " If also not set, this will be set to HEAD. However, if there are unstaged"
71-
echo " changes, it will left blank."
72-
echo
73-
}
74-
75-
while [ "$1" != "" ] ; do
76-
case $1 in
77-
--help|-h ) print_usage
78-
exit 1
79-
;;
80-
* ) echo "Unknown argument ${1}"
81-
exit 1
82-
;;
83-
esac
84-
done
85-
86-
echo
87-
echo "################################"
88-
echo "# Run O2DPG AnalysisQC testing #"
89-
echo "################################"
90-
echo
91-
92-
REPO_DIR=${O2DPG_TEST_REPO_DIR:-$(get_git_repo_directory)}
93-
if [[ ! -d ${REPO_DIR}/.git ]] ; then
94-
echo_red "Directory \"${REPO_DIR}\" is not a git repository."
95-
exit 1
96-
fi
97-
98-
if [[ -z ${O2DPG_ROOT+x} ]] ; then
99-
echo_red "O2DPG is not loaded, probably other packages are missing as well in this environment."
100-
exit 1
101-
fi
102-
103-
# source the utilities
104-
source ${REPO_DIR}/test/common/utils/utils.sh
105-
106-
# Do the initial steps in the source dir where we have the full git repo
107-
pushd ${REPO_DIR} > /dev/null
108-
109-
# flag if anything changed for AnalysisQC
110-
need_testing=$(get_changed_files | grep "MC/.*analysis_testing")
111-
112-
# go back to where we came from
113-
popd > /dev/null
114-
REPO_DIR=$(realpath ${REPO_DIR})
115-
116-
# Now, do the trick:
117-
# We just use the source dir since O2DPG's installation is basically just a copy of the whole repo.
118-
# This makes sense in particular for local testing but also in the CI it works in the same way. We could do
119-
# [[ -z {ALIBUILD_HEAD_HASH+x} ]] && export O2DPG_ROOT=${REPO_DIR}
120-
# but let's do the same for both local and CI consistently
121-
export O2DPG_ROOT=${REPO_DIR}
122-
123-
124-
###############
125-
# Let's do it #
126-
###############
127-
ret_global=0
128-
# prepare our local test directory for PWG tests
129-
rm -rf ${TEST_PARENT_DIR} 2>/dev/null
130-
mkdir -p ${TEST_PARENT_DIR} 2>/dev/null
131-
pushd ${TEST_PARENT_DIR} > /dev/null
132-
133-
# Test what we found
134-
if [[ "${need_testing}" != "" ]] ; then
135-
test_analysisqc
136-
ret_global=${?}
137-
else
138-
echo "Nothing to test"
139-
exit 0
140-
fi
141-
142-
# return to where we came from
143-
popd > /dev/null
144-
145-
# However, if a central test fails, exit code will be !=0
146-
if [[ "${ret_global}" != "0" ]] ; then
147-
echo
148-
echo "########################"
149-
echo "# ERROR for AnalysisQC #"
150-
echo "########################"
151-
echo
152-
print_error_logs ${TEST_PARENT_DIR}
153-
exit ${ret_global}
154-
fi
155-
156-
echo
157-
echo_green "AnalysisQC tests successful"
158-
echo
159-
3+
# for now, obsolete
1604
exit 0

test/run_generator_tests.sh

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -250,43 +250,40 @@ add_ini_files_from_tests()
250250
done
251251
}
252252

253-
add_ini_files_from_all_tests()
254-
{
255-
# Collect also those INI files for which the test has been changed
256-
local all_tests=$(find ${REPO_DIR} -name "*.C" | grep "MC/.*/ini/tests")
257-
local repo_dir_head=${REPO_DIR}
258-
for t in ${all_tests} ; do
259-
local this_test=$(realpath ${t})
260-
this_test=${this_test##${repo_dir_head}/}
261-
local tc=$(basename ${this_test})
262-
this_test=${this_test%%/tests/*}
263-
tc=${tc%.C}.ini
264-
tc=${this_test}/${tc}
265-
[[ "${INI_FILES}" == *"${tc}"* ]] && continue
266-
INI_FILES+=" ${tc} "
267-
done
268-
}
269-
270253

271254
collect_ini_files()
272255
{
273256
# Collect all INI files which have changed
274-
local ini_files=$(get_changed_files | grep ".ini$" | grep "MC/config")
275-
for ini in ${ini_files} ; do
257+
local changed_files=$(get_changed_files)
258+
for ini in ${changed_files} ; do
259+
[[ "${ini}" != *"MC/config"*".ini" ]] && continue
276260
[[ "${INI_FILES}" == *"${ini}"* ]] && continue || INI_FILES+=" ${ini} "
277261
done
278262

279263
# this relies on INI_FILES and MACRO_FILES_POTENTIALLY_INCLUDED
280264
# collect all INI files that might include some changed macros
281-
add_ini_files_from_macros $(get_changed_files | grep ".C$" | grep "MC/config")
265+
changed_files=$(get_changed_files)
266+
local macros=
267+
for m in ${changed_files} ; do
268+
[[ "${m}" != *"MC/config"*".C" ]] && continue
269+
macros+=" ${m} "
270+
done
271+
272+
add_ini_files_from_macros ${macros}
282273

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

288279
# also tests might have changed in which case we run them
289-
add_ini_files_from_tests $(get_changed_files | grep ".C$" | grep "MC/.*/ini/tests")
280+
changed_files=$(get_changed_files)
281+
local macros=
282+
for m in ${changed_files} ; do
283+
[[ "${m}" != *"MC/"*"ini/tests"*".C" ]] && continue
284+
macros+=" ${m} "
285+
done
286+
add_ini_files_from_tests ${macros}
290287
}
291288

292289

@@ -361,12 +358,12 @@ echo
361358

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

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

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

379-
# First check, if testing itself has changed. In that case this will add INI files
380-
# for which a test can be found
381-
global_testing_changed=$(get_changed_files | grep -E "common/kine_tests/test_generic_kine.C|run_generator_tests.sh" | grep "^test/")
382-
[[ "${global_testing_changed}" != "" ]] && add_ini_files_from_all_tests
383-
384376
# Then add the ini files that have changed as well. We need to do that so we get information
385377
# about missing tests etc.
386378
collect_ini_files

0 commit comments

Comments
 (0)