[LTP] [RFC PATCH 3/5] shell: Move shell code into functions
Petr Vorel
pvorel@suse.cz
Fri Feb 28 18:24:36 CET 2025
This is a preparation to make next changes smaller.
No functional changes.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
nit: maybe use local + lower case variables in vma05.sh?
testcases/kernel/mem/vma/vma05.sh | 45 ++++++++++---------
testcases/lib/tests/shell_loader.sh | 19 +++++---
.../lib/tests/shell_loader_all_filesystems.sh | 26 ++++++-----
.../lib/tests/shell_loader_brk_cleanup.sh | 7 ++-
testcases/lib/tests/shell_loader_c_child.sh | 15 ++++---
testcases/lib/tests/shell_loader_cleanup.sh | 7 ++-
.../lib/tests/shell_loader_filesystems.sh | 23 ++++++----
.../lib/tests/shell_loader_invalid_block.sh | 7 ++-
.../tests/shell_loader_invalid_metadata.sh | 7 ++-
testcases/lib/tests/shell_loader_kconfigs.sh | 7 ++-
.../lib/tests/shell_loader_no_metadata.sh | 7 ++-
.../lib/tests/shell_loader_supported_archs.sh | 7 ++-
testcases/lib/tests/shell_loader_tags.sh | 7 ++-
testcases/lib/tests/shell_loader_tcnt.sh | 7 ++-
.../lib/tests/shell_loader_wrong_metadata.sh | 7 ++-
15 files changed, 137 insertions(+), 61 deletions(-)
diff --git a/testcases/kernel/mem/vma/vma05.sh b/testcases/kernel/mem/vma/vma05.sh
index f4c76b7034..11d6b2ad86 100755
--- a/testcases/kernel/mem/vma/vma05.sh
+++ b/testcases/kernel/mem/vma/vma05.sh
@@ -41,29 +41,34 @@
. tst_loader.sh
-ulimit -c unlimited
-unset DEBUGINFOD_URLS
+tst_test()
+{
+ ulimit -c unlimited
+ unset DEBUGINFOD_URLS
-if [ $(uname -m) = "x86_64" ]; then
- if LINE=$(grep "vsyscall" /proc/self/maps); then
- RIGHT="ffffffffff600000-ffffffffff601000[[:space:]][r-]-xp"
- if echo "$LINE" | grep -q "$RIGHT"; then
- tst_res TPASS "[vsyscall] reported correctly"
- else
- tst_res TFAIL "[vsyscall] reporting wrong"
+ if [ $(uname -m) = "x86_64" ]; then
+ if LINE=$(grep "vsyscall" /proc/self/maps); then
+ RIGHT="ffffffffff600000-ffffffffff601000[[:space:]][r-]-xp"
+ if echo "$LINE" | grep -q "$RIGHT"; then
+ tst_res TPASS "[vsyscall] reported correctly"
+ else
+ tst_res TFAIL "[vsyscall] reporting wrong"
+ fi
fi
fi
-fi
-rm -rf core*
-{ vma05_vdso; } > /dev/null 2>&1
-[ -f core ] || tst_brk TBROK "missing core file"
+ rm -rf core*
+ { vma05_vdso; } > /dev/null 2>&1
+ [ -f core ] || tst_brk TBROK "missing core file"
-TRACE=$(gdb -silent -ex="thread apply all backtrace" -ex="quit"\
- vma05_vdso ./core* 2> /dev/null)
+ TRACE=$(gdb -silent -ex="thread apply all backtrace" -ex="quit"\
+ vma05_vdso ./core* 2> /dev/null)
-if echo "$TRACE" | grep -qF "??"; then
- tst_res TFAIL "[vdso] bug not patched"
-else
- tst_res TPASS "[vdso] backtrace complete"
-fi
+ if echo "$TRACE" | grep -qF "??"; then
+ tst_res TFAIL "[vdso] bug not patched"
+ else
+ tst_res TPASS "[vdso] backtrace complete"
+ fi
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader.sh b/testcases/lib/tests/shell_loader.sh
index a7c5848ff5..73812c3e23 100755
--- a/testcases/lib/tests/shell_loader.sh
+++ b/testcases/lib/tests/shell_loader.sh
@@ -16,10 +16,15 @@
. tst_loader.sh
-tst_res TPASS "Shell loader works fine!"
-case "$PWD" in
- /tmp/*)
- tst_res TPASS "We are running in temp directory in $PWD";;
- *)
- tst_res TFAIL "We are not running in temp directory but $PWD";;
-esac
+tst_test()
+{
+ tst_res TPASS "Shell loader works fine!"
+ case "$PWD" in
+ /tmp/*)
+ tst_res TPASS "We are running in temp directory in $PWD";;
+ *)
+ tst_res TFAIL "We are not running in temp directory but $PWD";;
+ esac
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_all_filesystems.sh b/testcases/lib/tests/shell_loader_all_filesystems.sh
index 91fac89fd6..33c73dfb41 100755
--- a/testcases/lib/tests/shell_loader_all_filesystems.sh
+++ b/testcases/lib/tests/shell_loader_all_filesystems.sh
@@ -14,16 +14,22 @@
. tst_loader.sh
-tst_res TINFO "In shell"
+tst_test()
+{
+ local mntpath=$(realpath ltp_mntpoint)
+ local mounted=$(grep $mntpath /proc/mounts)
+ local device path
-mntpath=$(realpath ltp_mntpoint)
-mounted=$(grep $mntpath /proc/mounts)
+ tst_res TINFO "In shell"
-if [ -n "$mounted" ]; then
- device=$(echo $mounted |cut -d' ' -f 1)
- path=$(echo $mounted |cut -d' ' -f 2)
+ if [ -n "$mounted" ]; then
+ device=$(echo $mounted |cut -d' ' -f 1)
+ path=$(echo $mounted |cut -d' ' -f 2)
- tst_res TPASS "$device mounted at $path"
-else
- tst_res TFAIL "Device not mounted!"
-fi
+ tst_res TPASS "$device mounted at $path"
+ else
+ tst_res TFAIL "Device not mounted!"
+ fi
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_brk_cleanup.sh b/testcases/lib/tests/shell_loader_brk_cleanup.sh
index 8c704a5406..ff33345ce3 100755
--- a/testcases/lib/tests/shell_loader_brk_cleanup.sh
+++ b/testcases/lib/tests/shell_loader_brk_cleanup.sh
@@ -17,4 +17,9 @@ cleanup()
tst_res TINFO "Cleanup runs"
}
-tst_brk TBROK "Test exits"
+tst_test()
+{
+ tst_brk TBROK "Test exits"
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_c_child.sh b/testcases/lib/tests/shell_loader_c_child.sh
index 34629e6d26..b2b8f3d057 100755
--- a/testcases/lib/tests/shell_loader_c_child.sh
+++ b/testcases/lib/tests/shell_loader_c_child.sh
@@ -15,9 +15,14 @@
. tst_loader.sh
-if [ -n "LTP_IPC_PATH" ]; then
- tst_res TPASS "LTP_IPC_PATH=$LTP_IPC_PATH!"
-fi
+tst_test()
+{
+ if [ -n "LTP_IPC_PATH" ]; then
+ tst_res TPASS "LTP_IPC_PATH=$LTP_IPC_PATH!"
+ fi
-tst_res TINFO "Running C child"
-shell_c_child
+ tst_res TINFO "Running C child"
+ shell_c_child
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_cleanup.sh b/testcases/lib/tests/shell_loader_cleanup.sh
index fb7bbdf5a9..684901b51f 100755
--- a/testcases/lib/tests/shell_loader_cleanup.sh
+++ b/testcases/lib/tests/shell_loader_cleanup.sh
@@ -17,4 +17,9 @@ do_cleanup()
tst_res TINFO "Cleanup executed"
}
-tst_res TPASS "Test is executed"
+tst_test()
+{
+ tst_res TPASS "Test is executed"
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_filesystems.sh b/testcases/lib/tests/shell_loader_filesystems.sh
index fe61708004..155cc4d9f6 100755
--- a/testcases/lib/tests/shell_loader_filesystems.sh
+++ b/testcases/lib/tests/shell_loader_filesystems.sh
@@ -21,15 +21,20 @@
. tst_loader.sh
-tst_res TINFO "In shell"
+tst_test()
+{
+ tst_res TINFO "In shell"
-mntpoint=$(realpath ltp_mntpoint)
-mounted=$(grep $mntpoint /proc/mounts)
+ mntpoint=$(realpath ltp_mntpoint)
+ mounted=$(grep $mntpoint /proc/mounts)
-if [ -n "$mounted" ]; then
- fs=$(echo $mounted |cut -d' ' -f 3)
+ if [ -n "$mounted" ]; then
+ fs=$(echo $mounted |cut -d' ' -f 3)
- tst_res TPASS "Mounted device formatted with $fs"
-else
- tst_res TFAIL "Device not mounted!"
-fi
+ tst_res TPASS "Mounted device formatted with $fs"
+ else
+ tst_res TFAIL "Device not mounted!"
+ fi
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_invalid_block.sh b/testcases/lib/tests/shell_loader_invalid_block.sh
index 01811c971d..370c9043bc 100755
--- a/testcases/lib/tests/shell_loader_invalid_block.sh
+++ b/testcases/lib/tests/shell_loader_invalid_block.sh
@@ -22,4 +22,9 @@
. tst_loader.sh
-tst_res TPASS "This should pass!"
+tst_test()
+{
+ tst_res TPASS "This should pass!"
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_invalid_metadata.sh b/testcases/lib/tests/shell_loader_invalid_metadata.sh
index aeae066841..3834f1b9ed 100755
--- a/testcases/lib/tests/shell_loader_invalid_metadata.sh
+++ b/testcases/lib/tests/shell_loader_invalid_metadata.sh
@@ -14,4 +14,9 @@
. tst_loader.sh
-tst_res TFAIL "Shell loader should TBROK the test"
+tst_test()
+{
+ tst_res TFAIL "Shell loader should TBROK the test"
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_kconfigs.sh b/testcases/lib/tests/shell_loader_kconfigs.sh
index b896f03ce0..e1b6187554 100755
--- a/testcases/lib/tests/shell_loader_kconfigs.sh
+++ b/testcases/lib/tests/shell_loader_kconfigs.sh
@@ -11,4 +11,9 @@
. tst_loader.sh
-tst_res TPASS "Shell loader works fine!"
+tst_test()
+{
+ tst_res TPASS "Shell loader works fine!"
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_no_metadata.sh b/testcases/lib/tests/shell_loader_no_metadata.sh
index e344327ed3..b664b48b57 100755
--- a/testcases/lib/tests/shell_loader_no_metadata.sh
+++ b/testcases/lib/tests/shell_loader_no_metadata.sh
@@ -7,4 +7,9 @@
. tst_loader.sh
-tst_res TFAIL "Shell loader should TBROK the test"
+tst_test()
+{
+ tst_res TFAIL "Shell loader should TBROK the test"
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_supported_archs.sh b/testcases/lib/tests/shell_loader_supported_archs.sh
index 45f0b1b1c2..9ad24f9c03 100755
--- a/testcases/lib/tests/shell_loader_supported_archs.sh
+++ b/testcases/lib/tests/shell_loader_supported_archs.sh
@@ -11,4 +11,9 @@
. tst_loader.sh
-tst_res TPASS "We are running on supported architecture"
+tst_test()
+{
+ tst_res TPASS "We are running on supported architecture"
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_tags.sh b/testcases/lib/tests/shell_loader_tags.sh
index 0b9416ea9a..c780a66c57 100755
--- a/testcases/lib/tests/shell_loader_tags.sh
+++ b/testcases/lib/tests/shell_loader_tags.sh
@@ -14,4 +14,9 @@
. tst_loader.sh
-tst_res TFAIL "Fails the test so that tags are shown."
+tst_test()
+{
+ tst_res TFAIL "Fails the test so that tags are shown."
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_tcnt.sh b/testcases/lib/tests/shell_loader_tcnt.sh
index ecf48396d6..93bd612ee2 100755
--- a/testcases/lib/tests/shell_loader_tcnt.sh
+++ b/testcases/lib/tests/shell_loader_tcnt.sh
@@ -14,4 +14,9 @@
. tst_loader.sh
-tst_res TPASS "Iteration $1"
+tst_test()
+{
+ tst_res TPASS "Iteration $1"
+}
+
+tst_test
diff --git a/testcases/lib/tests/shell_loader_wrong_metadata.sh b/testcases/lib/tests/shell_loader_wrong_metadata.sh
index b90b212371..8f18741100 100755
--- a/testcases/lib/tests/shell_loader_wrong_metadata.sh
+++ b/testcases/lib/tests/shell_loader_wrong_metadata.sh
@@ -14,4 +14,9 @@
. tst_loader.sh
-tst_res TFAIL "Shell loader should TBROK the test"
+tst_test()
+{
+ tst_res TFAIL "Shell loader should TBROK the test"
+}
+
+tst_test
--
2.47.2
More information about the ltp
mailing list