[LTP] [PATCH v2 1/1] generate_lvm_runfile.sh: Fix bashism

Martin Doucha mdoucha@suse.cz
Fri Aug 5 15:34:34 CEST 2022


Hi,
yes, running shell with -e would work. But there's a problem that
tst_test.sh currently fails to initialize in that shell mode. I've
tracked the problem down to incorrect use of tst_color_enabled() inside
tst_res() - the call needs to be wrapped in an `if ... then` to work
correctly under /bin/sh -e.

One more thing, the `exit 0` is unnecessary in the trap. This would work
just fine:
[ $? -eq 0 ] || tst_brk TBROK ...

And a comment explaining the need for `/bin/sh -e` would be useful.

On 05. 08. 22 9:05, Petr Vorel wrote:
> ERR is not on dash (tested on 0.5.11).
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Changes v1-v2:
> * add -e (i.e. set -e)
> 
>  testcases/misc/lvm/generate_lvm_runfile.sh | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/misc/lvm/generate_lvm_runfile.sh b/testcases/misc/lvm/generate_lvm_runfile.sh
> index 72b286a69..599d6c0e7 100755
> --- a/testcases/misc/lvm/generate_lvm_runfile.sh
> +++ b/testcases/misc/lvm/generate_lvm_runfile.sh
> @@ -1,6 +1,7 @@
> -#!/bin/sh
> +#!/bin/sh -e
>  # SPDX-License-Identifier: GPL-2.0-or-later
>  # Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz>
> +# Copyright (c) Linux Test Project, 2022
>  #
>  # Generate LTP runfile for LVM tests (runtest/lvm.local)
>  
> @@ -13,7 +14,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


More information about the ltp mailing list