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
This commit is contained in:
Junio C Hamano 2024-10-04 10:14:06 -07:00
commit 441e0df980
2 changed files with 8 additions and 36 deletions

View File

@ -926,7 +926,8 @@ test_expect_success () {
test_body_or_stdin test_body "$2" test_body_or_stdin test_body "$2"
test -n "$test_skip_test_preamble" || test -n "$test_skip_test_preamble" ||
say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body" say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body"
if test_run_ "$test_body" if test_run_ "$test_body" &&
check_test_results_san_file_empty_
then then
test_ok_ "$1" test_ok_ "$1"
else else

View File

@ -322,7 +322,6 @@ TEST_RESULTS_SAN_FILE_PFX=trace
TEST_RESULTS_SAN_DIR_SFX=leak TEST_RESULTS_SAN_DIR_SFX=leak
TEST_RESULTS_SAN_FILE= TEST_RESULTS_SAN_FILE=
TEST_RESULTS_SAN_DIR="$TEST_RESULTS_DIR/$TEST_NAME.$TEST_RESULTS_SAN_DIR_SFX" TEST_RESULTS_SAN_DIR="$TEST_RESULTS_DIR/$TEST_NAME.$TEST_RESULTS_SAN_DIR_SFX"
TEST_RESULTS_SAN_DIR_NR_LEAKS_STARTUP=
TRASH_DIRECTORY="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX" TRASH_DIRECTORY="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX"
test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
case "$TRASH_DIRECTORY" in case "$TRASH_DIRECTORY" in
@ -848,6 +847,7 @@ test_failure_ () {
GIT_EXIT_OK=t GIT_EXIT_OK=t
exit 0 exit 0
fi fi
check_test_results_san_file_ "$test_failure"
_error_exit _error_exit
fi fi
finalize_test_case_output failure "$failure_label" "$@" finalize_test_case_output failure "$failure_label" "$@"
@ -1215,42 +1215,16 @@ test_atexit_handler () {
teardown_malloc_check teardown_malloc_check
} }
sanitize_leak_log_message_ () { check_test_results_san_file_empty_ () {
local new="$1" && test -z "$TEST_RESULTS_SAN_FILE" ||
local old="$2" && test "$(nr_san_dir_leaks_)" = 0
local file="$3" &&
printf "With SANITIZE=leak at exit we have %d leak logs, but started with %d
This means that we have a blindspot where git is leaking but we're
losing the exit code somewhere, or not propagating it appropriately
upwards!
See the logs at \"%s.*\";
those logs are reproduced below." \
"$new" "$old" "$file"
} }
check_test_results_san_file_ () { check_test_results_san_file_ () {
if test -z "$TEST_RESULTS_SAN_FILE" if check_test_results_san_file_empty_
then then
return return
fi && fi &&
local old="$TEST_RESULTS_SAN_DIR_NR_LEAKS_STARTUP" &&
local new="$(nr_san_dir_leaks_)" &&
if test $new -le $old
then
return
fi &&
local out="$(sanitize_leak_log_message_ "$new" "$old" "$TEST_RESULTS_SAN_FILE")" &&
say_color error "$out" &&
if test "$old" != 0
then
echo &&
say_color error "The logs include output from past runs to avoid" &&
say_color error "that remove 'test-results' between runs."
fi &&
say_color error "$(cat "$TEST_RESULTS_SAN_FILE".*)" && say_color error "$(cat "$TEST_RESULTS_SAN_FILE".*)" &&
if test -n "$passes_sanitize_leak" && test "$test_failure" = 0 if test -n "$passes_sanitize_leak" && test "$test_failure" = 0
@ -1586,16 +1560,13 @@ then
test_done test_done
fi fi
rm -rf "$TEST_RESULTS_SAN_DIR"
if ! mkdir -p "$TEST_RESULTS_SAN_DIR" if ! mkdir -p "$TEST_RESULTS_SAN_DIR"
then then
BAIL_OUT "cannot create $TEST_RESULTS_SAN_DIR" BAIL_OUT "cannot create $TEST_RESULTS_SAN_DIR"
fi && fi &&
TEST_RESULTS_SAN_FILE="$TEST_RESULTS_SAN_DIR/$TEST_RESULTS_SAN_FILE_PFX" TEST_RESULTS_SAN_FILE="$TEST_RESULTS_SAN_DIR/$TEST_RESULTS_SAN_FILE_PFX"
# In case "test-results" is left over from a previous
# run: Only report if new leaks show up.
TEST_RESULTS_SAN_DIR_NR_LEAKS_STARTUP=$(nr_san_dir_leaks_)
# Don't litter *.leak dirs if there was nothing to report # Don't litter *.leak dirs if there was nothing to report
test_atexit "rmdir \"$TEST_RESULTS_SAN_DIR\" 2>/dev/null || :" test_atexit "rmdir \"$TEST_RESULTS_SAN_DIR\" 2>/dev/null || :"