Skip to content

Commit 95c679a

Browse files
peffgitster
authored andcommitted
test-lib: stop showing old leak logs
We ask LSan to record the logs of all leaks in test-results/, which is useful for finding leaks that didn't trigger a test failure. We don't clean out the leak/ directory for each test before running it, though. Instead, we count the number of files it has, and complain only if we ended up with more when the script finishes. So we shouldn't trigger any output if you've made a script leak free. But if you simply _reduced_ the number of leaks, then there is an annoying outcome: we do not record which logs were from this run and which were from previous ones. So when we dump them to stdout, you get a mess of possibly-outdated leaks. This is very confusing when you are in an edit-compile-test cycle trying to fix leaks. The instructions do note that you should "rm -rf test-results/" if you want to avoid this. But I'm having trouble seeing how this cumulative count could ever be useful. It is not even counting the number of leaks, but rather the number of processes with at least one leak! So let's just blow away the per-test leak/ directory before running. We already overwrite the ".out" file in test-results/ in the same way, so this is following that pattern. Running "make test" isn't affected by this, since it blows away all of test-results/ already. This only comes up when you are iterating on a single script that you're running manually. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6258f68 commit 95c679a

File tree

1 file changed

+2
-33
lines changed

1 file changed

+2
-33
lines changed

t/test-lib.sh

Lines changed: 2 additions & 33 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
@@ -1215,42 +1214,15 @@ test_atexit_handler () {
12151214
teardown_malloc_check
12161215
}
12171216

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"
1232-
}
1233-
12341217
check_test_results_san_file_ () {
12351218
if test -z "$TEST_RESULTS_SAN_FILE"
12361219
then
12371220
return
12381221
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
1222+
if test "$(nr_san_dir_leaks_)" = 0
12431223
then
12441224
return
12451225
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 &&
12541226
say_color error "$(cat "$TEST_RESULTS_SAN_FILE".*)" &&
12551227

12561228
if test -n "$passes_sanitize_leak" && test "$test_failure" = 0
@@ -1586,16 +1558,13 @@ then
15861558
test_done
15871559
fi
15881560

1561+
rm -rf "$TEST_RESULTS_SAN_DIR"
15891562
if ! mkdir -p "$TEST_RESULTS_SAN_DIR"
15901563
then
15911564
BAIL_OUT "cannot create $TEST_RESULTS_SAN_DIR"
15921565
fi &&
15931566
TEST_RESULTS_SAN_FILE="$TEST_RESULTS_SAN_DIR/$TEST_RESULTS_SAN_FILE_PFX"
15941567

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-
15991568
# Don't litter *.leak dirs if there was nothing to report
16001569
test_atexit "rmdir \"$TEST_RESULTS_SAN_DIR\" 2>/dev/null || :"
16011570

0 commit comments

Comments
 (0)