All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: Daniel Kiper <dkiper@net-space.pl>
Cc: grub-devel@gnu.org
Subject: Re: [PATCH v2 4/8] tests: Fail immediately when grub-shell fails and do not occlude the error code
Date: Thu, 7 Oct 2021 10:35:58 -0500	[thread overview]
Message-ID: <20211007103558.6eb0ce3f@crass-HP-ZBook-15-G2> (raw)
In-Reply-To: <20211007123716.owgasswltnage6hr@tomti.i.net-space.pl>

On Thu, 7 Oct 2021 14:37:16 +0200
Daniel Kiper <dkiper@net-space.pl> wrote:

> On Wed, Oct 06, 2021 at 03:05:57PM -0500, Glenn Washburn wrote:
> > On Wed, 6 Oct 2021 15:57:24 +0200
> > Daniel Kiper <dkiper@net-space.pl> wrote:
> >
> > > On Wed, Aug 25, 2021 at 02:03:58AM -0500, Glenn Washburn wrote:
> > > > If grub-shell fails, that means that whatever was being tested was not
> > > > actually tested. So fail immediately. Sometimes grub-shell is not the last
> > > > command in a pipeline of several commands, and in this case the failed error
> > > > code can be hidden by a later failing command or hidden when 'set -e' is not
> > > > set and there are subsequent successful commands. When the test script fails
> > > > because of a failure in grub-shell, then test script should exit with the
> > > > failed exit code of grub-shell.
> > > >
> > > > Signed-off-by: Glenn Washburn <development@efficientek.com>
> > > > ---
> > > >  tests/ahci_test.in             | 6 +++++-
> > > >  tests/cdboot_test.in           | 3 ++-
> > > >  tests/core_compress_test.in    | 6 ++++--
> > > >  tests/ehci_test.in             | 6 +++++-
> > > >  tests/fddboot_test.in          | 3 ++-
> > > >  tests/grub_cmd_date.in         | 3 ++-
> > > >  tests/grub_cmd_test.in         | 1 +
> > > >  tests/grub_script_blockarg.in  | 2 +-
> > > >  tests/grub_script_expansion.in | 3 ++-
> > > >  tests/gzcompress_test.in       | 3 ++-
> > > >  tests/hddboot_test.in          | 3 ++-
> > > >  tests/lzocompress_test.in      | 3 ++-
> > > >  tests/netboot_test.in          | 3 ++-
> > > >  tests/ohci_test.in             | 6 +++++-
> > > >  tests/partmap_test.in          | 4 ++--
> > > >  tests/pata_test.in             | 3 ++-
> > > >  tests/test_sha512sum.in        | 1 +
> > > >  tests/uhci_test.in             | 6 +++++-
> > > >  tests/xzcompress_test.in       | 3 ++-
> > > >  19 files changed, 49 insertions(+), 19 deletions(-)
> > > >
> > > > diff --git a/tests/ahci_test.in b/tests/ahci_test.in
> > > > index d844fe680..30dc9d31a 100644
> > > > --- a/tests/ahci_test.in
> > > > +++ b/tests/ahci_test.in
> > > > @@ -41,7 +41,11 @@ echo "hello" > "$outfile"
> > > >
> > > >  tar cf "$imgfile" "$outfile"
> > > >
> > > > -if [ "$(echo "nativedisk; source '(ahci0)/$outfile';" | "${grubshell}" --qemu-opts="-drive id=disk,file=$imgfile,if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 " | tail -n 1)" != "Hello World" ]; then
> > > > +echo "nativedisk; source '(ahci0)/$outfile';" |
> > > > +    "${grubshell}" --qemu-opts="-drive id=disk,file=$imgfile,if=none
> > > > +				-device ahci,id=ahci
> > > > +				-device ide-hd,drive=disk,bus=ahci.0" >$outfile
> > > > +if [ "$(cat "$outfile" | tail -n 1)" != "Hello World" ]; then
> > >
> > > This change is in line with the commit message...
> > >
> > > >     rm "$imgfile"
> > > >     rm "$outfile"
> > > >     exit 1
> > > > diff --git a/tests/cdboot_test.in b/tests/cdboot_test.in
> > > > index 75acdfedb..7229f79fb 100644
> > > > --- a/tests/cdboot_test.in
> > > > +++ b/tests/cdboot_test.in
> > > > @@ -34,6 +34,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
> > > >  	exit 0;;
> > > >  esac
> > > >
> > > > -if [ "$(echo hello | "${grubshell}" --boot=cd)" != "Hello World" ]; then
> > > > +v=`echo hello | "${grubshell}" --boot=cd`
> > > > +if [ "$v" != "Hello World" ]; then
> > >
> > > ... but this one is not. The grub-shell call is last one here. Hmmm...
> > > Am I missing something?
> >
> > This is the case where the error code is hidden, so 'set -e' doesn't
> > fail as it should.
> >
> > Note how this will not cause the script to error:
> >
> > $ bash -e -c 'if [ "$(echo XXX | ( cat; false ))" == "XXX" ]; then echo
> > `echo $$`; fi'
> >
> > But this will, which is what we want.
> >
> > $ bash -e -c 'v=`echo XXX | ( cat; false )`; if [ "$v" == "XXX" ]; then
> > echo `echo $$`; fi'
> 
> OK, AIUI error code is occluded by '['/test. Right?

Yes, although its not the fault of test. I believe it would be the case
for any "simple command" which uses subshells and one of the subshells
is returning an error exit code. For simple commands, only the exit
code of the primary command is checked for an error code.

For example:

  bash -e -c 'echo "$(echo XXX | ( cat; false ))"; echo ret=$?'

and

  bash -e -c 'cat <<<"$(echo XXX | ( cat; false ))"; echo ret=$?'

> 
> > So yes, this case, where error code is occluded with 'set -e', is not
> > described in the commit message. Should I update the commit message?
> 
> I think this patch should be split into two because these issues are two
> different things.
> 
> Daniel

Ok, I'll split it up.

Glenn


  reply	other threads:[~2021-10-07 15:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25  7:03 [PATCH v2 0/8] Various fixes/improvements for tests Glenn Washburn
2021-08-25  7:03 ` [PATCH v2 1/8] tests: Make sure LANG is set properly for iso9660_test Glenn Washburn
2021-08-25  9:34   ` Thomas Schmitt
2021-08-25 19:49     ` Glenn Washburn
2021-08-26  6:53       ` Thomas Schmitt
2021-08-26 17:06         ` Glenn Washburn
2021-08-26 17:49         ` Thomas Schmitt
2021-08-26 20:16           ` Glenn Washburn
2021-08-26 21:28             ` Thomas Schmitt
2021-08-26 22:30               ` Glenn Washburn
2021-08-27 19:13                 ` Thomas Schmitt
2021-08-27 20:03                   ` Glenn Washburn
2021-08-27 21:23                     ` Thomas Schmitt
2021-08-25  7:03 ` [PATCH v2 2/8] tests: Fix partmap_test for arm*-efi, disk numbering has changed Glenn Washburn
2021-10-06 13:45   ` Daniel Kiper
2021-08-25  7:03 ` [PATCH v2 3/8] tests: When checking squashfs fstime, use superblock last modified time Glenn Washburn
2021-10-06 13:46   ` Daniel Kiper
2021-08-25  7:03 ` [PATCH v2 4/8] tests: Fail immediately when grub-shell fails and do not occlude the error code Glenn Washburn
2021-10-06 13:57   ` Daniel Kiper
2021-10-06 20:05     ` Glenn Washburn
2021-10-07 12:37       ` Daniel Kiper
2021-10-07 15:35         ` Glenn Washburn [this message]
2021-08-25  7:03 ` [PATCH v2 5/8] tests: Make setup errors in grub-fs-tester hard errors Glenn Washburn
2021-10-06 15:26   ` Daniel Kiper
2021-08-25  7:04 ` [PATCH v2 6/8] tests: A failure of mktemp should cause the test script to exit with code 99 Glenn Washburn
2021-10-06 15:28   ` Daniel Kiper
2021-08-25  7:04 ` [PATCH v2 7/8] tests: Exit with skipped exit code when test not performed Glenn Washburn
2021-09-17 21:42   ` Glenn Washburn
2021-10-06 15:34     ` Daniel Kiper
2021-08-25  7:04 ` [PATCH v2 8/8] tests: Use @BUILD_SHEBANG@ autoconf var instead of literal shell Glenn Washburn
2021-10-06 15:37   ` Daniel Kiper

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=20211007103558.6eb0ce3f@crass-HP-ZBook-15-G2 \
    --to=development@efficientek.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.