tst_test.sh: Fix calling not yet loaded cleanup function
PATCH v3 1/2 tst_test.sh: Fix calling not yet loaded cleanup function
e7dc14caa introduced a regression for new API network tests (these using tst_net.sh), which use network namespaces and have cleanup function:
$ PATH="/opt/ltp/testcases/bin:$PATH" tcp_ipsec.sh -6 -A rfc4543_256 \ -p esp_aead -m tunnel -s 100:1000:65535:R65535 tcp_ipsec 1 TCONF: Must be super/root for this test! /opt/ltp/testcases/bin/tst_test.sh: line 32: tst_ipsec_cleanup: command not found
This is caused by tst_brk called in tst_net.sh test preparation (happen just after loading tst_net.sh, that's why cleanup function haven't been defined yet. This would require to load tst_net.sh just before tst_run.
But because tst_net.sh doesn't have it's own cleanup function (tst_cleanup_rhost is always called in _tst_do_exit in tst_test.sh regardless of setup/cleanup functions), we can assume that only after starting the actual test code (after tst_run start).
---
changes v2->v3:
* simplify setup, inspired by Joerg
Kind regards,
Petr
testcases/lib/tst_test.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
testcases/lib/tst_test.sh +5 -1
@@ -28,7 +28,9 @@ _tst_do_exit() local ret=0 TST_DO_EXIT=1 - if [ -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then + if [ -n "$TST_RUN_STARTED" -a -n "$TST_CLEANUP" -a \ + -z "$TST_NO_CLEANUP" ]; then + $TST_CLEANUP fi
@@ -495,6 +497,8 @@ tst_run() local _tst_max local _tst_name + TST_RUN_STARTED=1 + if [ -n "$TST_TEST_PATH" ]; then for _tst_i in $(grep '^[^#]*\bTST_' "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do case "$_tst_i" in
Signature · 1 line
2.26.2
PATCH v3 2/2 tst_test.sh: Warn about setup/cleanup function not loaded
Inspired by regression fixed by previous commit.
---
Maybe this sanity check is not needed any more.
Kind regards,
Petr
testcases/lib/tst_test.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
testcases/lib/tst_test.sh +10 -2
@@ -30,8 +30,11 @@ _tst_do_exit() if [ -n "$TST_RUN_STARTED" -a -n "$TST_CLEANUP" -a \ -z "$TST_NO_CLEANUP" ]; then - - $TST_CLEANUP + if type "$TST_CLEANUP" >/dev/null 2>&1; then + $TST_CLEANUP + else + tst_brk TBROK "cleanup function set (TST_CLEANUP='$TST_CLEANUP'), but not found (test bug)" + fi fi if [ "$TST_NEEDS_DEVICE" = 1 -a "$TST_DEVICE_FLAG" = 1 ]; then
@@ -587,6 +590,11 @@ tst_run() if [ -n "$TST_SETUP" ]; then $TST_SETUP + if type "$TST_SETUP" >/dev/null 2>&1; then + $TST_SETUP + else + tst_brk TBROK "setup function set (TST_SETUP='$TST_SETUP'), but not found (test bug)" + fi fi #TODO check that test reports some results for each test function call
Signature · 1 line
2.26.2