Skip to content

Commit e92684e

Browse files
avargitster
authored andcommitted
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 956d2e4 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5beca49 commit e92684e

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

t/README

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,28 @@ declared themselves as leak-free by setting
371371
"TEST_PASSES_SANITIZE_LEAK=true" before sourcing "test-lib.sh". This
372372
test mode is used by the "linux-leaks" CI target.
373373

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+
374383
GIT_TEST_SANITIZE_LEAK_LOG=true will log memory leaks to
375384
"test-results/$TEST_NAME.leak/trace.*" files. The logs include a
376385
"dedup_token" (see +"ASAN_OPTIONS=help=1 ./git") and other options to
377386
make logs +machine-readable.
378387

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+
379396
GIT_TEST_PROTOCOL_VERSION=<n>, when set, makes 'protocol.version'
380397
default to n.
381398

t/test-lib.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,17 +1451,34 @@ BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK () {
14511451

14521452
if test -n "$SANITIZE_LEAK"
14531453
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"
14551466
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
14591471

1460-
if ! test_bool_env TEST_PASSES_SANITIZE_LEAK false
1472+
if test -z "$passes_sanitize_leak"
14611473
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
14641476
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
14651482
fi
14661483

14671484
if test_bool_env GIT_TEST_SANITIZE_LEAK_LOG false
@@ -1480,7 +1497,8 @@ then
14801497
prepend_var LSAN_OPTIONS : log_path=\"$TEST_RESULTS_SAN_FILE\"
14811498
export LSAN_OPTIONS
14821499
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
14841502
then
14851503
BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK "GIT_TEST_PASSING_SANITIZE_LEAK=true"
14861504
elif test_bool_env GIT_TEST_SANITIZE_LEAK_LOG false

0 commit comments

Comments
 (0)