Skip to content

Commit d0cc579

Browse files
peffgitster
authored andcommitted
test-lib: set ASAN_OPTIONS variable before we run git
We turn off ASan's leak detection by default in the test suite because it's too noisy. But we don't do so until part-way through test-lib. This is before we've run any tests, but after we do our initial "./git" to see if the binary has even been built. When built with clang, this seems to work fine. However, using "gcc -fsanitize=address", the leak checker seems to complain more aggressively: $ ./git ... ==5352==ERROR: LeakSanitizer: detected memory leaks Direct leak of 2 byte(s) in 1 object(s) allocated from: #0 0x7f120e7afcf8 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1cf8) #1 0x559fc2a3ce41 in do_xmalloc /home/peff/compile/git/wrapper.c:60 #2 0x559fc2a3cf1a in do_xmallocz /home/peff/compile/git/wrapper.c:100 #3 0x559fc2a3d0ad in xmallocz /home/peff/compile/git/wrapper.c:108 #4 0x559fc2a3d0ad in xmemdupz /home/peff/compile/git/wrapper.c:124 #5 0x559fc2a3d0ad in xstrndup /home/peff/compile/git/wrapper.c:130 #6 0x559fc274535a in main /home/peff/compile/git/common-main.c:39 #7 0x7f120dabd2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0) This is a leak in the sense that we never free it, but it's in a global that is meant to last the whole program. So it's not really interesting or in need of fixing. And at any rate, mentioning leaks outside of the test_expect blocks is certainly unwelcome, as it pollutes stderr. Let's bump the setting of ASAN_OPTIONS higher in test-lib.sh to catch our initial "can we even run git?" test. While we're at it, we can add a comment to make it a bit less inscrutable. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c8e978 commit d0cc579

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

t/test-lib.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ then
3636
fi
3737
GIT_BUILD_DIR="$TEST_DIRECTORY"/..
3838

39+
# If we were built with ASAN, it may complain about leaks
40+
# of program-lifetime variables. Disable it by default to lower
41+
# the noise level. This needs to happen at the start of the script,
42+
# before we even do our "did we build git yet" check (since we don't
43+
# want that one to complain to stderr).
44+
: ${ASAN_OPTIONS=detect_leaks=0}
45+
export ASAN_OPTIONS
46+
3947
################################################################
4048
# It appears that people try to run tests without building...
4149
"$GIT_BUILD_DIR/git" >/dev/null
@@ -148,9 +156,6 @@ else
148156
}
149157
fi
150158

151-
: ${ASAN_OPTIONS=detect_leaks=0}
152-
export ASAN_OPTIONS
153-
154159
# Protect ourselves from common misconfiguration to export
155160
# CDPATH into the environment
156161
unset CDPATH

0 commit comments

Comments
 (0)