Skip to content

Commit 66c1a56

Browse files
avargitster
authored andcommitted
test-lib: add GIT_SAN_OPTIONS, inherit [AL]SAN_OPTIONS
Change our ASAN_OPTIONS and LSAN_OPTIONS to set defaults for those variables, rather than punting out entirely if we already have them in the environment. We want to take any user-provided settings over our own, but we can do that by prepending our defaults to the variable. The libsanitizer options parsing has "last option wins" semantics. It's now possible to do e.g.: LSAN_OPTIONS=report_objects=1 ./t0006-date.sh And not have the "report_objects=1" setting overwrite our sensible default of "abort_on_error=1", but by prepending to the list we ensure that: LSAN_OPTIONS=report_objects=1:abort_on_error=0 ./t0006-date.sh Will take the desired "abort_on_error=0" over our default. See b0f4c90 (t: support clang/gcc AddressSanitizer, 2014-12-08) for the original pattern being altered here, and 85b81b3 (test-lib: set LSAN_OPTIONS to abort by default, 2017-09-05) for when LSAN_OPTIONS was added in addition to the then-existing ASAN_OPTIONS. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6ebfd0 commit 66c1a56

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

t/test-lib.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,33 @@ then
3636
fi
3737
GIT_BUILD_DIR="$TEST_DIRECTORY"/..
3838

39+
# Prepend a string to a VAR using an arbitrary ":" delimiter, not
40+
# adding the delimiter if VAR or VALUE is empty. I.e. a generalized:
41+
#
42+
# VAR=$1${VAR:+${1:+$2}$VAR}
43+
#
44+
# Usage (using ":" as the $2 delimiter):
45+
#
46+
# prepend_var VAR : VALUE
47+
prepend_var () {
48+
eval "$1=$3\${$1:+${3:+$2}\$$1}"
49+
}
50+
51+
# If [AL]SAN is in effect we want to abort so that we notice
52+
# problems. The GIT_SAN_OPTIONS variable can be used to set common
53+
# defaults shared between [AL]SAN_OPTIONS.
54+
prepend_var GIT_SAN_OPTIONS : abort_on_error=1
55+
3956
# If we were built with ASAN, it may complain about leaks
4057
# of program-lifetime variables. Disable it by default to lower
4158
# the noise level. This needs to happen at the start of the script,
4259
# before we even do our "did we build git yet" check (since we don't
4360
# want that one to complain to stderr).
44-
: ${ASAN_OPTIONS=detect_leaks=0:abort_on_error=1}
61+
prepend_var ASAN_OPTIONS : $GIT_SAN_OPTIONS
62+
prepend_var ASAN_OPTIONS : detect_leaks=0
4563
export ASAN_OPTIONS
4664

47-
# If LSAN is in effect we _do_ want leak checking, but we still
48-
# want to abort so that we notice the problems.
49-
: ${LSAN_OPTIONS=abort_on_error=1}
65+
prepend_var LSAN_OPTIONS : $GIT_SAN_OPTIONS
5066
export LSAN_OPTIONS
5167

5268
if test ! -f "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS

0 commit comments

Comments
 (0)