git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] test-lib: stop showing old leak logs

From
Jeff King <peff@peff.net>
Date
Sep 24, 2024, 21:35 UTC
Message-ID
<20240924213540.GA1142403@coredump.intra.peff.net>
In-Reply-To
<20240924213404.GA1142219@coredump.intra.peff.net>

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 <peff@peff.net>
---
 t/test-lib.sh | 35 ++---------------------------------
 1 file changed, 2 insertions(+), 33 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index e718efe4c6..7d4471fbc5 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -322,7 +322,6 @@ TEST_RESULTS_SAN_FILE_PFX=trace
 TEST_RESULTS_SAN_DIR_SFX=leak
 TEST_RESULTS_SAN_FILE=
 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"
 test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
 case "$TRASH_DIRECTORY" in
@@ -1215,42 +1214,15 @@ test_atexit_handler () {
 	teardown_malloc_check
 }
 
-sanitize_leak_log_message_ () {
-	local new="$1" &&
-	local old="$2" &&
-	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_ () {
 	if test -z "$TEST_RESULTS_SAN_FILE"
 	then
 		return
 	fi &&
-	local old="$TEST_RESULTS_SAN_DIR_NR_LEAKS_STARTUP" &&
-	local new="$(nr_san_dir_leaks_)" &&
-
-	if test $new -le $old
+	if test "$(nr_san_dir_leaks_)" = 0
 	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".*)" &&
 
 	if test -n "$passes_sanitize_leak" && test "$test_failure" = 0
@@ -1586,16 +1558,13 @@ then
 		test_done
 	fi
 
+	rm -rf "$TEST_RESULTS_SAN_DIR"
 	if ! mkdir -p "$TEST_RESULTS_SAN_DIR"
 	then
 		BAIL_OUT "cannot create $TEST_RESULTS_SAN_DIR"
 	fi &&
 	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
 	test_atexit "rmdir \"$TEST_RESULTS_SAN_DIR\" 2>/dev/null || :"
 
-- 
2.46.2.1011.gf1f9323e02
Previous: Jeff KingNext: Patrick Steinhardt
Message 2 of 9 in “LSan quality of life improvements”
  1. 0/3 LSan quality of life improvementsJeff King, Sep 24, 2024
  2. 1/3 test-lib: stop showing old leak logsJeff King, Sep 24, 2024
  3. Patrick SteinhardtSep 26, 2024
  4. 2/3 test-lib: show leak-sanitizer logs on --immediate failureJeff King, Sep 24, 2024
  5. Patrick SteinhardtSep 26, 2024
  6. 3/3 test-lib: check for leak logs after every testJeff King, Sep 24, 2024
  7. Patrick SteinhardtSep 26, 2024
  8. Jeff KingSep 27, 2024
  9. Patrick SteinhardtSep 26, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.