* [LTP] [PATCH v4 1/6] shell lib: Add support for test cleanup
2025-07-22 12:59 [LTP] [PATCH v4 0/6] shell lib: Add support for test cleanup Petr Vorel
@ 2025-07-22 12:59 ` Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 2/6] shell: Move shell code into functions Petr Vorel
` (4 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Petr Vorel @ 2025-07-22 12:59 UTC (permalink / raw)
To: ltp
From: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
The same as in v3.
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.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread* [LTP] [PATCH v4 2/6] shell: Move shell code into functions
2025-07-22 12:59 [LTP] [PATCH v4 0/6] shell lib: Add support for test cleanup Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 1/6] " Petr Vorel
@ 2025-07-22 12:59 ` Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 3/6] tst_res_: Add support for TWARN Petr Vorel
` (3 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Petr Vorel @ 2025-07-22 12:59 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>
NOTE: it's important to properly quote strings when assign with local.
Otherwise shell_loader_all_filesystems.sh fails on old dash 0.5.8-2.10 on local export:
/__w/ltp/ltp/testcases/lib/tests//shell_loader_all_filesystems.sh: 20: local: /tmp/LTP_sheiFmNGP/ltp_mntpoint: bad variable name
Quote grep subcomand helps. While at it quote also realpath subcomand.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
The same as in v3.
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..8fe3809a5e 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.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread* [LTP] [PATCH v4 3/6] tst_res_: Add support for TWARN
2025-07-22 12:59 [LTP] [PATCH v4 0/6] shell lib: Add support for test cleanup Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 1/6] " Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 2/6] shell: Move shell code into functions Petr Vorel
@ 2025-07-22 12:59 ` Petr Vorel
2025-07-23 10:05 ` Cyril Hrubis
2025-07-22 12:59 ` [LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno Petr Vorel
` (2 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Petr Vorel @ 2025-07-22 12:59 UTC (permalink / raw)
To: ltp
TWARN is standard flag in LTP API, it should be supported, otherwise we
get:
Usage: tst_{res,brk} filename lineno [TPASS|TBROK|TFAIL|TCONF|TINFO|TDEBUG] 'A short description'
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
* New in v4
testcases/lib/tst_res_.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/testcases/lib/tst_res_.c b/testcases/lib/tst_res_.c
index fd9b8e8414..c09d689ee5 100644
--- a/testcases/lib/tst_res_.c
+++ b/testcases/lib/tst_res_.c
@@ -8,7 +8,7 @@
static void print_help(void)
{
- printf("Usage: tst_{res,brk} filename lineno [TPASS|TBROK|TFAIL|TCONF|TINFO|TDEBUG] 'A short description'\n");
+ printf("Usage: tst_{res,brk} filename lineno [TPASS|TBROK|TFAIL|TWARN|TCONF|TINFO|TDEBUG] 'A short description'\n");
}
int main(int argc, char *argv[])
@@ -28,6 +28,8 @@ int main(int argc, char *argv[])
type = TCONF;
} else if (!strcmp(argv[3], "TINFO")) {
type = TINFO;
+ } else if (!strcmp(argv[3], "TWARN")) {
+ type = TWARN;
} else if (!strcmp(argv[3], "TDEBUG")) {
type = TDEBUG;
} else if (!strcmp(argv[3], "TBROK")) {
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread* [LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno
2025-07-22 12:59 [LTP] [PATCH v4 0/6] shell lib: Add support for test cleanup Petr Vorel
` (2 preceding siblings ...)
2025-07-22 12:59 ` [LTP] [PATCH v4 3/6] tst_res_: Add support for TWARN Petr Vorel
@ 2025-07-22 12:59 ` Petr Vorel
2025-07-23 10:10 ` Cyril Hrubis
2025-07-22 12:59 ` [LTP] [PATCH v4 5/6] shell lib: Add basic support for test setup Petr Vorel
2025-07-22 12:59 ` [LTP] [PATCH v4 6/6] shell: Add shell_loader_setup_cleanup.sh test Petr Vorel
5 siblings, 1 reply; 13+ messages in thread
From: Petr Vorel @ 2025-07-22 12:59 UTC (permalink / raw)
To: ltp
Printing to stderr, tst_res_ filename and lineno helps debugging wrong
code. Best would be if it prints either code which invoked it or the
original message, but at least this is an improvement.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
* New in v4
testcases/lib/tst_res_.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/testcases/lib/tst_res_.c b/testcases/lib/tst_res_.c
index c09d689ee5..5b255d4d54 100644
--- a/testcases/lib/tst_res_.c
+++ b/testcases/lib/tst_res_.c
@@ -16,7 +16,7 @@ int main(int argc, char *argv[])
int type, i;
if (argc < 5) {
- printf("argc = %i expected 5\n", argc);
+ fprintf(stderr, "%s:%d: argc = %i expected 5\n", __FILE__, __LINE__, argc);
goto help;
}
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
} else if (!strcmp(argv[3], "TBROK")) {
type = TBROK;
} else {
- printf("Wrong type '%s'\n", argv[3]);
+ fprintf(stderr, "%s:%d: Wrong type '%s'\n", __FILE__, __LINE__, argv[3]);
goto help;
}
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno
2025-07-22 12:59 ` [LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno Petr Vorel
@ 2025-07-23 10:10 ` Cyril Hrubis
2025-07-23 19:38 ` Petr Vorel
0 siblings, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2025-07-23 10:10 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> Printing to stderr, tst_res_ filename and lineno helps debugging wrong
> code. Best would be if it prints either code which invoked it or the
> original message, but at least this is an improvement.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> * New in v4
>
> testcases/lib/tst_res_.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/testcases/lib/tst_res_.c b/testcases/lib/tst_res_.c
> index c09d689ee5..5b255d4d54 100644
> --- a/testcases/lib/tst_res_.c
> +++ b/testcases/lib/tst_res_.c
> @@ -16,7 +16,7 @@ int main(int argc, char *argv[])
> int type, i;
>
> if (argc < 5) {
> - printf("argc = %i expected 5\n", argc);
> + fprintf(stderr, "%s:%d: argc = %i expected 5\n", __FILE__, __LINE__, argc);
> goto help;
> }
>
> @@ -35,7 +35,7 @@ int main(int argc, char *argv[])
> } else if (!strcmp(argv[3], "TBROK")) {
> type = TBROK;
> } else {
> - printf("Wrong type '%s'\n", argv[3]);
> + fprintf(stderr, "%s:%d: Wrong type '%s'\n", __FILE__, __LINE__, argv[3]);
In this case we cantually have file and line in argv[1] and argv[2] and
we can print that as well.
And possibly in the case that argc < 5 we can attempt to print argv[1]
and argv[2] as well, but it's likely going to be wrong data since the
number of arguments does not match in that case.
> goto help;
> }
>
> --
> 2.50.1
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno
2025-07-23 10:10 ` Cyril Hrubis
@ 2025-07-23 19:38 ` Petr Vorel
2025-07-24 10:14 ` Cyril Hrubis
0 siblings, 1 reply; 13+ messages in thread
From: Petr Vorel @ 2025-07-23 19:38 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> Hi!
> > Printing to stderr, tst_res_ filename and lineno helps debugging wrong
> > code. Best would be if it prints either code which invoked it or the
> > original message, but at least this is an improvement.
> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > * New in v4
> > testcases/lib/tst_res_.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> > diff --git a/testcases/lib/tst_res_.c b/testcases/lib/tst_res_.c
> > index c09d689ee5..5b255d4d54 100644
> > --- a/testcases/lib/tst_res_.c
> > +++ b/testcases/lib/tst_res_.c
> > @@ -16,7 +16,7 @@ int main(int argc, char *argv[])
> > int type, i;
> > if (argc < 5) {
> > - printf("argc = %i expected 5\n", argc);
> > + fprintf(stderr, "%s:%d: argc = %i expected 5\n", __FILE__, __LINE__, argc);
> > goto help;
> > }
> > @@ -35,7 +35,7 @@ int main(int argc, char *argv[])
> > } else if (!strcmp(argv[3], "TBROK")) {
> > type = TBROK;
> > } else {
> > - printf("Wrong type '%s'\n", argv[3]);
> > + fprintf(stderr, "%s:%d: Wrong type '%s'\n", __FILE__, __LINE__, argv[3]);
> In this case we cantually have file and line in argv[1] and argv[2] and
> we can print that as well.
Thanks for a hint! I see I was blind (it's used below :)).
Because I really want whole functionality merged, I merged all but this patch.
And for this single patch I'll send v6.
> And possibly in the case that argc < 5 we can attempt to print argv[1]
> and argv[2] as well, but it's likely going to be wrong data since the
> number of arguments does not match in that case.
Maybe to detect if argv[2] is a number and then use argv[1] and argv[2],
otherwise use __FILE__ and __LINE__ ? But since atoi() does not detect errors,
we would have to use something smarter - safe_strtol() if possible to use LTP
API otherwise strtol()?
Or is it just too complicated and we can use argv[1] and argv[2] if argc > 2
and fallback to __FILE__ and __LINE__ otherwise?
Anyway, thanks a lot for your work and help to slowly move shell tests to shell
loader. Hopefully we are getting closer to have shell tests more reliable
without a need to rewrite everything to C.
Kind regards,
Petr
> > goto help;
> > }
> > --
> > 2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH v4 5/6] shell lib: Add basic support for test setup
2025-07-22 12:59 [LTP] [PATCH v4 0/6] shell lib: Add support for test cleanup Petr Vorel
` (3 preceding siblings ...)
2025-07-22 12:59 ` [LTP] [PATCH v4 4/6] tst_res_: Print error to stderr, with filename and lineno Petr Vorel
@ 2025-07-22 12:59 ` Petr Vorel
2025-07-23 10:35 ` Cyril Hrubis
2025-07-22 12:59 ` [LTP] [PATCH v4 6/6] shell: Add shell_loader_setup_cleanup.sh test Petr Vorel
5 siblings, 1 reply; 13+ messages in thread
From: Petr Vorel @ 2025-07-22 12:59 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
* Add tst_run.sh
* 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_loader.sh
tst_run_shell test.sh
. tst_loader.sh
. tst_env.sh
. tst_run.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>
---
Changes v3->v4:
* Add checks for $TST_SETUP and $TST_CLEANUP (Li)
NOTE: I decided to use TWARN for $TST_CLEANUP as usually test could run
without it.
testcases/kernel/mem/vma/vma05.sh | 2 +-
testcases/lib/tests/shell_loader.sh | 2 +-
.../lib/tests/shell_loader_all_filesystems.sh | 2 +-
.../lib/tests/shell_loader_brk_cleanup.sh | 2 +-
testcases/lib/tests/shell_loader_c_child.sh | 2 +-
testcases/lib/tests/shell_loader_cleanup.sh | 2 +-
.../lib/tests/shell_loader_filesystems.sh | 2 +-
.../lib/tests/shell_loader_invalid_block.sh | 2 +-
.../tests/shell_loader_invalid_metadata.sh | 2 +-
testcases/lib/tests/shell_loader_kconfigs.sh | 2 +-
.../lib/tests/shell_loader_no_metadata.sh | 2 +-
.../lib/tests/shell_loader_supported_archs.sh | 2 +-
testcases/lib/tests/shell_loader_tags.sh | 2 +-
testcases/lib/tests/shell_loader_tcnt.sh | 2 +-
.../lib/tests/shell_loader_wrong_metadata.sh | 2 +-
testcases/lib/tst_env.sh | 9 -------
testcases/lib/tst_run.sh | 24 +++++++++++++++++++
17 files changed, 39 insertions(+), 24 deletions(-)
create mode 100644 testcases/lib/tst_run.sh
diff --git a/testcases/kernel/mem/vma/vma05.sh b/testcases/kernel/mem/vma/vma05.sh
index 11d6b2ad86..c560eecbcd 100755
--- a/testcases/kernel/mem/vma/vma05.sh
+++ b/testcases/kernel/mem/vma/vma05.sh
@@ -71,4 +71,4 @@ tst_test()
fi
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader.sh b/testcases/lib/tests/shell_loader.sh
index 73812c3e23..78dba06b25 100755
--- a/testcases/lib/tests/shell_loader.sh
+++ b/testcases/lib/tests/shell_loader.sh
@@ -27,4 +27,4 @@ tst_test()
esac
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_all_filesystems.sh b/testcases/lib/tests/shell_loader_all_filesystems.sh
index 8fe3809a5e..3c3978f51c 100755
--- a/testcases/lib/tests/shell_loader_all_filesystems.sh
+++ b/testcases/lib/tests/shell_loader_all_filesystems.sh
@@ -32,4 +32,4 @@ tst_test()
fi
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_brk_cleanup.sh b/testcases/lib/tests/shell_loader_brk_cleanup.sh
index ff33345ce3..4e8ce4f737 100755
--- a/testcases/lib/tests/shell_loader_brk_cleanup.sh
+++ b/testcases/lib/tests/shell_loader_brk_cleanup.sh
@@ -22,4 +22,4 @@ tst_test()
tst_brk TBROK "Test exits"
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_c_child.sh b/testcases/lib/tests/shell_loader_c_child.sh
index b2b8f3d057..13480968f9 100755
--- a/testcases/lib/tests/shell_loader_c_child.sh
+++ b/testcases/lib/tests/shell_loader_c_child.sh
@@ -25,4 +25,4 @@ tst_test()
shell_c_child
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_cleanup.sh b/testcases/lib/tests/shell_loader_cleanup.sh
index 684901b51f..91071a5a75 100755
--- a/testcases/lib/tests/shell_loader_cleanup.sh
+++ b/testcases/lib/tests/shell_loader_cleanup.sh
@@ -22,4 +22,4 @@ tst_test()
tst_res TPASS "Test is executed"
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_filesystems.sh b/testcases/lib/tests/shell_loader_filesystems.sh
index b2c9d2f7d1..d584503adb 100755
--- a/testcases/lib/tests/shell_loader_filesystems.sh
+++ b/testcases/lib/tests/shell_loader_filesystems.sh
@@ -40,4 +40,4 @@ tst_test()
fi
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_invalid_block.sh b/testcases/lib/tests/shell_loader_invalid_block.sh
index 370c9043bc..be45303d79 100755
--- a/testcases/lib/tests/shell_loader_invalid_block.sh
+++ b/testcases/lib/tests/shell_loader_invalid_block.sh
@@ -27,4 +27,4 @@ tst_test()
tst_res TPASS "This should pass!"
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_invalid_metadata.sh b/testcases/lib/tests/shell_loader_invalid_metadata.sh
index 3834f1b9ed..c4c7579243 100755
--- a/testcases/lib/tests/shell_loader_invalid_metadata.sh
+++ b/testcases/lib/tests/shell_loader_invalid_metadata.sh
@@ -19,4 +19,4 @@ tst_test()
tst_res TFAIL "Shell loader should TBROK the test"
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_kconfigs.sh b/testcases/lib/tests/shell_loader_kconfigs.sh
index e1b6187554..d03bc99cac 100755
--- a/testcases/lib/tests/shell_loader_kconfigs.sh
+++ b/testcases/lib/tests/shell_loader_kconfigs.sh
@@ -16,4 +16,4 @@ tst_test()
tst_res TPASS "Shell loader works fine!"
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_no_metadata.sh b/testcases/lib/tests/shell_loader_no_metadata.sh
index b664b48b57..2ad458ef8d 100755
--- a/testcases/lib/tests/shell_loader_no_metadata.sh
+++ b/testcases/lib/tests/shell_loader_no_metadata.sh
@@ -12,4 +12,4 @@ tst_test()
tst_res TFAIL "Shell loader should TBROK the test"
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_supported_archs.sh b/testcases/lib/tests/shell_loader_supported_archs.sh
index 9ad24f9c03..a45cc59b7d 100755
--- a/testcases/lib/tests/shell_loader_supported_archs.sh
+++ b/testcases/lib/tests/shell_loader_supported_archs.sh
@@ -16,4 +16,4 @@ tst_test()
tst_res TPASS "We are running on supported architecture"
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_tags.sh b/testcases/lib/tests/shell_loader_tags.sh
index c780a66c57..56eadaf7a2 100755
--- a/testcases/lib/tests/shell_loader_tags.sh
+++ b/testcases/lib/tests/shell_loader_tags.sh
@@ -19,4 +19,4 @@ tst_test()
tst_res TFAIL "Fails the test so that tags are shown."
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_tcnt.sh b/testcases/lib/tests/shell_loader_tcnt.sh
index 93bd612ee2..cf2a0b74ec 100755
--- a/testcases/lib/tests/shell_loader_tcnt.sh
+++ b/testcases/lib/tests/shell_loader_tcnt.sh
@@ -19,4 +19,4 @@ tst_test()
tst_res TPASS "Iteration $1"
}
-tst_test
+. tst_run.sh
diff --git a/testcases/lib/tests/shell_loader_wrong_metadata.sh b/testcases/lib/tests/shell_loader_wrong_metadata.sh
index 8f18741100..35c535beed 100755
--- a/testcases/lib/tests/shell_loader_wrong_metadata.sh
+++ b/testcases/lib/tests/shell_loader_wrong_metadata.sh
@@ -19,4 +19,4 @@ tst_test()
tst_res TFAIL "Shell loader should TBROK the test"
}
-tst_test
+. tst_run.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_run.sh b/testcases/lib/tst_run.sh
new file mode 100644
index 0000000000..5f573b9a06
--- /dev/null
+++ b/testcases/lib/tst_run.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2025 Cyril Hrubis <chrubis@suse.cz>
+# Copyright (c) 2025 Petr Vorel <pvorel@suse.cz>
+
+. tst_env.sh
+
+if [ -n "$TST_CLEANUP" ]; then
+ if command -v $TST_CLEANUP >/dev/null 2>/dev/null; then
+ trap $TST_CLEANUP EXIT
+ else
+ tst_res TWARN "TST_CLEANUP=$TST_CLEANUP declared, but function not defined (or cmd not found)" # FIXME: debug
+ fi
+fi
+
+if [ -n "$TST_SETUP" ]; then
+ if command -v $TST_SETUP >/dev/null 2>/dev/null; then
+ $TST_SETUP
+ else
+ tst_brk TBROK "TST_SETUP=$TST_SETUP declared, but function not defined (or cmd not found)"
+ fi
+fi
+
+tst_test
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread* [LTP] [PATCH v4 6/6] shell: Add shell_loader_setup_cleanup.sh test
2025-07-22 12:59 [LTP] [PATCH v4 0/6] shell lib: Add support for test cleanup Petr Vorel
` (4 preceding siblings ...)
2025-07-22 12:59 ` [LTP] [PATCH v4 5/6] shell lib: Add basic support for test setup Petr Vorel
@ 2025-07-22 12:59 ` Petr Vorel
2025-07-23 10:39 ` Cyril Hrubis
5 siblings, 1 reply; 13+ messages in thread
From: Petr Vorel @ 2025-07-22 12:59 UTC (permalink / raw)
To: ltp
Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
The same as in v3.
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..8184278313
--- /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_loader.sh
+
+setup()
+{
+ tst_res TINFO "setup executed"
+}
+
+cleanup()
+{
+ tst_res TINFO "Cleanup executed"
+}
+
+tst_test()
+{
+ tst_res TPASS "Test is executed"
+}
+
+. tst_run.sh
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread