Skip to content

Commit a281069

Browse files
committed
Merge branch 'ab/test-leak-diag'
Random test-framework clean-up. * ab/test-leak-diag: test-lib: add "fast_unwind_on_malloc=0" to LSAN_OPTIONS test-lib: make $GIT_BUILD_DIR an absolute path test-lib: correct and assert TEST_DIRECTORY overriding test-lib: add GIT_SAN_OPTIONS, inherit [AL]SAN_OPTIONS
2 parents 6878ea6 + 71f2679 commit a281069

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

t/test-lib.sh

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@
1919
# t/ subdirectory and are run in 'trash directory' subdirectory.
2020
if test -z "$TEST_DIRECTORY"
2121
then
22-
# We allow tests to override this, in case they want to run tests
23-
# outside of t/, e.g. for running tests on the test library
24-
# itself.
25-
TEST_DIRECTORY=$(pwd)
26-
else
2722
# ensure that TEST_DIRECTORY is an absolute path so that it
2823
# is valid even if the current working directory is changed
24+
TEST_DIRECTORY=$(pwd)
25+
else
26+
# The TEST_DIRECTORY will always be the path to the "t"
27+
# directory in the git.git checkout. This is overridden by
28+
# e.g. t/lib-subtest.sh, but only because its $(pwd) is
29+
# different. Those tests still set "$TEST_DIRECTORY" to the
30+
# same path.
31+
#
32+
# See use of "$GIT_BUILD_DIR" and "$TEST_DIRECTORY" below for
33+
# hard assumptions about "$GIT_BUILD_DIR/t" existing and being
34+
# the "$TEST_DIRECTORY", and e.g. "$TEST_DIRECTORY/helper"
35+
# needing to exist.
2936
TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
3037
fi
3138
if test -z "$TEST_OUTPUT_DIRECTORY"
@@ -34,19 +41,42 @@ then
3441
# elsewhere
3542
TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
3643
fi
37-
GIT_BUILD_DIR="$TEST_DIRECTORY"/..
44+
GIT_BUILD_DIR="${TEST_DIRECTORY%/t}"
45+
if test "$TEST_DIRECTORY" = "$GIT_BUILD_DIR"
46+
then
47+
echo "PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?" >&2
48+
exit 1
49+
fi
50+
51+
# Prepend a string to a VAR using an arbitrary ":" delimiter, not
52+
# adding the delimiter if VAR or VALUE is empty. I.e. a generalized:
53+
#
54+
# VAR=$1${VAR:+${1:+$2}$VAR}
55+
#
56+
# Usage (using ":" as the $2 delimiter):
57+
#
58+
# prepend_var VAR : VALUE
59+
prepend_var () {
60+
eval "$1=$3\${$1:+${3:+$2}\$$1}"
61+
}
62+
63+
# If [AL]SAN is in effect we want to abort so that we notice
64+
# problems. The GIT_SAN_OPTIONS variable can be used to set common
65+
# defaults shared between [AL]SAN_OPTIONS.
66+
prepend_var GIT_SAN_OPTIONS : abort_on_error=1
67+
prepend_var GIT_SAN_OPTIONS : strip_path_prefix=\"$GIT_BUILD_DIR/\"
3868

3969
# If we were built with ASAN, it may complain about leaks
4070
# of program-lifetime variables. Disable it by default to lower
4171
# the noise level. This needs to happen at the start of the script,
4272
# before we even do our "did we build git yet" check (since we don't
4373
# want that one to complain to stderr).
44-
: ${ASAN_OPTIONS=detect_leaks=0:abort_on_error=1}
74+
prepend_var ASAN_OPTIONS : $GIT_SAN_OPTIONS
75+
prepend_var ASAN_OPTIONS : detect_leaks=0
4576
export ASAN_OPTIONS
4677

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}
78+
prepend_var LSAN_OPTIONS : $GIT_SAN_OPTIONS
79+
prepend_var LSAN_OPTIONS : fast_unwind_on_malloc=0
5080
export LSAN_OPTIONS
5181

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

0 commit comments

Comments
 (0)