77# git clone http://github.com/gemc/src /root/src && cd /root/src
88# ./ci/build.sh
99
10+ # Load environment variables: log file paths, job count, helper functions.
1011source ci/env.sh
12+
13+ # Resolve meson setup flags from the optional sanitizer argument ($1).
1114meson_option=$( meson_setup_options $1 )
1215
16+ # Print build environment summary (compiler paths, options, core count).
1317{
1418 echo " > Geant-config: $( command -v geant4-config) : $( geant4-config --version) "
1519 echo " > Root-config: $( command -v root-config) : $( root-config --version) "
@@ -21,6 +25,7 @@ meson_option=$(meson_setup_options $1)
2125} | tee -a " $setup_log "
2226
2327
28+ # Remove any previous install directory, then configure the build tree.
2429{
2530 echo
2631 rm -rf $GEMC
4045fi
4146
4247
48+ # Compile all targets using all available cores.
4349echo " > Running meson compile -C build -v -j $jobs " | tee -a $compile_log
4450meson compile -C build -v -j $jobs >> $compile_log
4551if [ $? -ne 0 ]; then
5157 echo
5258fi
5359
60+ # Install built artifacts to the configured prefix.
5461echo " > Running meson install -C build " | tee -a $install_log
5562meson install -C build >> $install_log
5663if [ $? -ne 0 ]; then
6269 echo
6370fi
6471
72+ # Print a summary of the installed gemc files and version.
6573show_gemc_installation
6674
75+ # Base options shared by all meson test invocations.
6776test_options=(
6877 -C build
6978 --print-errorlogs
@@ -72,7 +81,7 @@ test_options=(
7281 --num-processes 1
7382)
7483
75- # Specific tests to run when sanitizer is enabled
84+ # Subset of tests run when a sanitizer is active (keeps the suite fast and focused).
7685sanitizer_tests=(
7786 -v
7887 test_generator_lund_file_events
@@ -81,35 +90,15 @@ sanitizer_tests=(
8190 examples_geo_basic_simple_flux_ascii_variation_default
8291)
8392
93+ # Tests that need the CSV plugin preloaded to work under UBSan.
8494undefined_preload_tests=(
8595 test_gstreamer_csv_verbose
8696)
8797
88- function run_meson_test_with_retry {
89- local label=" $1 "
90- shift
91-
92- for attempt in 1 2; do
93- echo " > Running ${label} (attempt ${attempt} /2):" " $@ " | tee -a " $test_log "
94- " $@ " >> " $test_log "
95- local exit_code=$?
96-
97- if [ $exit_code -eq 0 ]; then
98- return 0
99- fi
100-
101- if [ $attempt -eq 2 ]; then
102- return $exit_code
103- fi
104-
105- echo " > ${label} failed; retrying once" | tee -a " $test_log "
106- done
107- }
108-
109-
98+ # Start with the base test options; append sanitizer-specific or verbose flag below.
11099meson_args=( " ${test_options[@]} " )
111100
112- # if $1 is NOT one of sanitize option, run meson test
101+ # When a sanitizer is active run only the targeted subset; otherwise run all tests verbosely.
113102case " $1 " in
114103 address|thread|undefined|leak)
115104 meson_args+=( " ${sanitizer_tests[@]} " )
@@ -119,8 +108,9 @@ case "$1" in
119108 ;;
120109esac
121110
122- : > " $test_log "
123- if ! run_meson_test_with_retry " meson test" meson test " ${meson_args[@]} " ; then
111+ # Clear (or create) the test log before the first test run.
112+ > " $test_log "
113+ if ! run_command_with_retry " meson test" meson test " ${meson_args[@]} " ; then
124114 echo " > Meson Tests failed. Log: "
125115 cat $test_log
126116 exit 1
@@ -129,12 +119,13 @@ else
129119 echo
130120fi
131121
122+ # Under UBSan, preload the CSV plugin to avoid static-TLS exhaustion at dlopen time.
132123if [ " $1 " = " undefined" ]; then
133124 gstreamer_csv_plugin=" $PWD /build/gstreamer_csv_plugin.gplugin"
134125 # UBSan on Linux can exhaust static TLS before GEMC's runtime dlopen() loads
135126 # this plugin. Preloading it makes the dynamic loader reserve TLS at process
136127 # startup while keeping the workaround scoped to the affected sanitizer test.
137- if ! run_meson_test_with_retry " undefined sanitizer preload tests" \
128+ if ! run_command_with_retry " undefined sanitizer preload tests" \
138129 env LD_PRELOAD=" $gstreamer_csv_plugin " meson test " ${test_options[@]} " -v " ${undefined_preload_tests[@]} " ; then
139130 echo " > Meson Tests failed. Log: "
140131 cat $test_log
@@ -145,6 +136,7 @@ if [ "$1" = "undefined" ]; then
145136 fi
146137fi
147138
139+ # Print a pass/fail summary parsed from the accumulated test log.
148140echo " - Successful: $( grep ' Ok:' " $test_log " | awk ' {sum += $2} END {print sum + 0}' ) " | tee -a " $test_log "
149141echo " - Failures: $( grep ' Fail:' " $test_log " | awk ' {sum += $2} END {print sum + 0}' ) " | tee -a " $test_log "
150142echo " > Complete test log: $test_log "
0 commit comments