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

[PATCH 1/3] test-lib: invert return value of check_test_results_san_file_empty

From
Jeff King <peff@peff.net>
Date
Jan 7, 2025, 07:05 UTC
Message-ID
<20250107070501.GA584668@coredump.intra.peff.net>
In-Reply-To
<20250107070409.GA584456@coredump.intra.peff.net>

We have a function to check whether LSan logged any leaks. It returns success for no leaks, and non-zero otherwise. This is the simplest thing for its callers, who want to say "if no leaks then return early". But because it's implemented as a shell pipeline, you end up with the awkward:

  ! find ... |
  xargs grep leaks |
  grep -v false-positives

where the "!" is actually negating the final grep. Switch the return value (and name) to return success when there are leaks. This should make the code a little easier to read, and the negation in the callers still reads pretty naturally.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/test-lib-functions.sh | 2 +-
 t/test-lib.sh           | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 78e054ab50..c25cee0ad8 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -927,7 +927,7 @@ test_expect_success () {
 		test -n "$test_skip_test_preamble" ||
 		say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body"
 		if test_run_ "$test_body" &&
-		   check_test_results_san_file_empty_
+		   ! check_test_results_san_file_has_entries_
 		then
 			test_ok_ "$1"
 		else
diff --git a/t/test-lib.sh b/t/test-lib.sh
index d1f62adbf8..be3553e40e 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1169,20 +1169,20 @@ test_atexit_handler () {
 	teardown_malloc_check
 }
 
-check_test_results_san_file_empty_ () {
-	test -z "$TEST_RESULTS_SAN_FILE" && return 0
+check_test_results_san_file_has_entries_ () {
+	test -z "$TEST_RESULTS_SAN_FILE" && return 1
 
 	# stderr piped to /dev/null because the directory may have
 	# been "rmdir"'d already.
-	! find "$TEST_RESULTS_SAN_DIR" \
+	find "$TEST_RESULTS_SAN_DIR" \
 		-type f \
 		-name "$TEST_RESULTS_SAN_FILE_PFX.*" 2>/dev/null |
 	xargs grep ^DEDUP_TOKEN |
 	grep -qv sanitizer::GetThreadStackTopAndBottom
 }
 
 check_test_results_san_file_ () {
-	if check_test_results_san_file_empty_
+	if ! check_test_results_san_file_has_entries_
 	then
 		return
 	fi &&
-- 
2.48.0.rc2.377.g0507c08f68
Previous: Jeff KingNext: Jeff King
Message 22 of 37 in “What's cooking in git.git (Dec 2024, #11; Mon, 30)”
  1. Junio C HamanoDec 30, 2024
  2. René ScharfeDec 31, 2024
  3. Patrick SteinhardtJan 3, 2025
  4. a less-invasive racy-leak fix, was Re: What's cooking in git.git (Dec 2024, #11; Mon, 30)Jeff King, Jan 1, 2025
  5. 0/6 a less-invasive racy-leak fixJeff King, Jan 1, 2025
  6. 1/6 test-lib: use individual lsan dir for --stress runsJeff King, Jan 1, 2025
  7. 2/6 Revert "index-pack: spawn threads atomically"Jeff King, Jan 1, 2025
  8. 3/6 test-lib: rely on logs to detect leaksJeff King, Jan 1, 2025
  9. Patrick SteinhardtJan 3, 2025
  10. Jeff KingJan 3, 2025
  11. 4/6 test-lib: simplify leak-log checkingJeff King, Jan 1, 2025
  12. Patrick SteinhardtJan 3, 2025
  13. Jeff KingJan 3, 2025
  14. Patrick SteinhardtJan 6, 2025
  15. Jeff KingJan 7, 2025
  16. 5/6 test-lib: check leak logs for presence of DEDUP_TOKENJeff King, Jan 1, 2025
  17. 6/6 test-lib: ignore leaks in the sanitizer's thread codeJeff King, Jan 1, 2025
  18. Patrick SteinhardtJan 3, 2025
  19. Jeff KingJan 3, 2025
  20. Patrick SteinhardtJan 6, 2025
  21. 0/3 lsan test-lib readabilityJeff King, Jan 7, 2025
  22. 1/3 test-lib: invert return value of check_test_results_san_file_emptyJeff King, Jan 7, 2025
  23. 2/3 test-lib: simplify lsan results checkJeff King, Jan 7, 2025
  24. Patrick SteinhardtJan 7, 2025
  25. Jeff KingJan 9, 2025
  26. Patrick SteinhardtJan 9, 2025
  27. Junio C HamanoJan 7, 2025
  28. Jeff KingJan 9, 2025
  29. 3/3 test-lib: add a few comments to LSan log checkingJeff King, Jan 7, 2025
  30. Patrick SteinhardtJan 7, 2025
  31. Junio C HamanoJan 2, 2025
  32. Jeff KingJan 2, 2025
  33. Chris TorekJan 2, 2025
  34. Junio C HamanoJan 2, 2025
  35. Jeff KingJan 2, 2025
  36. Junio C HamanoJan 2, 2025
  37. Jeff KingJan 2, 2025

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.