Skip to content

Commit 8c37444

Browse files
committed
Merge branch 'ab/leak-check' into seen
Plugging more leaks. source: <[email protected]> * ab/leak-check: CI: use "GIT_TEST_SANITIZE_LEAK_LOG=true" in linux-leaks upload-pack: fix a memory leak in create_pack_file() leak tests: mark passing SANITIZE=leak tests as leak-free test-lib: have the "check" mode for SANITIZE=leak consider leak logs test-lib: add a GIT_TEST_PASSING_SANITIZE_LEAK=check mode test-lib: simplify by removing test_external tests: move copy/pasted PERL + Test::More checks to a lib-perl.sh t/Makefile: don't remove test-results in "clean-except-prove-cache" test-lib: add a SANITIZE=leak logging mode t/README: reword the "GIT_TEST_PASSING_SANITIZE_LEAK" description test-lib: add a --invert-exit-code switch test-lib: fix GIT_EXIT_OK logic errors, use BAIL_OUT test-lib: don't set GIT_EXIT_OK before calling test_atexit_handler test-lib: use $1, not $@ in test_known_broken_{ok,failure}_
2 parents cea431c + 9737bf2 commit 8c37444

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+396
-216
lines changed

ci/lib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ linux-musl)
276276
linux-leaks)
277277
export SANITIZE=leak
278278
export GIT_TEST_PASSING_SANITIZE_LEAK=true
279+
export GIT_TEST_SANITIZE_LEAK_LOG=true
279280
;;
280281
esac
281282

contrib/credential/netrc/t-git-credential-netrc.sh

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,20 @@
33
cd ../../../t
44
test_description='git-credential-netrc'
55
. ./test-lib.sh
6+
. "$TEST_DIRECTORY"/lib-perl.sh
67

7-
if ! test_have_prereq PERL; then
8-
skip_all='skipping perl interface tests, perl not available'
9-
test_done
10-
fi
11-
12-
perl -MTest::More -e 0 2>/dev/null || {
13-
skip_all="Perl Test::More unavailable, skipping test"
14-
test_done
15-
}
8+
skip_all_if_no_Test_More
169

1710
# set up test repository
1811

1912
test_expect_success \
2013
'set up test repository' \
2114
'git config --add gpg.program test.git-config-gpg'
2215

23-
# The external test will outputs its own plan
24-
test_external_has_tap=1
25-
2616
export PERL5LIB="$GITPERLLIB"
27-
test_external \
28-
'git-credential-netrc' \
17+
test_expect_success 'git-credential-netrc' '
2918
perl "$GIT_BUILD_DIR"/contrib/credential/netrc/test.pl
19+
'
3020

3121
test_done
3222
)

contrib/scalar/t/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ $(T):
4242
@echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
4343

4444
clean-except-prove-cache:
45-
$(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
45+
$(RM) -r 'trash directory'.*
4646
$(RM) -r valgrind/bin
4747

4848
clean: clean-except-prove-cache

contrib/subtree/t/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pre-clean:
4747
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
4848

4949
clean-except-prove-cache:
50-
$(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
50+
$(RM) -r 'trash directory'.*
5151
$(RM) -r valgrind/bin
5252

5353
clean: clean-except-prove-cache

t/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pre-clean:
6262
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
6363

6464
clean-except-prove-cache: clean-chainlint
65-
$(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
65+
$(RM) -r 'trash directory'.*
6666
$(RM) -r valgrind/bin
6767

6868
clean: clean-except-prove-cache

t/README

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,47 @@ excluded as so much relies on it, but this might change in the future.
366366
GIT_TEST_SPLIT_INDEX=<boolean> forces split-index mode on the whole
367367
test suite. Accept any boolean values that are accepted by git-config.
368368

369-
GIT_TEST_PASSING_SANITIZE_LEAK=<boolean> when compiled with
370-
SANITIZE=leak will run only those tests that have whitelisted
371-
themselves as passing with no memory leaks. Tests can be whitelisted
372-
by setting "TEST_PASSES_SANITIZE_LEAK=true" before sourcing
373-
"test-lib.sh" itself at the top of the test script. This test mode is
374-
used by the "linux-leaks" CI target.
369+
GIT_TEST_PASSING_SANITIZE_LEAK=true skips those tests that haven't
370+
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+
With GIT_TEST_SANITIZE_LEAK_LOG=true we'll look at the leak logs
389+
before exiting and exit on failure if the logs showed that we had a
390+
memory leak, even if the test itself would have otherwise passed. This
391+
allows us to catch e.g. missing &&-chaining. This is especially useful
392+
when combined with "GIT_TEST_PASSING_SANITIZE_LEAK", see below.
393+
394+
GIT_TEST_PASSING_SANITIZE_LEAK=check when combined with "--immediate"
395+
will run to completion faster, and result in the same failing
396+
tests. The only practical reason to run
397+
GIT_TEST_PASSING_SANITIZE_LEAK=check without "--immediate" is to
398+
combine it with "GIT_TEST_SANITIZE_LEAK_LOG=true". If we stop at the
399+
first failing test case our leak logs won't show subsequent leaks we
400+
might have run into.
401+
402+
GIT_TEST_PASSING_SANITIZE_LEAK=(true|check) will not catch all memory
403+
leaks unless combined with GIT_TEST_SANITIZE_LEAK_LOG=true. Some tests
404+
run "git" (or "test-tool" etc.) without properly checking the exit
405+
code, or git will invoke itself and fail to ferry the abort() exit
406+
code to the original caller. When the two modes are combined we'll
407+
look at the "test-results/$TEST_NAME.leak/trace.*" files at the end of
408+
the test run to see if had memory leaks which the test itself didn't
409+
catch.
375410

376411
GIT_TEST_PROTOCOL_VERSION=<n>, when set, makes 'protocol.version'
377412
default to n.
@@ -935,32 +970,6 @@ see test-lib-functions.sh for the full list and their options.
935970
test_done
936971
fi
937972

938-
- test_external [<prereq>] <message> <external> <script>
939-
940-
Execute a <script> with an <external> interpreter (like perl). This
941-
was added for tests like t9700-perl-git.sh which do most of their
942-
work in an external test script.
943-
944-
test_external \
945-
'GitwebCache::*FileCache*' \
946-
perl "$TEST_DIRECTORY"/t9503/test_cache_interface.pl
947-
948-
If the test is outputting its own TAP you should set the
949-
test_external_has_tap variable somewhere before calling the first
950-
test_external* function. See t9700-perl-git.sh for an example.
951-
952-
# The external test will outputs its own plan
953-
test_external_has_tap=1
954-
955-
- test_external_without_stderr [<prereq>] <message> <external> <script>
956-
957-
Like test_external but fail if there's any output on stderr,
958-
instead of checking the exit code.
959-
960-
test_external_without_stderr \
961-
'Perl API' \
962-
perl "$TEST_DIRECTORY"/t9700/test.pl
963-
964973
- test_expect_code <exit-code> <command>
965974

966975
Run a command and ensure that it exits with the given exit code.

t/lib-perl.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2022 Ævar Arnfjörð Bjarmason
2+
3+
test_lazy_prereq PERL_TEST_MORE '
4+
perl -MTest::More -e 0
5+
'
6+
7+
skip_all_if_no_Test_More () {
8+
if ! test_have_prereq PERL
9+
then
10+
skip_all='skipping perl interface tests, perl not available'
11+
test_done
12+
fi
13+
14+
if ! test_have_prereq PERL_TEST_MORE
15+
then
16+
skip_all="Perl Test::More unavailable, skipping test"
17+
test_done
18+
fi
19+
}

t/t0000-basic.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,78 @@ test_expect_success 'subtest: --run invalid range end' '
578578
EOF_ERR
579579
'
580580

581+
test_expect_success 'subtest: --invert-exit-code without --immediate' '
582+
run_sub_test_lib_test_err full-pass \
583+
--invert-exit-code &&
584+
check_sub_test_lib_test_err full-pass \
585+
<<-\EOF_OUT 3<<-EOF_ERR
586+
ok 1 - passing test #1
587+
ok 2 - passing test #2
588+
ok 3 - passing test #3
589+
# passed all 3 test(s)
590+
1..3
591+
# faking up non-zero exit with --invert-exit-code
592+
EOF_OUT
593+
EOF_ERR
594+
'
595+
596+
test_expect_success 'subtest: --invert-exit-code with --immediate: all passed' '
597+
run_sub_test_lib_test_err full-pass \
598+
--invert-exit-code --immediate &&
599+
check_sub_test_lib_test_err full-pass \
600+
<<-\EOF_OUT 3<<-EOF_ERR
601+
ok 1 - passing test #1
602+
ok 2 - passing test #2
603+
ok 3 - passing test #3
604+
# passed all 3 test(s)
605+
1..3
606+
# faking up non-zero exit with --invert-exit-code
607+
EOF_OUT
608+
EOF_ERR
609+
'
610+
611+
test_expect_success 'subtest: --invert-exit-code without --immediate: partial pass' '
612+
run_sub_test_lib_test partial-pass \
613+
--invert-exit-code &&
614+
check_sub_test_lib_test partial-pass <<-\EOF
615+
ok 1 - passing test #1
616+
not ok 2 - # TODO induced breakage (--invert-exit-code): failing test #2
617+
# false
618+
ok 3 - passing test #3
619+
# failed 1 among 3 test(s)
620+
1..3
621+
# faked up failures as TODO & now exiting with 0 due to --invert-exit-code
622+
EOF
623+
'
624+
625+
test_expect_success 'subtest: --invert-exit-code with --immediate: partial pass' '
626+
run_sub_test_lib_test partial-pass \
627+
--invert-exit-code --immediate &&
628+
check_sub_test_lib_test partial-pass \
629+
<<-\EOF_OUT 3<<-EOF_ERR
630+
ok 1 - passing test #1
631+
not ok 2 - # TODO induced breakage (--invert-exit-code): failing test #2
632+
# false
633+
1..2
634+
# faked up failures as TODO & now exiting with 0 due to --invert-exit-code
635+
EOF_OUT
636+
EOF_ERR
637+
'
638+
639+
test_expect_success 'subtest: --invert-exit-code --immediate: got a failure' '
640+
run_sub_test_lib_test partial-pass \
641+
--invert-exit-code --immediate &&
642+
check_sub_test_lib_test_err partial-pass \
643+
<<-\EOF_OUT 3<<-EOF_ERR
644+
ok 1 - passing test #1
645+
not ok 2 - # TODO induced breakage (--invert-exit-code): failing test #2
646+
# false
647+
1..2
648+
# faked up failures as TODO & now exiting with 0 due to --invert-exit-code
649+
EOF_OUT
650+
EOF_ERR
651+
'
652+
581653
test_expect_success 'subtest: tests respect prerequisites' '
582654
write_and_run_sub_test_lib_test prereqs <<-\EOF &&
583655

t/t0027-auto-crlf.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='CRLF conversion all combinations'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
compare_files () {

t/t0032-reftable-unittest.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
test_description='reftable unittests'
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
test_expect_success 'unittests' '

t/t0033-safe-directory.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='verify safe.directory checks'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
GIT_TEST_ASSUME_DIFFERENT_OWNER=1

t/t0050-filesystem.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='Various filesystem issues'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
auml=$(printf '\303\244')

t/t0095-bloom.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='Testing the various Bloom filter computations in bloom.c'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'compute unseeded murmur3 hash for empty string' '

t/t0202-gettext-perl.sh

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@ test_description='Perl gettext interface (Git::I18N)'
77

88
TEST_PASSES_SANITIZE_LEAK=true
99
. ./lib-gettext.sh
10+
. "$TEST_DIRECTORY"/lib-perl.sh
11+
skip_all_if_no_Test_More
1012

11-
if ! test_have_prereq PERL; then
12-
skip_all='skipping perl interface tests, perl not available'
13-
test_done
14-
fi
15-
16-
perl -MTest::More -e 0 2>/dev/null || {
17-
skip_all="Perl Test::More unavailable, skipping test"
18-
test_done
19-
}
20-
21-
# The external test will outputs its own plan
22-
test_external_has_tap=1
23-
24-
test_external_without_stderr \
25-
'Perl Git::I18N API' \
26-
perl "$TEST_DIRECTORY"/t0202/test.pl
13+
test_expect_success 'run t0202/test.pl to test Git::I18N.pm' '
14+
"$PERL_PATH" "$TEST_DIRECTORY"/t0202/test.pl 2>stderr &&
15+
test_must_be_empty stderr
16+
'
2717

2818
test_done

t/t1405-main-ref-store.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='test main ref store api'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
RUN="test-tool ref-store main"

t/t1407-worktree-ref-store.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='test worktree ref store api'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
RWT="test-tool ref-store worktree:wt"

t/t1418-reflog-exists.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='Test reflog display routines'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89

910
test_expect_success 'setup' '

t/t1701-racy-split-index.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
test_description='racy split index'
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
test_expect_success 'setup' '

t/t2006-checkout-index-basic.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
test_description='basic checkout-index tests
44
'
55

6+
TEST_PASSES_SANITIZE_LEAK=true
67
. ./test-lib.sh
78

89
test_expect_success 'checkout-index --gobbledegook' '

t/t2023-checkout-m.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Ensures that checkout -m on a resolved file restores the conflicted file'
77
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
88
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
99

10+
TEST_PASSES_SANITIZE_LEAK=true
1011
. ./test-lib.sh
1112

1213
test_expect_success setup '

t/t2205-add-worktree-config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ outside the repository. Two instances for which this can occur are tested:
1717
repository can be added to the index.
1818
'
1919

20+
TEST_PASSES_SANITIZE_LEAK=true
2021
. ./test-lib.sh
2122

2223
test_expect_success '1a: setup--config worktree' '

t/t3012-ls-files-dedup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='git ls-files --deduplicate test'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_expect_success 'setup' '

t/t4017-diff-retval.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='Return value of diffs'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
test_expect_success 'setup' '

0 commit comments

Comments
 (0)