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

[PATCH 3/3] test-lib: check for leak logs after every test

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

If you are trying to find and fix leaks in a large test script, it can be overwhelming to see the leak logs for every test at once. The previous commit let you use "--immediate" to see the logs after the first failing test, but this isn't always the first leak. As discussed there, we may see leaks from previous tests that didn't happen to fail.

To catch those, let's check for any logs that appeared after each test snippet is run, meaning that in a SANITIZE=leak build, any leak is an immediate failure of the test snippet.

This check is mostly free in non-leak builds (just a "test -z"), and only a few extra processes in a leak build, so I don't think the overhead should matter (if it does, we could probably optimize for the common "no logs" case without even spending a process).

Signed-off-by: Jeff King <peff@peff.net>
---
 t/test-lib-functions.sh |  3 ++-
 t/test-lib.sh           | 11 ++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index fde9bf54fc..78e054ab50 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -926,7 +926,8 @@ test_expect_success () {
 		test_body_or_stdin test_body "$2"
 		test -n "$test_skip_test_preamble" ||
 		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
 			test_ok_ "$1"
 		else
diff --git a/t/test-lib.sh b/t/test-lib.sh
index d624ee186c..b1a8ee5c00 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1215,12 +1215,13 @@ test_atexit_handler () {
 	teardown_malloc_check
 }
 
+check_test_results_san_file_empty_ () {
+	test -z "$TEST_RESULTS_SAN_FILE" ||
+	test "$(nr_san_dir_leaks_)" = 0
+}
+
 check_test_results_san_file_ () {
-	if test -z "$TEST_RESULTS_SAN_FILE"
-	then
-		return
-	fi &&
-	if test "$(nr_san_dir_leaks_)" = 0
+	if check_test_results_san_file_empty_
 	then
 		return
 	fi &&
-- 
2.46.2.1011.gf1f9323e02
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 6 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.