Skip to content

Commit 441e0df

Browse files
committed
Merge branch 'jk/test-lsan-improvements'
Usability improvements for running tests in leak-checking mode. * jk/test-lsan-improvements: test-lib: check for leak logs after every test test-lib: show leak-sanitizer logs on --immediate failure test-lib: stop showing old leak logs
2 parents 111e864 + cf14643 commit 441e0df

File tree

2 files changed

+8
-36
lines changed

2 files changed

+8
-36
lines changed

t/test-lib-functions.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,8 @@ test_expect_success () {
926926
test_body_or_stdin test_body "$2"
927927
test -n "$test_skip_test_preamble" ||
928928
say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body"
929-
if test_run_ "$test_body"
929+
if test_run_ "$test_body" &&
930+
check_test_results_san_file_empty_
930931
then
931932
test_ok_ "$1"
932933
else

t/test-lib.sh

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ TEST_RESULTS_SAN_FILE_PFX=trace
322322
TEST_RESULTS_SAN_DIR_SFX=leak
323323
TEST_RESULTS_SAN_FILE=
324324
TEST_RESULTS_SAN_DIR="$TEST_RESULTS_DIR/$TEST_NAME.$TEST_RESULTS_SAN_DIR_SFX"
325-
TEST_RESULTS_SAN_DIR_NR_LEAKS_STARTUP=
326325
TRASH_DIRECTORY="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX"
327326
test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
328327
case "$TRASH_DIRECTORY" in
@@ -848,6 +847,7 @@ test_failure_ () {
848847
GIT_EXIT_OK=t
849848
exit 0
850849
fi
850+
check_test_results_san_file_ "$test_failure"
851851
_error_exit
852852
fi
853853
finalize_test_case_output failure "$failure_label" "$@"
@@ -1215,42 +1215,16 @@ test_atexit_handler () {
12151215
teardown_malloc_check
12161216
}
12171217

1218-
sanitize_leak_log_message_ () {
1219-
local new="$1" &&
1220-
local old="$2" &&
1221-
local file="$3" &&
1222-
1223-
printf "With SANITIZE=leak at exit we have %d leak logs, but started with %d
1224-
1225-
This means that we have a blindspot where git is leaking but we're
1226-
losing the exit code somewhere, or not propagating it appropriately
1227-
upwards!
1228-
1229-
See the logs at \"%s.*\";
1230-
those logs are reproduced below." \
1231-
"$new" "$old" "$file"
1218+
check_test_results_san_file_empty_ () {
1219+
test -z "$TEST_RESULTS_SAN_FILE" ||
1220+
test "$(nr_san_dir_leaks_)" = 0
12321221
}
12331222

12341223
check_test_results_san_file_ () {
1235-
if test -z "$TEST_RESULTS_SAN_FILE"
1224+
if check_test_results_san_file_empty_
12361225
then
12371226
return
12381227
fi &&
1239-
local old="$TEST_RESULTS_SAN_DIR_NR_LEAKS_STARTUP" &&
1240-
local new="$(nr_san_dir_leaks_)" &&
1241-
1242-
if test $new -le $old
1243-
then
1244-
return
1245-
fi &&
1246-
local out="$(sanitize_leak_log_message_ "$new" "$old" "$TEST_RESULTS_SAN_FILE")" &&
1247-
say_color error "$out" &&
1248-
if test "$old" != 0
1249-
then
1250-
echo &&
1251-
say_color error "The logs include output from past runs to avoid" &&
1252-
say_color error "that remove 'test-results' between runs."
1253-
fi &&
12541228
say_color error "$(cat "$TEST_RESULTS_SAN_FILE".*)" &&
12551229

12561230
if test -n "$passes_sanitize_leak" && test "$test_failure" = 0
@@ -1586,16 +1560,13 @@ then
15861560
test_done
15871561
fi
15881562

1563+
rm -rf "$TEST_RESULTS_SAN_DIR"
15891564
if ! mkdir -p "$TEST_RESULTS_SAN_DIR"
15901565
then
15911566
BAIL_OUT "cannot create $TEST_RESULTS_SAN_DIR"
15921567
fi &&
15931568
TEST_RESULTS_SAN_FILE="$TEST_RESULTS_SAN_DIR/$TEST_RESULTS_SAN_FILE_PFX"
15941569

1595-
# In case "test-results" is left over from a previous
1596-
# run: Only report if new leaks show up.
1597-
TEST_RESULTS_SAN_DIR_NR_LEAKS_STARTUP=$(nr_san_dir_leaks_)
1598-
15991570
# Don't litter *.leak dirs if there was nothing to report
16001571
test_atexit "rmdir \"$TEST_RESULTS_SAN_DIR\" 2>/dev/null || :"
16011572

0 commit comments

Comments
 (0)