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

Re: [PATCH 2/3] test-lib: simplify lsan results check

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 7, 2025, 07:37 UTC
Message-ID
<Z3zZt2OCjcDGvjBS@pks.im>
In-Reply-To
<20250107070752.GB584668@coredump.intra.peff.net>
On Tue, Jan 07, 2025 at 02:07:52AM -0500, Jeff King wrote:
Show 9 quoted lines
> We want to know if there are any leaks logged by LSan in the results
> directory, so we run "find" on the containing directory and pipe it to
> xargs. We can accomplish the same thing by just globbing in the shell
> and passing the result to grep, which has a few advantages:
> 
>   - it's one fewer process to run
> 
>   - we can glob on the TEST_RESULTS_SAN_FILE pattern, which is what we
>     checked at the beginning of the function, and is the same glob use
s/use/used

I'm always a bit thrown off by your style of bulleted lists, where they feel like sentences but start with a lower-case letter, and sometimes they do and sometimes they don't end with punctuation. Maybe it's just me not being a native speaker and it's a natural thing to do in English. In any case, it's nothing that really matters in the end, but would be happy to learn if this is indeed something you tend to do in English.

Show 19 quoted lines
>     to show the logs in check_test_results_san_file_
> 
>   - this correctly handles the case where TEST_OUTPUT_DIRECTORY has a
>     space in it. For example doing:
> 
>        mkdir "/tmp/foo bar"
>        TEST_OUTPUT_DIRECTORY="/tmp/foo bar" make SANITIZE=leak test
> 
>     would yield a lot of:
> 
>       grep: /tmp/foo: No such file or directory
>       grep: bar/test-results/t0006-date.leak/trace.test-tool.582311: No such file or directory
> 
>     when there are leaks. We could do the same thing with "xargs
>     --null", but that isn't portable.
> 
> We are now subject to command-line length limits, but that is also true
> of the globbing cat used to show the logs themselves. This hasn't been a
> problem in practice.

Yup, this also came to my mind immediately. But I agree that it shouldn't be an issue in general.

Show 6 quoted lines
> We do need to use "grep -s" for the case that the glob does not expand
> (i.e., there are not any log files at all). This option is in POSIX, and
> has been used in t7407 for several years without anybody complaining.
> This also also naturally handles the case where the surrounding
> directory has already been removed (in which case there are likewise no
> files!), dropping the need to comment about it.

Okay. So in case there are no matching files we don't expand the globbing string, and "--no-messages" makes us ignore that case. A bit funny, but I don't see any issue with it.

Show 5 quoted lines
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I was surprised by the use of "grep -s" in t7407, since it is totally
> pointless there. But I think we can take its presence as a positive sign
> for portability.
Good to know.
Show 19 quoted lines
>  t/test-lib.sh | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index be3553e40e..898c2267b8 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -1172,12 +1172,7 @@ test_atexit_handler () {
>  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" \
> -		-type f \
> -		-name "$TEST_RESULTS_SAN_FILE_PFX.*" 2>/dev/null |
> -	xargs grep ^DEDUP_TOKEN |
> +	grep -s ^DEDUP_TOKEN "$TEST_RESULTS_SAN_FILE".* |
>  	grep -qv sanitizer::GetThreadStackTopAndBottom
And this nicely simplifies things indeed.
Patrick
Previous: Jeff KingNext: Jeff King
Message 24 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.