mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
faececa53f
As noted in previous on-list discussions[1] we have various tests that will falsely report being leak-free because we're missing the relevant exit code from LSAN as summarized below. We should fix those issues, but in the meantime and as an additional sanity check we can and should consider our own ASAN logs before reporting that a test is leak-free. Before this compiling with SANITIZE=leak and running: ./t6407-merge-binary.sh Will exit successfully, now we'll get an error and an informative message on: GIT_TEST_SANITIZE_LEAK_LOG=true ./t6407-merge-binary.sh Even better, as noted in the updated t/README we'll now error out when combined with the "check" mode: GIT_TEST_PASSING_SANITIZE_LEAK=check \ GIT_TEST_SANITIZE_LEAK_LOG=true \ ./t4058-diff-duplicates.sh Why do we miss these leaks? Because: * We have leaks inside "test_expect_failure" blocks, which by design will not distinguish a "normal" failure from an abort() or segfault. See [1] for a discussion of it shortcomings. * We have "git" invocations outside of "test_expect_success", e.g. setup code in the main body of the test, or in test helper functions that don't use &&-chaining. * Our tests will otherwise catch segfaults and abort(), but if we invoke a command that invokes another command it needs to ferry the exit code up to us. Notably a command that e.g. might invoke "git pack-objects" might itself exit with status 128 if that "pack-objects" segfaults or abort()'s. If the test invoking the parent command(s) is using "test_must_fail" we'll consider it an expected "ok" failure. * run-command.c doesn't (but probably should) ferry up such exit codes, so for e.g. "git push" tests where we expect a failure and an underlying "git" command fails we won't ferry up the segfault or abort exit code. * We have gitweb.perl and some other perl code ignoring return values from close(), i.e. ignoring exit codes from "git rev-parse" et al. * We have in-tree shellscripts like "git-merge-one-file.sh" invoking git commands, they'll usually return their own exit codes on "git" failure, rather then ferrying up segfault or abort() exit code. E.g. these invocations in git-merge-one-file.sh leak, but aren't reflected in the "git merge" exit code: src1=$(git unpack-file $2) src2=$(git unpack-file $3) That case would be easily "fixed" by adding a line like this after each assignment: test $? -ne 0 && exit $? But we'd then in e.g. "t6407-merge-binary.sh" run into write_tree_trivial() in "builtin/merge.c" calling die() instead of ferrying up the relevant exit code. Let's remove "TEST_PASSES_SANITIZE_LEAK=true" from tests we were falsely marking as leak-free. In the case of t6407-merge-binary.sh it was marked as leak-free in9081a421a6
(checkout: fix "branch info" memory leaks, 2021-11-16). I'd previously removed other bad "TEST_PASSES_SANITIZE_LEAK=true" opt-ins in the series merged inea05fd5fbf
(Merge branch 'ab/keep-git-exit-codes-in-tests', 2022-03-16). The case of t1060-object-corruption.sh is more subtle, and will be discussed in a subsequent commit. 1. https://lore.kernel.org/git/cover-0.7-00000000000-20220318T002951Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
60 lines
1.1 KiB
Bash
Executable file
60 lines
1.1 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='ask merge-recursive to merge binary files'
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
|
|
cat "$TEST_DIRECTORY"/test-binary-1.png >m &&
|
|
git add m &&
|
|
git ls-files -s | sed -e "s/ 0 / 1 /" >E1 &&
|
|
test_tick &&
|
|
git commit -m "initial" &&
|
|
|
|
git branch side &&
|
|
echo frotz >a &&
|
|
git add a &&
|
|
echo nitfol >>m &&
|
|
git add a m &&
|
|
git ls-files -s a >E0 &&
|
|
git ls-files -s m | sed -e "s/ 0 / 3 /" >E3 &&
|
|
test_tick &&
|
|
git commit -m "main adds some" &&
|
|
|
|
git checkout side &&
|
|
echo rezrov >>m &&
|
|
git add m &&
|
|
git ls-files -s m | sed -e "s/ 0 / 2 /" >E2 &&
|
|
test_tick &&
|
|
git commit -m "side modifies" &&
|
|
|
|
git tag anchor &&
|
|
|
|
cat E0 E1 E2 E3 >expect
|
|
'
|
|
|
|
test_expect_success resolve '
|
|
|
|
rm -f a* m* &&
|
|
git reset --hard anchor &&
|
|
|
|
test_must_fail git merge -s resolve main &&
|
|
git ls-files -s >current &&
|
|
test_cmp expect current
|
|
'
|
|
|
|
test_expect_success recursive '
|
|
|
|
rm -f a* m* &&
|
|
git reset --hard anchor &&
|
|
|
|
test_must_fail git merge -s recursive main &&
|
|
git ls-files -s >current &&
|
|
test_cmp expect current
|
|
'
|
|
|
|
test_done
|