Skip to content

Commit 657c740

Browse files
committed
Merge branch 'ab/leak-check'
Extend SANITIZE=leak checking and declare more tests "currently leak-free". * 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 leak tests: don't skip some tests under SANITIZE=leak 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 f0e9754 + c24feab commit 657c740

Some content is hidden

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

57 files changed

+405
-227
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/t0002-gitfile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test_expect_success 'check commit-tree' '
6565
test_path_is_file "$REAL/objects/$(objpath $SHA)"
6666
'
6767

68-
test_expect_success !SANITIZE_LEAK 'check rev-list' '
68+
test_expect_success 'check rev-list' '
6969
git update-ref "HEAD" "$SHA" &&
7070
git rev-list HEAD >actual &&
7171
echo $SHA >expected &&

t/t0004-unwritable.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test_expect_success WRITE_TREE_OUT 'write-tree output on unwritable repository'
3131
test_cmp expect out.write-tree
3232
'
3333

34-
test_expect_success POSIXPERM,SANITY,!SANITIZE_LEAK 'commit should notice unwritable repository' '
34+
test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
3535
test_when_finished "chmod 775 .git/objects .git/objects/??" &&
3636
chmod a-w .git/objects .git/objects/?? &&
3737
test_must_fail git commit -m second 2>out.commit

0 commit comments

Comments
 (0)