[LTP] [PATCH v3 2/5] shell: Use conditional expansion for library setup/cleanup
Petr Vorel
pvorel@suse.cz
Wed Apr 27 14:50:00 CEST 2022
To avoid surprises when test specific setup/cleanup function is
redefined by shell library.
Although there is not an optimal general solution because usually test
which have specific setup/cleanup also needs to call library setup/cleanup,
but it's better not to require TST_{SETUP,CLEANUP} to be on specific place.
Added to all shell libraries, regardless it's required or not.
Suggested-by: Martin Doucha <mdoucha@suse.cz>
Reviewed-by: Martin Doucha <mdoucha@suse.cz>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
changes v2->v3:
* remove copyright only changes
* busy_poll_lib.sh: revert conditional expansion (note that
setup/cleanup defined by test was added in previous commit)
testcases/kernel/controllers/memcg/functional/memcg_lib.sh | 4 ++--
testcases/kernel/device-drivers/zram/zram_lib.sh | 6 +++---
testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh | 4 ++--
testcases/kernel/fs/fs_bind/fs_bind_lib.sh | 4 ++--
testcases/network/dhcp/dhcp_lib.sh | 6 +++---
testcases/network/stress/interface/if-lib.sh | 7 +++++--
testcases/network/virt/macsec_lib.sh | 6 +++---
7 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
index 1b76b6597..db010acc7 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
@@ -10,8 +10,8 @@ TST_NEEDS_CHECKPOINTS=1
TST_NEEDS_ROOT=1
TST_NEEDS_TMPDIR=1
TST_NEEDS_CMDS="killall find kill"
-TST_CLEANUP=memcg_cleanup
-TST_SETUP=memcg_setup
+TST_SETUP="${TST_SETUP:-memcg_setup}"
+TST_CLEANUP="${TST_CLEANUP:-memcg_cleanup}"
TST_TESTFUNC=memcg_testfunc
MEMCG_SHMMAX=${MEMCG_SHMMAX:-0}
diff --git a/testcases/kernel/device-drivers/zram/zram_lib.sh b/testcases/kernel/device-drivers/zram/zram_lib.sh
index a420fb672..803fd9825 100755
--- a/testcases/kernel/device-drivers/zram/zram_lib.sh
+++ b/testcases/kernel/device-drivers/zram/zram_lib.sh
@@ -1,6 +1,6 @@
#!/bin/sh
# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
dev_makeswap=-1
@@ -12,8 +12,8 @@ sys_control=-1
TST_NEEDS_TMPDIR=1
TST_NEEDS_ROOT=1
-TST_SETUP="zram_load"
-TST_CLEANUP="zram_cleanup"
+TST_SETUP="${TST_SETUP:-zram_load}"
+TST_CLEANUP="${TST_CLEANUP:-zram_cleanup}"
TST_NEEDS_DRIVERS="zram"
. tst_test.sh
diff --git a/testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh b/testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh
index 497682531..ff862db43 100755
--- a/testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh
+++ b/testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh
@@ -4,8 +4,8 @@
# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
# Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
-TST_SETUP=binfmt_misc_setup
-TST_CLEANUP=binfmt_misc_cleanup
+TST_SETUP="${TST_SETUP:-binfmt_misc_setup}"
+TST_CLEANUP="${TST_CLEANUP:-binfmt_misc_cleanup}"
TST_NEEDS_DRIVERS="binfmt_misc"
TST_NEEDS_TMPDIR=1
TST_NEEDS_ROOT=1
diff --git a/testcases/kernel/fs/fs_bind/fs_bind_lib.sh b/testcases/kernel/fs/fs_bind/fs_bind_lib.sh
index a5356fa36..6676d1021 100644
--- a/testcases/kernel/fs/fs_bind/fs_bind_lib.sh
+++ b/testcases/kernel/fs/fs_bind/fs_bind_lib.sh
@@ -7,8 +7,8 @@
TST_NEEDS_TMPDIR=1
TST_NEEDS_ROOT=1
TST_MIN_KVER=2.6.15
-TST_SETUP=fs_bind_setup
-TST_CLEANUP=fs_bind_cleanup
+TST_SETUP="${TST_SETUP:-fs_bind_setup}"
+TST_CLEANUP="${TST_CLEANUP:-fs_bind_cleanup}"
TST_TESTFUNC=fs_bind_test
TST_NEEDS_CMDS="mount umount awk sed"
diff --git a/testcases/network/dhcp/dhcp_lib.sh b/testcases/network/dhcp/dhcp_lib.sh
index 5537112c8..ebee0c2e9 100755
--- a/testcases/network/dhcp/dhcp_lib.sh
+++ b/testcases/network/dhcp/dhcp_lib.sh
@@ -1,11 +1,11 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2014-2018 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
# Author: Alexey Kodanev alexey.kodanev@oracle.com
-TST_SETUP="dhcp_lib_setup"
-TST_CLEANUP="dhcp_lib_cleanup"
+TST_SETUP="${TST_SETUP:-dhcp_lib_setup}"
+TST_CLEANUP="${TST_CLEANUP:-dhcp_lib_cleanup}"
TST_TESTFUNC="test01"
TST_NEEDS_TMPDIR=1
TST_NEEDS_ROOT=1
diff --git a/testcases/network/stress/interface/if-lib.sh b/testcases/network/stress/interface/if-lib.sh
index b398be1ad..2b1db6e00 100644
--- a/testcases/network/stress/interface/if-lib.sh
+++ b/testcases/network/stress/interface/if-lib.sh
@@ -5,7 +5,11 @@
CMD="${CMD:-ip}"
-TST_SETUP="${TST_SETUP:-if_setup}"
+if [ -z "$TST_SETUP" ]; then
+ TST_SETUP="if_setup"
+ TST_CLEANUP="${TST_CLEANUP:-netstress_cleanup}"
+fi
+
TST_TESTFUNC="test_body"
TST_PARSE_ARGS="if_parse_args"
TST_USAGE="if_usage"
@@ -32,7 +36,6 @@ if_setup()
tst_require_cmds "$CMD"
netstress_setup
- TST_CLEANUP="${TST_CLEANUP:-netstress_cleanup}"
}
if_cleanup_restore()
diff --git a/testcases/network/virt/macsec_lib.sh b/testcases/network/virt/macsec_lib.sh
index c2573c572..ac77f0976 100755
--- a/testcases/network/virt/macsec_lib.sh
+++ b/testcases/network/virt/macsec_lib.sh
@@ -1,6 +1,6 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
@@ -10,8 +10,8 @@ IPSEC_MODE="transport"
TST_NEEDS_TMPDIR=1
TST_TESTFUNC=virt_netperf_msg_sizes
-TST_SETUP=macsec_lib_setup
-TST_CLEANUP=macsec_lib_cleanup
+TST_SETUP="${TST_SETUP:-macsec_lib_setup}"
+TST_CLEANUP="${TST_CLEANUP:-macsec_lib_cleanup}"
TST_NEEDS_DRIVERS="macsec"
. ipsec_lib.sh
. virt_lib.sh
--
2.35.3
More information about the ltp
mailing list