[LTP] [RFC PATCH 4/5] shell lib: Add basic support for test cleanup
Petr Vorel
pvorel@suse.cz
Mon Mar 10 11:27:31 CET 2025
Hi Cyril, all,
Note: subject wrongly mentions cleanup instead of setup
s/cleanup/setup/
> > diff --git a/testcases/lib/tst_env.sh b/testcases/lib/tst_env.sh
> > index b13bab37c3..68f9a0daa9 100644
> > --- a/testcases/lib/tst_env.sh
> > +++ b/testcases/lib/tst_env.sh
> > @@ -35,7 +35,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_exec.sh b/testcases/lib/tst_exec.sh
> > new file mode 100755
> > index 0000000000..dcf40fd5bb
> > --- /dev/null
> > +++ b/testcases/lib/tst_exec.sh
> > @@ -0,0 +1,19 @@
> > +#!/bin/sh
> > +# Copyright (c) 2025 Cyril Hrubis <chrubis@suse.cz>
> > +# Copyright (c) 2025 Petr Vorel <pvorel@suse.cz>
> > +
> > +. tst_env.sh
> > +
> > +. "$1"
> > +
> > +if [ -n "$TST_CLEANUP" ]; then
> > + trap $TST_CLEANUP EXIT
> > +fi
> > +
> > +if [ -n "$TST_SETUP" ]; then
> > + $TST_SETUP
> > +fi
> > +
> > +tst_test
> > +
> > +# vim: set ft=sh ts=4 sts=4 sw=4 expandtab :
> Please do not add the vim formatting hints.
Ah, sorry (editor macro when creating new file, I forget to delete it).
> > diff --git a/testcases/lib/tst_loader.sh b/testcases/lib/tst_loader.sh
> > index 62c9cc6d8f..e2d1bd7daf 100644
> > --- a/testcases/lib/tst_loader.sh
> > +++ b/testcases/lib/tst_loader.sh
> > @@ -3,11 +3,8 @@
> > # 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") "$@"
> > + tst_run_shell tst_exec.sh $(basename "$0") "$@"
> > exit $?
> > -else
> > - . tst_env.sh
> > fi
> Do we really need the tst_exec.sh?
> Doesn't it work if we add what is in the tst_exec here?
Do you mean to avoid this change:
- tst_run_shell $(basename "$0") "$@"
+ tst_run_shell tst_exec.sh $(basename "$0") "$@"
and put the content here? I'll try it during this week.
> The whole point of [ -z "$LTP_IPC_PATH" ]; is to detect when we are
> being re-executed by the tst_run_shell, so the else branch (which
> isn't really needed, because we do exit in the if) was when the test did
> run.
+1. I figured this later after doing more debugging (preparation for internal
SUSE talk).
> If you change the tests to be in functions and source the tst_loader.sh
> at the end it should just work.
+1
Thanks for your review!
Kind regards,
Petr
More information about the ltp
mailing list