Skip to content

Commit daaee6b

Browse files
committed
First implementation of parallel testing
1 parent 8b165c5 commit daaee6b

2 files changed

Lines changed: 72 additions & 13 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#---> GeneratorLF_Coalescence.ini
2+
[GeneratorExternal]
3+
fileName = ${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGLF/pythia8/generator_pythia8_coalescence.C
4+
funcName = generateCoalescence({1000010030, 1000020030, 1010010030}, 1, 0.239)
5+
6+
[GeneratorPythia8]
7+
config=${O2_ROOT}/share/Generators/egconfig/pythia8_inel.cfg
8+
9+

test/run_generator_tests.sh

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ TEST_COUNTER=1
4646
# whether or not to delete everything except logs (default is to delete)
4747
KEEP_ONLY_LOGS=1
4848

49+
# Number of workers for parallel test runs
50+
NWORKERS=${NWORKERS:-8}
51+
4952
# Prepare some colored output
5053
SRED="\033[0;31m"
5154
SGREEN="\033[0;32m"
@@ -132,7 +135,7 @@ exec_test()
132135
[[ "${RET}" != "0" ]] && { remove_artifacts ; return ${RET} ; }
133136
# run the simulation, fail if not successful
134137
echo "### Testing base o2-sim executable ###" >> ${LOG_FILE_SIM}
135-
o2-sim -g ${generator_lower} ${trigger} --noGeant -n ${nev} -j 4 --configFile ${ini_path} --configKeyValues "GeneratorPythia8.includePartonEvent=true" >> ${LOG_FILE_SIM} 2>&1
138+
o2-sim -g ${generator_lower} ${trigger} --noGeant -n ${nev} -j 1 --configFile ${ini_path} --configKeyValues "GeneratorPythia8.includePartonEvent=true" >> ${LOG_FILE_SIM} 2>&1
136139
RET=${?}
137140
[[ "${RET}" != "0" ]] && { remove_artifacts ; return ${RET} ; }
138141

@@ -152,6 +155,14 @@ exec_test()
152155
}
153156

154157

158+
wait_for_slot()
159+
{
160+
# Wait until the number of background jobs is less than NWORKERS
161+
while (( $(jobs -r | wc -l) >= NWORKERS )) ; do
162+
sleep 0.1
163+
done
164+
}
165+
155166
check_generators()
156167
{
157168
# check all possible generators incorporated in the INI file
@@ -169,24 +180,31 @@ check_generators()
169180
local look_for=$(grep " ${g}.*\(\)" ${test_script})
170181
local has_trigger="$(grep Trigger${g} ${ini_path})"
171182
[[ -z "${look_for}" ]] && continue
172-
echo -n "Test ${TEST_COUNTER}: ${ini_path} with generator ${g}"
183+
echo "Test ${TEST_COUNTER}: ${ini_path} with generator ${g} - STARTED"
173184
tested_any=1
174185
# prepare the test directory
175186
local test_dir=${TEST_COUNTER}_$(basename ${ini})_${g}_dir
176187
rm -rf ${test_dir} 2> /dev/null
177188
mkdir ${test_dir}
178-
pushd ${test_dir} > /dev/null
179-
# one single test
180-
exec_test ${ini_path} ${g} ${has_trigger}
181-
RET=${?}
182-
popd > /dev/null
183-
if [[ "${RET}" != "0" ]] ; then
184-
echo_red " -> FAILED"
185-
ret_this=${RET}
186-
else
187-
echo_green " -> PASSED"
188-
fi
189+
local test_num=${TEST_COUNTER}
189190
((TEST_COUNTER++))
191+
192+
# Wait for an available slot before starting a new test
193+
wait_for_slot
194+
195+
# Run test in background
196+
(
197+
cd ${test_dir}
198+
exec_test ${ini_path} ${g} ${has_trigger}
199+
exit $?
200+
) &
201+
local pid=$!
202+
203+
# Store test information in global arrays
204+
test_pids+=(${pid})
205+
test_numbers+=(${test_num})
206+
test_generators+=(${g})
207+
test_ini_paths+=("${ini_path}")
190208
fi
191209
done
192210
[[ -z "${tested_any}" ]] && { echo_red "No test scenario was found for any generator. There must be at least one generator to be tested." ; ret_this=1 ; }
@@ -469,6 +487,12 @@ pushd ${TEST_PARENT_DIR} > /dev/null
469487
# global return code to be returned at the end
470488
ret_global=0
471489

490+
# Global arrays to track all test jobs (across all INI files)
491+
declare -a test_pids
492+
declare -a test_numbers
493+
declare -a test_generators
494+
declare -a test_ini_paths
495+
472496
# check each of the INI files
473497
for ini in ${ini_files_full_paths} ; do
474498

@@ -495,6 +519,32 @@ for ini in ${ini_files_full_paths} ; do
495519
[[ "${fail_immediately}" == "1" ]] && break
496520
fi
497521
done
522+
523+
# Wait for all test jobs to complete and collect results
524+
idx=0
525+
for pid in "${test_pids[@]}" ; do
526+
wait ${pid}
527+
RET=$?
528+
test_num="${test_numbers[$idx]}"
529+
generator="${test_generators[$idx]}"
530+
ini_path="${test_ini_paths[$idx]}"
531+
532+
if [[ "${RET}" != "0" ]] ; then
533+
echo_red "Test ${test_num}: ${ini_path} with generator ${generator} -> FAILED"
534+
ret_global=${RET}
535+
if [[ "${fail_immediately}" == "1" ]] ; then
536+
# Kill remaining background jobs
537+
for remaining_pid in "${test_pids[@]}" ; do
538+
kill ${remaining_pid} 2>/dev/null
539+
done
540+
break
541+
fi
542+
else
543+
echo_green "Test ${test_num}: ${ini_path} with generator ${generator} -> PASSED"
544+
fi
545+
((idx++))
546+
done
547+
498548
# return to where we came from
499549
popd > /dev/null
500550

0 commit comments

Comments
 (0)