test-lib: add a GIT_TEST_PASSING_SANITIZE_LEAK=check mode

Add a new "GIT_TEST_PASSING_SANITIZE_LEAK=check" mode to the test-lib.sh. As noted in the updated "t/README" this compliments the existing "GIT_TEST_PASSING_SANITIZE_LEAK=true" mode added in 956d2e4639b (tests: add a test mode for SANITIZE=leak, run it in CI, 2021-09-23). Rather than document this all in one (even more) dense paragraph split up the discussion of how it combines with --immediate into its own paragraph following the discussion of "GIT_TEST_SANITIZE_LEAK_LOG=true". Before the removal of "test_external" in a preceding commit we would have had to special-case t9700-perl-git.sh and t0202-gettext-perl.sh. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jul 28, 2022 at 01:13 UTC e92684e1a26a2e61f53c691d65e01b446914784d
2 files changed +43 -8
t/README
+17
@@ -371,11 +371,28 @@ declared themselves as leak-free by setting
371 "TEST_PASSES_SANITIZE_LEAK=true" before sourcing "test-lib.sh". This
372 test mode is used by the "linux-leaks" CI target.
373
374 +GIT_TEST_PASSING_SANITIZE_LEAK=check checks that our
375 +"TEST_PASSES_SANITIZE_LEAK=true" markings are current. Rather than
376 +skipping those tests that haven't set "TEST_PASSES_SANITIZE_LEAK=true"
377 +before sourcing "test-lib.sh" this mode runs them with
378 +"--invert-exit-code". This is used to check that there's a one-to-one
379 +mapping between "TEST_PASSES_SANITIZE_LEAK=true" and those tests that
380 +pass under "SANITIZE=leak". This is especially useful when testing a
381 +series that fixes various memory leaks with "git rebase -x".
382 +
383 GIT_TEST_SANITIZE_LEAK_LOG=true will log memory leaks to
384 "test-results/$TEST_NAME.leak/trace.*" files. The logs include a
385 "dedup_token" (see +"ASAN_OPTIONS=help=1 ./git") and other options to
386 make logs +machine-readable.
387
388 +GIT_TEST_PASSING_SANITIZE_LEAK=check when combined with "--immediate"
389 +will run to completion faster, and result in the same failing
390 +tests. The only practical reason to run
391 +GIT_TEST_PASSING_SANITIZE_LEAK=check without "--immediate" is to
392 +combine it with "GIT_TEST_SANITIZE_LEAK_LOG=true". If we stop at the
393 +first failing test case our leak logs won't show subsequent leaks we
394 +might have run into.
395 +
396 GIT_TEST_PROTOCOL_VERSION=<n>, when set, makes 'protocol.version'
397 default to n.
398
t/test-lib.sh
+26 -8
@@ -1451,17 +1451,34 @@ BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK () {
1451
1452 if test -n "$SANITIZE_LEAK"
1453 then
1454 - if test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
1454 + # Normalize with test_bool_env
1455 + passes_sanitize_leak=
1456 +
1457 + # We need to see TEST_PASSES_SANITIZE_LEAK in "git
1458 + # env--helper" (via test_bool_env)
1459 + export TEST_PASSES_SANITIZE_LEAK
1460 + if test_bool_env TEST_PASSES_SANITIZE_LEAK false
1461 + then
1462 + passes_sanitize_leak=t
1463 + fi
1464 +
1465 + if test "$GIT_TEST_PASSING_SANITIZE_LEAK" = "check"
1466 then
1456 - # We need to see it in "git env--helper" (via
1457 - # test_bool_env)
1458 - export TEST_PASSES_SANITIZE_LEAK
1467 + if test -n "$invert_exit_code"
1468 + then
1469 + BAIL_OUT "cannot use --invert-exit-code under GIT_TEST_PASSING_SANITIZE_LEAK=check"
1470 + fi
1471
1460 - if ! test_bool_env TEST_PASSES_SANITIZE_LEAK false
1472 + if test -z "$passes_sanitize_leak"
1473 then
1462 - skip_all="skipping $this_test under GIT_TEST_PASSING_SANITIZE_LEAK=true"
1463 - test_done
1474 + say "in GIT_TEST_PASSING_SANITIZE_LEAK=check mode, setting --invert-exit-code for TEST_PASSES_SANITIZE_LEAK != true"
1475 + invert_exit_code=t
1476 fi
1477 + elif test -z "$passes_sanitize_leak" &&
1478 + test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
1479 + then
1480 + skip_all="skipping $this_test under GIT_TEST_PASSING_SANITIZE_LEAK=true"
1481 + test_done
1482 fi
1483
1484 if test_bool_env GIT_TEST_SANITIZE_LEAK_LOG false
@@ -1480,7 +1497,8 @@ then
1497 prepend_var LSAN_OPTIONS : log_path=\"$TEST_RESULTS_SAN_FILE\"
1498 export LSAN_OPTIONS
1499 fi
1483 -elif test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
1500 +elif test "$GIT_TEST_PASSING_SANITIZE_LEAK" = "check" ||
1501 + test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
1502 then
1503 BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK "GIT_TEST_PASSING_SANITIZE_LEAK=true"
1504 elif test_bool_env GIT_TEST_SANITIZE_LEAK_LOG false