[LTP] [PATCH 2/2] shell lib: Add support for test cleanup

Cyril Hrubis chrubis@suse.cz
Fri Feb 14 15:07:42 CET 2025


Hi!
> Unfortunately TST_SETUP will not work that way - function is not found or if you
> load tst_env.sh at the end, it complains about missing tst_res or tst_brk:
> 
> ./tests/./shell_loader_brk_cleanup.sh: line 16: tst_res: command not found
> 
> Obviously it does not help to add it to tst_loader.sh.
> 
> I'm surprised it checks that, is there shopt option which could disable it?

The problem here the order the scripts are sourced. It looks like this:

test.sh
 . tst_loader.sh
  tst_run_shell test.sh
   . tst_loader.sh
    . tst_env.sh <- at this point in the execution you haven't even started
                    parsing test.sh so you cannot run functions from there
		    at all

If you wanted to have separate setup function you would have to build
things differently, you would have to execute a library shell script
by the tst_run_shell tool, which would source the test.sh and execute
the functions passed to it. So the execution would look like:

test.sh
 . tst_loader.sh
 tst_run_shell tst_exec.sh test.sh
  . test.sh
    . tst_env.sh

And then the tst_exec.sh would do:

	. "$1"

	if [ -n "$TST_SETUP" ]; then
		$TST_SETUP
	fi

	$TST_TEST

or something along these lines.

And the test.sh would have to look like:

TST_SETUP=setup
TST_CLEANUP=cleanup
TST_TEST=runtest

. tst_loader.sh


setup()
{
...
}

cleanup()
{
...
}

runtest()
{
...
}


All the code would have to be in functions.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list