* [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP
@ 2025-04-30 13:04 Petr Vorel
2025-04-30 13:04 ` [LTP] [PATCH v2 1/4] shell lib: Add support for test cleanup Petr Vorel
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Petr Vorel @ 2025-04-30 13:04 UTC (permalink / raw)
To: ltp
Hi Cyril, all,
we are getting there, but not yet finished.
one remaining problem - it requires *full* path in PATH. I wonder what
basic I'm missing. The current change requires to use full path
otherwise execvpe() fails.
I suppose it is due change cwd due creating temporary directory - it
fails only with:
"needs_tmpdir": true
shell_loader_setup_cleanup.sh does not suffer this problem.
It's also not dash related, problem is on bash as well.
# PATH="testcases/lib:testcases/lib/tests:$PATH" shell_loader.sh
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_sheQVjoS6 as tmpdir (tmpfs filesystem)
tst_test.c:1903: TINFO: LTP version: 20250130-250-g344e47016d
...
tst_test.c:1720: TINFO: Overall timeout per run is 0h 00m 30s
tst_test.c:218: TBROK: execvpe(shell_loader.sh, ...) failed!: ENOENT (2)
NOTE: export PATH does not help.
# export PATH="testcases/lib:testcases/lib/tests:$PATH"
# shell_loader.sh
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_sheQVjoS6 as tmpdir (tmpfs filesystem)
tst_test.c:1903: TINFO: LTP version: 20250130-250-g344e47016d
...
tst_test.c:1720: TINFO: Overall timeout per run is 0h 00m 30s
tst_test.c:218: TBROK: execvpe(shell_loader.sh, ...) failed!: ENOENT (2)
Full path helps:
# PATH="/opt/ltp/testcases/bin:$PATH" shell_loader.sh
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_shejdXdvf as tmpdir (tmpfs filesystem)
tst_test.c:1903: TINFO: LTP version: 20250130-250-g344e47016d
...
tst_test.c:1720: TINFO: Overall timeout per run is 0h 00m 30s
shell_loader.sh:-1: TPASS: Shell loader works fine!
shell_loader.sh:-1: TPASS: We are running in temp directory in /tmp/LTP_shejdXdvf
And yes, we have -1 on dash, but as you noted in tst_env.sh we can do
nothing about it.
Changes v1->v2:
* use tst_env.sh also in tests instead using tst_exec.sh in
tst_run_shell.c. Therefore remove "lib: Allow test to have positional
args" commit.
Link to v1:
https://patchwork.ozlabs.org/project/ltp/list/?series=446566&state=*
https://lore.kernel.org/ltp/20250228172439.3276777-1-pvorel@suse.cz/
Cyril Hrubis (1):
shell lib: Add support for test cleanup
Petr Vorel (3):
shell: Move shell code into functions
shell lib: Add basic support for test setup
shell: Add shell_loader_setup_cleanup.sh test
testcases/kernel/mem/vma/vma05.sh | 47 ++++++++++---------
testcases/lib/run_tests.sh | 5 +-
testcases/lib/tests/shell_loader.sh | 21 +++++----
.../lib/tests/shell_loader_all_filesystems.sh | 28 ++++++-----
.../lib/tests/shell_loader_brk_cleanup.sh | 25 ++++++++++
testcases/lib/tests/shell_loader_c_child.sh | 17 ++++---
testcases/lib/tests/shell_loader_cleanup.sh | 25 ++++++++++
.../lib/tests/shell_loader_filesystems.sh | 25 ++++++----
.../lib/tests/shell_loader_invalid_block.sh | 9 +++-
.../tests/shell_loader_invalid_metadata.sh | 9 +++-
testcases/lib/tests/shell_loader_kconfigs.sh | 9 +++-
.../lib/tests/shell_loader_no_metadata.sh | 9 +++-
.../lib/tests/shell_loader_setup_cleanup.sh | 31 ++++++++++++
.../lib/tests/shell_loader_supported_archs.sh | 9 +++-
testcases/lib/tests/shell_loader_tags.sh | 9 +++-
testcases/lib/tests/shell_loader_tcnt.sh | 9 +++-
.../lib/tests/shell_loader_wrong_metadata.sh | 9 +++-
testcases/lib/tst_env.sh | 5 --
testcases/lib/tst_loader.sh | 15 ++++--
19 files changed, 235 insertions(+), 81 deletions(-)
create mode 100755 testcases/lib/tests/shell_loader_brk_cleanup.sh
create mode 100755 testcases/lib/tests/shell_loader_cleanup.sh
create mode 100755 testcases/lib/tests/shell_loader_setup_cleanup.sh
--
2.49.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH v2 1/4] shell lib: Add support for test cleanup
2025-04-30 13:04 [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Petr Vorel
@ 2025-04-30 13:04 ` Petr Vorel
2025-04-30 13:04 ` [LTP] [PATCH v2 2/4] shell: Move shell code into functions Petr Vorel
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2025-04-30 13:04 UTC (permalink / raw)
To: ltp
From: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/lib/run_tests.sh | 4 +++-
.../lib/tests/shell_loader_brk_cleanup.sh | 20 +++++++++++++++++++
testcases/lib/tests/shell_loader_cleanup.sh | 20 +++++++++++++++++++
testcases/lib/tst_env.sh | 4 ++++
4 files changed, 47 insertions(+), 1 deletion(-)
create mode 100755 testcases/lib/tests/shell_loader_brk_cleanup.sh
create mode 100755 testcases/lib/tests/shell_loader_cleanup.sh
diff --git a/testcases/lib/run_tests.sh b/testcases/lib/run_tests.sh
index 321f74e5fe..128cee3377 100755
--- a/testcases/lib/run_tests.sh
+++ b/testcases/lib/run_tests.sh
@@ -9,6 +9,7 @@ shell_loader_filesystems.sh
shell_loader_kconfigs.sh
shell_loader_supported_archs.sh
shell_loader_tcnt.sh
+shell_loader_cleanup.sh
shell_test01
shell_test02
shell_test03
@@ -21,7 +22,8 @@ TESTS_TBROK="
shell_loader_invalid_block.sh
shell_loader_invalid_metadata.sh
shell_loader_no_metadata.sh
-shell_loader_wrong_metadata.sh"
+shell_loader_wrong_metadata.sh
+shell_loader_brk_cleanup.sh"
TESTS_TCONF="shell_test06"
diff --git a/testcases/lib/tests/shell_loader_brk_cleanup.sh b/testcases/lib/tests/shell_loader_brk_cleanup.sh
new file mode 100755
index 0000000000..8c704a5406
--- /dev/null
+++ b/testcases/lib/tests/shell_loader_brk_cleanup.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2024-2025 Cyril Hrubis <chrubis@suse.cz>
+#
+# ---
+# env
+# {
+# }
+# ---
+
+TST_CLEANUP=cleanup
+
+. tst_loader.sh
+
+cleanup()
+{
+ tst_res TINFO "Cleanup runs"
+}
+
+tst_brk TBROK "Test exits"
diff --git a/testcases/lib/tests/shell_loader_cleanup.sh b/testcases/lib/tests/shell_loader_cleanup.sh
new file mode 100755
index 0000000000..fb7bbdf5a9
--- /dev/null
+++ b/testcases/lib/tests/shell_loader_cleanup.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2024-2025 Cyril Hrubis <chrubis@suse.cz>
+#
+# ---
+# env
+# {
+# }
+# ---
+
+TST_CLEANUP=do_cleanup
+
+. tst_loader.sh
+
+do_cleanup()
+{
+ tst_res TINFO "Cleanup executed"
+}
+
+tst_res TPASS "Test is executed"
diff --git a/testcases/lib/tst_env.sh b/testcases/lib/tst_env.sh
index 68f9a0daa9..b13bab37c3 100644
--- a/testcases/lib/tst_env.sh
+++ b/testcases/lib/tst_env.sh
@@ -35,3 +35,7 @@ tst_brk_()
alias tst_res="tst_res_ $tst_script_name \$LINENO"
alias tst_brk="tst_brk_ $tst_script_name \$LINENO"
+
+if [ -n "$TST_CLEANUP" ]; then
+ trap $TST_CLEANUP EXIT
+fi
--
2.49.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [LTP] [PATCH v2 2/4] shell: Move shell code into functions
2025-04-30 13:04 [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Petr Vorel
2025-04-30 13:04 ` [LTP] [PATCH v2 1/4] shell lib: Add support for test cleanup Petr Vorel
@ 2025-04-30 13:04 ` Petr Vorel
2025-05-02 9:26 ` Cyril Hrubis
2025-04-30 13:04 ` [LTP] [PATCH v2 3/4] shell lib: Add basic support for test setup Petr Vorel
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2025-04-30 13:04 UTC (permalink / raw)
To: ltp
This is a preparation to make next changes smaller.
No functional changes.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
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 b7e1f9ba49..b2c9d2f7d1 100755
--- a/testcases/lib/tests/shell_loader_filesystems.sh
+++ b/testcases/lib/tests/shell_loader_filesystems.sh
@@ -24,15 +24,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.49.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [LTP] [PATCH v2 3/4] shell lib: Add basic support for test setup
2025-04-30 13:04 [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Petr Vorel
2025-04-30 13:04 ` [LTP] [PATCH v2 1/4] shell lib: Add support for test cleanup Petr Vorel
2025-04-30 13:04 ` [LTP] [PATCH v2 2/4] shell: Move shell code into functions Petr Vorel
@ 2025-04-30 13:04 ` Petr Vorel
2025-05-02 9:36 ` Cyril Hrubis
2025-04-30 13:04 ` [LTP] [PATCH v2 4/4] shell: Add shell_loader_setup_cleanup.sh test Petr Vorel
2025-05-02 8:51 ` [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Cyril Hrubis
4 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2025-04-30 13:04 UTC (permalink / raw)
To: ltp
Add basic support for test cleanup in shell loader.
This required to:
* Source tst_env.sh also in the tests before test/setup/cleanup functions,
otherwise tst_res alias would not be found:
tests/shell_loader_setup_cleanup.sh: 22: tst_res: not found
* Move sourcing tst_loader.sh at the end of the test (after
test/setup/cleanup functions), otherwise test/setup/cleanup would not be found:
tests/shell_loader_setup_cleanup.sh: 19: testcases/lib/tst_loader.sh: setup: not found
tests/shell_loader_setup_cleanup.sh: 22: testcases/lib/tst_loader.sh: tst_test: not found
This solves the problem of the order the scripts are sourced. Before it was:
test.sh
. tst_loader.sh
tst_run_shell test.sh
. tst_loader.sh
. tst_env.sh <- at this point in the execution it haven't even started parsing
test.sh so it cannot run functions from there at all
Now:
test.sh
. tst_env.sh
. tst_loader.sh
tst_run_shell test.sh
. tst_env.sh
. tst_loader.sh
There will be more improvements in the future, at least adding TST_CNT
support (will require changes in tst_test.c to handle timeouts).
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Co-developed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/kernel/mem/vma/vma05.sh | 4 ++--
testcases/lib/tests/shell_loader.sh | 4 ++--
.../lib/tests/shell_loader_all_filesystems.sh | 4 ++--
testcases/lib/tests/shell_loader_brk_cleanup.sh | 4 ++--
testcases/lib/tests/shell_loader_c_child.sh | 4 ++--
testcases/lib/tests/shell_loader_cleanup.sh | 4 ++--
testcases/lib/tests/shell_loader_filesystems.sh | 4 ++--
testcases/lib/tests/shell_loader_invalid_block.sh | 4 ++--
.../lib/tests/shell_loader_invalid_metadata.sh | 4 ++--
testcases/lib/tests/shell_loader_kconfigs.sh | 4 ++--
testcases/lib/tests/shell_loader_no_metadata.sh | 4 ++--
.../lib/tests/shell_loader_supported_archs.sh | 4 ++--
testcases/lib/tests/shell_loader_tags.sh | 4 ++--
testcases/lib/tests/shell_loader_tcnt.sh | 4 ++--
.../lib/tests/shell_loader_wrong_metadata.sh | 4 ++--
testcases/lib/tst_env.sh | 9 ---------
testcases/lib/tst_loader.sh | 15 ++++++++++++---
17 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/testcases/kernel/mem/vma/vma05.sh b/testcases/kernel/mem/vma/vma05.sh
index 11d6b2ad86..e7780e8957 100755
--- a/testcases/kernel/mem/vma/vma05.sh
+++ b/testcases/kernel/mem/vma/vma05.sh
@@ -39,7 +39,7 @@
# }
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
@@ -71,4 +71,4 @@ tst_test()
fi
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader.sh b/testcases/lib/tests/shell_loader.sh
index 73812c3e23..01acf6d352 100755
--- a/testcases/lib/tests/shell_loader.sh
+++ b/testcases/lib/tests/shell_loader.sh
@@ -14,7 +14,7 @@
# }
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
@@ -27,4 +27,4 @@ tst_test()
esac
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_all_filesystems.sh b/testcases/lib/tests/shell_loader_all_filesystems.sh
index 33c73dfb41..1a54b2d81c 100755
--- a/testcases/lib/tests/shell_loader_all_filesystems.sh
+++ b/testcases/lib/tests/shell_loader_all_filesystems.sh
@@ -12,7 +12,7 @@
# }
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
@@ -32,4 +32,4 @@ tst_test()
fi
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_brk_cleanup.sh b/testcases/lib/tests/shell_loader_brk_cleanup.sh
index ff33345ce3..95303d6409 100755
--- a/testcases/lib/tests/shell_loader_brk_cleanup.sh
+++ b/testcases/lib/tests/shell_loader_brk_cleanup.sh
@@ -10,7 +10,7 @@
TST_CLEANUP=cleanup
-. tst_loader.sh
+. tst_env.sh
cleanup()
{
@@ -22,4 +22,4 @@ tst_test()
tst_brk TBROK "Test exits"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_c_child.sh b/testcases/lib/tests/shell_loader_c_child.sh
index b2b8f3d057..c33decb1df 100755
--- a/testcases/lib/tests/shell_loader_c_child.sh
+++ b/testcases/lib/tests/shell_loader_c_child.sh
@@ -13,7 +13,7 @@
# }
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
@@ -25,4 +25,4 @@ tst_test()
shell_c_child
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_cleanup.sh b/testcases/lib/tests/shell_loader_cleanup.sh
index 684901b51f..4918df5ff2 100755
--- a/testcases/lib/tests/shell_loader_cleanup.sh
+++ b/testcases/lib/tests/shell_loader_cleanup.sh
@@ -10,7 +10,7 @@
TST_CLEANUP=do_cleanup
-. tst_loader.sh
+. tst_env.sh
do_cleanup()
{
@@ -22,4 +22,4 @@ tst_test()
tst_res TPASS "Test is executed"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_filesystems.sh b/testcases/lib/tests/shell_loader_filesystems.sh
index b2c9d2f7d1..98466b918c 100755
--- a/testcases/lib/tests/shell_loader_filesystems.sh
+++ b/testcases/lib/tests/shell_loader_filesystems.sh
@@ -22,7 +22,7 @@
# }
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
@@ -40,4 +40,4 @@ tst_test()
fi
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_invalid_block.sh b/testcases/lib/tests/shell_loader_invalid_block.sh
index 370c9043bc..d2f5dc564f 100755
--- a/testcases/lib/tests/shell_loader_invalid_block.sh
+++ b/testcases/lib/tests/shell_loader_invalid_block.sh
@@ -20,11 +20,11 @@
# This is an invalid block that breaks the test.
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
tst_res TPASS "This should pass!"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_invalid_metadata.sh b/testcases/lib/tests/shell_loader_invalid_metadata.sh
index 3834f1b9ed..52b3e69695 100755
--- a/testcases/lib/tests/shell_loader_invalid_metadata.sh
+++ b/testcases/lib/tests/shell_loader_invalid_metadata.sh
@@ -12,11 +12,11 @@
# ---
#
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
tst_res TFAIL "Shell loader should TBROK the test"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_kconfigs.sh b/testcases/lib/tests/shell_loader_kconfigs.sh
index e1b6187554..61222ba115 100755
--- a/testcases/lib/tests/shell_loader_kconfigs.sh
+++ b/testcases/lib/tests/shell_loader_kconfigs.sh
@@ -9,11 +9,11 @@
# }
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
tst_res TPASS "Shell loader works fine!"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_no_metadata.sh b/testcases/lib/tests/shell_loader_no_metadata.sh
index b664b48b57..77c4420964 100755
--- a/testcases/lib/tests/shell_loader_no_metadata.sh
+++ b/testcases/lib/tests/shell_loader_no_metadata.sh
@@ -5,11 +5,11 @@
# This test has no metadata and should not be executed
#
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
tst_res TFAIL "Shell loader should TBROK the test"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_supported_archs.sh b/testcases/lib/tests/shell_loader_supported_archs.sh
index 9ad24f9c03..eda243003b 100755
--- a/testcases/lib/tests/shell_loader_supported_archs.sh
+++ b/testcases/lib/tests/shell_loader_supported_archs.sh
@@ -9,11 +9,11 @@
# }
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
tst_res TPASS "We are running on supported architecture"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_tags.sh b/testcases/lib/tests/shell_loader_tags.sh
index c780a66c57..91e5a2ab2c 100755
--- a/testcases/lib/tests/shell_loader_tags.sh
+++ b/testcases/lib/tests/shell_loader_tags.sh
@@ -12,11 +12,11 @@
# }
# ---
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
tst_res TFAIL "Fails the test so that tags are shown."
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_tcnt.sh b/testcases/lib/tests/shell_loader_tcnt.sh
index 93bd612ee2..bfdc6b7576 100755
--- a/testcases/lib/tests/shell_loader_tcnt.sh
+++ b/testcases/lib/tests/shell_loader_tcnt.sh
@@ -12,11 +12,11 @@
# ---
#
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
tst_res TPASS "Iteration $1"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tests/shell_loader_wrong_metadata.sh b/testcases/lib/tests/shell_loader_wrong_metadata.sh
index 8f18741100..7ac4f348ee 100755
--- a/testcases/lib/tests/shell_loader_wrong_metadata.sh
+++ b/testcases/lib/tests/shell_loader_wrong_metadata.sh
@@ -12,11 +12,11 @@
# ---
#
-. tst_loader.sh
+. tst_env.sh
tst_test()
{
tst_res TFAIL "Shell loader should TBROK the test"
}
-tst_test
+. tst_loader.sh
diff --git a/testcases/lib/tst_env.sh b/testcases/lib/tst_env.sh
index b13bab37c3..585790a7d0 100644
--- a/testcases/lib/tst_env.sh
+++ b/testcases/lib/tst_env.sh
@@ -18,11 +18,6 @@ if [ -z "$LINENO" ]; then
LINENO=-1
fi
-if [ -z "$LTP_IPC_PATH" ]; then
- echo "This script has to be executed from a LTP loader!"
- exit 1
-fi
-
tst_brk_()
{
tst_res_ "$@"
@@ -35,7 +30,3 @@ tst_brk_()
alias tst_res="tst_res_ $tst_script_name \$LINENO"
alias tst_brk="tst_brk_ $tst_script_name \$LINENO"
-
-if [ -n "$TST_CLEANUP" ]; then
- trap $TST_CLEANUP EXIT
-fi
diff --git a/testcases/lib/tst_loader.sh b/testcases/lib/tst_loader.sh
index 62c9cc6d8f..ba6961353c 100644
--- a/testcases/lib/tst_loader.sh
+++ b/testcases/lib/tst_loader.sh
@@ -3,11 +3,20 @@
# Copyright (c) 2024-2025 Cyril Hrubis <chrubis@suse.cz>
#
# This is a loader for shell tests that use the C test library.
-#
if [ -z "$LTP_IPC_PATH" ]; then
tst_run_shell $(basename "$0") "$@"
exit $?
-else
- . tst_env.sh
fi
+
+. tst_env.sh
+
+if [ -n "$TST_CLEANUP" ]; then
+ trap $TST_CLEANUP EXIT
+fi
+
+if [ -n "$TST_SETUP" ]; then
+ $TST_SETUP
+fi
+
+tst_test
--
2.49.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [LTP] [PATCH v2 4/4] shell: Add shell_loader_setup_cleanup.sh test
2025-04-30 13:04 [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Petr Vorel
` (2 preceding siblings ...)
2025-04-30 13:04 ` [LTP] [PATCH v2 3/4] shell lib: Add basic support for test setup Petr Vorel
@ 2025-04-30 13:04 ` Petr Vorel
2025-05-02 8:51 ` [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Cyril Hrubis
4 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2025-04-30 13:04 UTC (permalink / raw)
To: ltp
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/lib/run_tests.sh | 1 +
.../lib/tests/shell_loader_setup_cleanup.sh | 31 +++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100755 testcases/lib/tests/shell_loader_setup_cleanup.sh
diff --git a/testcases/lib/run_tests.sh b/testcases/lib/run_tests.sh
index 128cee3377..5c309bbeb5 100755
--- a/testcases/lib/run_tests.sh
+++ b/testcases/lib/run_tests.sh
@@ -10,6 +10,7 @@ shell_loader_kconfigs.sh
shell_loader_supported_archs.sh
shell_loader_tcnt.sh
shell_loader_cleanup.sh
+shell_loader_setup_cleanup.sh
shell_test01
shell_test02
shell_test03
diff --git a/testcases/lib/tests/shell_loader_setup_cleanup.sh b/testcases/lib/tests/shell_loader_setup_cleanup.sh
new file mode 100755
index 0000000000..fd149cedb0
--- /dev/null
+++ b/testcases/lib/tests/shell_loader_setup_cleanup.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2025 Petr Vorel <pvorel@suse.cz>
+#
+# ---
+# env
+# {
+# }
+# ---
+
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+
+. tst_env.sh
+
+setup()
+{
+ tst_res TINFO "setup executed"
+}
+
+cleanup()
+{
+ tst_res TINFO "Cleanup executed"
+}
+
+tst_test()
+{
+ tst_res TPASS "Test is executed"
+}
+
+. tst_loader.sh
--
2.49.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP
2025-04-30 13:04 [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Petr Vorel
` (3 preceding siblings ...)
2025-04-30 13:04 ` [LTP] [PATCH v2 4/4] shell: Add shell_loader_setup_cleanup.sh test Petr Vorel
@ 2025-05-02 8:51 ` Cyril Hrubis
2025-05-06 22:04 ` Petr Vorel
4 siblings, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2025-05-02 8:51 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> we are getting there, but not yet finished.
>
> one remaining problem - it requires *full* path in PATH. I wonder what
> basic I'm missing. The current change requires to use full path
> otherwise execvpe() fails.
>
> I suppose it is due change cwd due creating temporary directory - it
> fails only with:
> "needs_tmpdir": true
> shell_loader_setup_cleanup.sh does not suffer this problem.
> It's also not dash related, problem is on bash as well.
That is exactly it. The test cannot run scripts that it cannot find so
we need an absolute path to the directory the scripts are in. If you
look at run_tests.sh we do srcdir=$(realpath $(dirname $0)) and prefix
all the paths with that directory.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v2 2/4] shell: Move shell code into functions
2025-04-30 13:04 ` [LTP] [PATCH v2 2/4] shell: Move shell code into functions Petr Vorel
@ 2025-05-02 9:26 ` Cyril Hrubis
0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2025-05-02 9:26 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v2 3/4] shell lib: Add basic support for test setup
2025-04-30 13:04 ` [LTP] [PATCH v2 3/4] shell lib: Add basic support for test setup Petr Vorel
@ 2025-05-02 9:36 ` Cyril Hrubis
0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2025-05-02 9:36 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> test.sh
> . tst_env.sh
> . tst_loader.sh
> tst_run_shell test.sh
> . tst_env.sh
> . tst_loader.sh
Maybe we can even simplify this a bit more if we move the part that
calls the tst_run_shell before we parse the whole shell test.
I guess that this would work:
test.sh
. tst_loader.sh
tst_run_shell test.sh
. tst_loader.sh
. tst_env.sh
. tst_run.sh
And the tst_loader.sh would be untouched and the code you are adding to
tst_loader.sh in this patch would go to the tst_run.sh.
That way we would include tst_env.sh in the tst_loader.sh on it's
second invocation, parse the shell test code and finally in tst_run.sh
setup the cleanup trap, call the setup and run the actual test.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP
2025-05-02 8:51 ` [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Cyril Hrubis
@ 2025-05-06 22:04 ` Petr Vorel
0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2025-05-06 22:04 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
> Hi!
> > we are getting there, but not yet finished.
> > one remaining problem - it requires *full* path in PATH. I wonder what
> > basic I'm missing. The current change requires to use full path
> > otherwise execvpe() fails.
> > I suppose it is due change cwd due creating temporary directory - it
> > fails only with:
> > "needs_tmpdir": true
> > shell_loader_setup_cleanup.sh does not suffer this problem.
> > It's also not dash related, problem is on bash as well.
> That is exactly it. The test cannot run scripts that it cannot find so
> we need an absolute path to the directory the scripts are in. If you
> look at run_tests.sh we do srcdir=$(realpath $(dirname $0)) and prefix
> all the paths with that directory.
+1, thanks for the reminder (I forget my code :), we were discussing it
together). I see whether I add it to tst_loader.sh or tst_env.sh.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-05-06 22:05 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 13:04 [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Petr Vorel
2025-04-30 13:04 ` [LTP] [PATCH v2 1/4] shell lib: Add support for test cleanup Petr Vorel
2025-04-30 13:04 ` [LTP] [PATCH v2 2/4] shell: Move shell code into functions Petr Vorel
2025-05-02 9:26 ` Cyril Hrubis
2025-04-30 13:04 ` [LTP] [PATCH v2 3/4] shell lib: Add basic support for test setup Petr Vorel
2025-05-02 9:36 ` Cyril Hrubis
2025-04-30 13:04 ` [LTP] [PATCH v2 4/4] shell: Add shell_loader_setup_cleanup.sh test Petr Vorel
2025-05-02 8:51 ` [LTP] [PATCH v2 0/4] shell loader rewrite to support TST_SETUP Cyril Hrubis
2025-05-06 22:04 ` Petr Vorel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.