git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Derrick Stolee <derrickstolee@github.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Shubham Mishra <shivam828787@gmail.com>,
	Christian Couder <christian.couder@gmail.com>,
	Taylor Blau <me@ttaylorr.com>
Subject: Re: [PATCH 00/15] tests: don't ignore "git" exit codes
Date: Thu, 03 Mar 2022 11:13:02 +0100	[thread overview]
Message-ID: <220303.86fsnz5o9w.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <76a1ff22-3eb0-08fb-5aa9-e612ee5b522f@github.com>


On Wed, Mar 02 2022, Derrick Stolee wrote:

> On 3/2/2022 12:27 PM, Ævar Arnfjörð Bjarmason wrote:
>> This series fixes issues where we ignored the exit code of "git" due
>> to it being on the LHS of a pipe, or because we interpolated its
>> output with $() in a "test" construct, or had missing &&- chains in
>> helper functions etc.
>> 
>> This series is not made by string-replacing things in our test suite,
>> if it was it would be much larger. These are all tests I've seen real
>> hide real failures under SANITIZE=leak, either on current "master", or
>> in combination with various local leak fixes I've got unsubmitted.
>
> My first reaction was to check that Subham was on the CC line (yes)
> because they have been working in this space, too. Your focus on
> examples that break SANITIZE=leak is appreciated so there is room
> for that project.

Yeah, I'm certainly not meaning to steal this whole "hide exit code"
microproject, and there's *a lot* more to chew on there :) (and I have
no intention of doing the rest).

But hopefully this series also serves as a nice tour-de-force through
the test suite showing a wide variety of exit-code-hiding cases for any
future work in the area.

I.e. the "git on theon LHS of a pipe" is an overly narrow definition of
it.

But then again I think these should also all be covered in passing by
t/README's "don'ts" list.

>> In cases where I was starting to fix a pattern in a file I'd fix the
>> rest of the file if it was easy, but otherwise these are all cases
>> where I ran SANITIZE=leak, had a test pass, but having ASAN_OPTIONS
>> log to a file revealed that we had memory leaks within that test.
>
> Neat trick.
>
> The patches in this series clearly do the right transformations to
> expose these errors at the appropriate time. The only time I got
> hung up was patch 11 where test_expect_failure was swapped for
> test_expect_success (while also dropping a test_must_fail inside
> the test). The double-negative confused me at first, but in the end
> the patch works as-is.
>
>> As an aside we still have various potential issues with hidden
>> segfaults etc. in the test suite after this that are tricked to solve,
>> because:
>> 
>>  * Our tests will (mostly) catch segfaults and abort(), but if we
>>    invoke a command that invokes another command it needs to ferry the
>>    exit code up to us.
>> 
>>  * run-command.c notably does not do that, 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.
>
> Perhaps run-command.c could auto-exit for certain well-known error
> codes that could only happen on certain kinds of failures (segfault,
> for example). A simple die() might be something that is expected to
> be handled by the top-level command in some cases.

Yes. I have a local WIP patch to make it do that.

Basically just set a a global "uh oh, one of our ran commands segfaulted
or abort()-ed, here's that exit status".

Then when we do the real exit() (which we always intercept due to the
trace2 logging needing to do so) an non-zero exit() of e.g. status 128
will be changed to the appropriate exit status of that segfault or
abort().

We'll thus ferry such exit codes upwards, clobbering whatever the
"desired" exit code of e.g. "git pull" would have been (but that's a
feature in this case).

One thing I got hung up on is that it's relatively straightforward for
the wait_or_whine() case in run-command.c, but I didn't look into how to
do that with the pthread_join() we do for finish_async(), which
e.g. happens if the multiplex'd dialog exits in this way.

>>  * 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, and if they fail returning "1", not ferrying up the
>>    segfault or abort() exit code.
>
> These are more involved and harder to evaluate. Add them to the pile
> of projects for new contributors?

FWIW those are relatively easy, for the first:

    use v5.10.1;
    use autodie qw(close);

And for the second just go through the relatively small amount of such
remaining shell code and convert:

	if ! git ...
	then
		exit 1

To:

	git ...
	code=$?
        if test $code -ne 0
	then
		exit $code

Or whatever.
    

    

  reply	other threads:[~2022-03-03 10:22 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 17:27 [PATCH 00/15] tests: don't ignore "git" exit codes Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 01/15] tests: change some 'test $(git) = "x"' to test_cmp Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 02/15] tests: use "test_stdout_line_count", not "test $(git [...] | wc -l)" Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 03/15] read-tree tests: check "diff-files" exit code on failure Ævar Arnfjörð Bjarmason
2022-03-02 23:06   ` Junio C Hamano
2022-03-02 17:27 ` [PATCH 04/15] diff tests: don't ignore "git diff" exit code Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 05/15] diff tests: don't ignore "git diff" exit code in "read" loop Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 06/15] apply tests: use "test_must_fail" instead of ad-hoc pattern Ævar Arnfjörð Bjarmason
2022-03-02 23:09   ` Junio C Hamano
2022-03-02 17:27 ` [PATCH 07/15] merge " Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 08/15] rev-parse tests: don't ignore "git reflog" exit code Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 09/15] notes tests: don't ignore "git" " Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 10/15] diff tests: don't ignore "git rev-list" " Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 11/15] rev-list tests: don't hide abort() in "test_expect_failure" Ævar Arnfjörð Bjarmason
2022-03-02 23:16   ` Junio C Hamano
2022-03-03 10:10     ` Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 12/15] gettext tests: don't ignore "test-tool regex" exit code Ævar Arnfjörð Bjarmason
2022-03-02 23:20   ` Junio C Hamano
2022-03-03 15:46     ` Ævar Arnfjörð Bjarmason
2022-03-03 20:58       ` Junio C Hamano
2022-03-02 17:27 ` [PATCH 13/15] apply tests: don't ignore "git ls-files" exit code, drop sub-shell Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 14/15] checkout tests: don't ignore "git <cmd>" exit code Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 15/15] rev-list simplify tests: don't ignore "git" " Ævar Arnfjörð Bjarmason
2022-03-02 23:23 ` [PATCH 00/15] tests: don't ignore "git" exit codes Junio C Hamano
2022-03-03  2:02 ` Derrick Stolee
2022-03-03 10:13   ` Ævar Arnfjörð Bjarmason [this message]
2022-03-03 14:06   ` Phillip Wood
2022-03-03 15:35     ` Ævar Arnfjörð Bjarmason
2022-03-04  2:44       ` Junio C Hamano
2022-03-04  6:57         ` Ævar Arnfjörð Bjarmason
2022-03-03  5:09 ` Shubham Mishra
2022-03-03  9:53   ` Ævar Arnfjörð Bjarmason
2022-03-07 12:48 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 01/15] tests: change some 'test $(git) = "x"' to test_cmp Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 02/15] tests: use "test_stdout_line_count", not "test $(git [...] | wc -l)" Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 03/15] read-tree tests: check "diff-files" exit code on failure Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 04/15] diff tests: don't ignore "git diff" exit code Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 05/15] diff tests: don't ignore "git diff" exit code in "read" loop Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 06/15] apply tests: use "test_must_fail" instead of ad-hoc pattern Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 07/15] merge " Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 08/15] rev-parse tests: don't ignore "git reflog" exit code Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 09/15] notes tests: don't ignore "git" " Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 10/15] diff tests: don't ignore "git rev-list" " Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 11/15] rev-list tests: don't hide abort() in "test_expect_failure" Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 12/15] gettext tests: don't ignore "test-tool regex" exit code Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 13/15] apply tests: don't ignore "git ls-files" exit code, drop sub-shell Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 14/15] checkout tests: don't ignore "git <cmd>" exit code Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 15/15] rev-list simplify tests: don't ignore "git" " Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=220303.86fsnz5o9w.gmgdl@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=shivam828787@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).