Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/1] generate_lvm_runfile.sh: Fix bashism
@ 2022-08-03 17:57 Petr Vorel
  2022-08-04 15:33 ` Martin Doucha
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2022-08-03 17:57 UTC (permalink / raw)
  To: ltp; +Cc: linux-nfs

ERR is not on dash (tested on 0.5.11).

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/misc/lvm/generate_lvm_runfile.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/misc/lvm/generate_lvm_runfile.sh b/testcases/misc/lvm/generate_lvm_runfile.sh
index 72b286a69..5bf5d91d6 100755
--- a/testcases/misc/lvm/generate_lvm_runfile.sh
+++ b/testcases/misc/lvm/generate_lvm_runfile.sh
@@ -13,7 +13,7 @@ LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
 
 generate_runfile()
 {
-	trap 'tst_brk TBROK "Cannot create LVM runfile"' ERR
+	trap '[ $? -eq 0 ] && exit 0 || tst_brk TBROK "Cannot create LVM runfile"' EXIT
 	INFILE="$LTPROOT/testcases/data/lvm/runfile.tpl"
 	OUTFILE="$LTPROOT/runtest/lvm.local"
 	FS_LIST=`tst_supported_fs`
-- 
2.37.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH 1/1] generate_lvm_runfile.sh: Fix bashism
  2022-08-03 17:57 [LTP] [PATCH 1/1] generate_lvm_runfile.sh: Fix bashism Petr Vorel
@ 2022-08-04 15:33 ` Martin Doucha
  2022-08-04 20:24   ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Doucha @ 2022-08-04 15:33 UTC (permalink / raw)
  To: Petr Vorel, ltp; +Cc: linux-nfs

Hi,
`trap ... EXIT` cannot be used to emulate `trap ... ERR`. The latter
behaves as if every command/pipeline in the script (except conditions)
were wrapped in ROD. So `trap ... ERR` will trigger exit on any failure,
while `trap ... EXIT` will let the script continue after all errors and
then check exit code of only the very last command. That's not what we
want here.

On 03. 08. 22 19:57, Petr Vorel wrote:
> ERR is not on dash (tested on 0.5.11).
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/misc/lvm/generate_lvm_runfile.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/testcases/misc/lvm/generate_lvm_runfile.sh b/testcases/misc/lvm/generate_lvm_runfile.sh
> index 72b286a69..5bf5d91d6 100755
> --- a/testcases/misc/lvm/generate_lvm_runfile.sh
> +++ b/testcases/misc/lvm/generate_lvm_runfile.sh
> @@ -13,7 +13,7 @@ LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
>  
>  generate_runfile()
>  {
> -	trap 'tst_brk TBROK "Cannot create LVM runfile"' ERR
> +	trap '[ $? -eq 0 ] && exit 0 || tst_brk TBROK "Cannot create LVM runfile"' EXIT
>  	INFILE="$LTPROOT/testcases/data/lvm/runfile.tpl"
>  	OUTFILE="$LTPROOT/runtest/lvm.local"
>  	FS_LIST=`tst_supported_fs`


-- 
Martin Doucha   mdoucha@suse.cz
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH 1/1] generate_lvm_runfile.sh: Fix bashism
  2022-08-04 15:33 ` Martin Doucha
@ 2022-08-04 20:24   ` Petr Vorel
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2022-08-04 20:24 UTC (permalink / raw)
  To: Martin Doucha; +Cc: linux-nfs, ltp

Hi Martin,

> Hi,
> `trap ... EXIT` cannot be used to emulate `trap ... ERR`. The latter
> behaves as if every command/pipeline in the script (except conditions)
> were wrapped in ROD. So `trap ... ERR` will trigger exit on any failure,
Ah, thx for info. OK, we also need to add set -e (or #!/bin/sh -e).
Because using ERR would require to change shebang to #!/bin/bash.

Kind regards,
Petr

> while `trap ... EXIT` will let the script continue after all errors and
> then check exit code of only the very last command. That's not what we
> want here.

> On 03. 08. 22 19:57, Petr Vorel wrote:
> > ERR is not on dash (tested on 0.5.11).

> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> >  testcases/misc/lvm/generate_lvm_runfile.sh | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)

> > diff --git a/testcases/misc/lvm/generate_lvm_runfile.sh b/testcases/misc/lvm/generate_lvm_runfile.sh
> > index 72b286a69..5bf5d91d6 100755
> > --- a/testcases/misc/lvm/generate_lvm_runfile.sh
> > +++ b/testcases/misc/lvm/generate_lvm_runfile.sh
> > @@ -13,7 +13,7 @@ LVM_TMPDIR="$LVM_DIR/ltp/growfiles"

> >  generate_runfile()
> >  {
> > -	trap 'tst_brk TBROK "Cannot create LVM runfile"' ERR
> > +	trap '[ $? -eq 0 ] && exit 0 || tst_brk TBROK "Cannot create LVM runfile"' EXIT
> >  	INFILE="$LTPROOT/testcases/data/lvm/runfile.tpl"
> >  	OUTFILE="$LTPROOT/runtest/lvm.local"
> >  	FS_LIST=`tst_supported_fs`

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-04 20:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-03 17:57 [LTP] [PATCH 1/1] generate_lvm_runfile.sh: Fix bashism Petr Vorel
2022-08-04 15:33 ` Martin Doucha
2022-08-04 20:24   ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox