Skip to contentSkip to conversation

generate_lvm_runfile.sh: Fix bashism

PATCH In review Petr Vorel 2 participants 2 messages Aug 5, 2022

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH v2 1/1 generate_lvm_runfile.sh: Fix bashism

ERR is not on dash (tested on 0.5.11).

---
Changes v1-v2:
* add -e (i.e. set -e)

 testcases/misc/lvm/generate_lvm_runfile.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/misc/lvm/generate_lvm_runfile.sh +3 -2
index 72b286a69..599d6c0e7 100755
@@ -1,6 +1,7 @@
-#!/bin/sh
+#!/bin/sh -e
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2020 SUSE LLC <[email protected]>
+# 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`
Signature · 5 lines
2.36.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

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.

Quoted 32 lines · Petr Vorel

ERR is not on dash (tested on 0.5.11).

---
Changes v1-v2:
* add -e (i.e. set -e)

 testcases/misc/lvm/generate_lvm_runfile.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/misc/lvm/generate_lvm_runfile.sh +3 -2
index 72b286a69..599d6c0e7 100755
@@ -1,6 +1,7 @@
-#!/bin/sh
+#!/bin/sh -e
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2020 SUSE LLC <[email protected]>
+# 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`
Signature · 10 lines
Martin Doucha   [email protected]
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