[LTP] [PATCH 5/6] [WIP,RFC] tst_run.sh: Run setup() only once
Cyril Hrubis
chrubis@suse.cz
Wed Mar 18 12:23:31 CET 2026
Hi!
> > NOTE: this is still not working on iterations (-i2), because
> > static int iterations is from tst_test.c is not propagated to
> > tst_run_shell.c. I wonder if I should set the value as environment
> > variable or add it into struct context.
>
> Passing the current iteration as env variable is feasible.
>
> Since LTP export an similar variable 'TST_ITERATIONS' in tst_test.sh,
> maybe define another env var for current loop, e.g. TST_ITERATION
> (or TST_CURRENT_LOOP), pass to tst_run.sh?
>
> Something like:
>
> 1. Create tst_get_cur_iteration(void) function in LTP core API
>
> 2. Export current loop in tst_run_shell.c before running run_shell_tcnt()
>
> static void run_shell_tcnt(unsigned int n)
> {
> ...
> char iter_buf[32];
>
> snprintf(iter_buf, sizeof(iter_buf), "%u", tst_get_cur_iteration());
>
> if (setenv("TST_ITERATION", iter_buf, 1))
> tst_brk(TBROK | TERRNO, "setenv(TST_ITERATION) failed");
>
> tst_run_script(shell_filename, params);
> }
>
> 3. Reuse it in tst_run.sh to run setup once globally
>
> [ "$1" == "1" ] && [ "${TST_ITERATION:-1}" == "1" ] && $TST_SETUP
It's a bit more complicated we do not have only iterations but also
duration and timeout per iteration. So we would need a function that
would return if the script should continue or not and also call the
heartbeat() function. Something as:
int tst_next_shell_iteration(void)
{
int cont = 0;
static int iteration = 0;
if (iteration < iterations)
cont = 1;
if (stop_time && get_time_ms() < stop_time())
cont = 1;
if (!cont)
return 0;
heartbeat();
return ++iteration;
}
The shell helper would call this and we would use it in tst_run.sh and
loop the tst_test() until we are said to stop.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list