Message ID | 20250430130417.43523-4-pvorel@suse.cz |
---|---|
State | Needs Review / ACK |
Headers | show |
Series | shell loader rewrite to support TST_SETUP | expand |
Context | Check | Description |
---|---|---|
ltpci/debian_stable_s390x-linux-gnu-gcc_s390x | success | success |
ltpci/debian_stable_aarch64-linux-gnu-gcc_arm64 | success | success |
ltpci/debian_stable_powerpc64le-linux-gnu-gcc_ppc64el | success | success |
ltpci/debian_stable_gcc | success | success |
ltpci/ubuntu_jammy_gcc | success | success |
ltpci/alpine_latest_gcc | success | success |
ltpci/debian_stable_gcc | success | success |
ltpci/opensuse-archive_42-2_gcc | success | success |
ltpci/fedora_latest_clang | success | success |
ltpci/debian_oldstable_gcc | success | success |
ltpci/debian_oldstable_clang | success | success |
ltpci/quay-io-centos-centos_stream9_gcc | success | success |
ltpci/opensuse-leap_latest_gcc | success | success |
ltpci/debian_testing_clang | success | success |
ltpci/debian_testing_gcc | success | success |
ltpci/ubuntu_bionic_gcc | fail | failure |
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.
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
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(-)