[LTP] [PATCH 5/6] [WIP,RFC] tst_run.sh: Run setup() only once

Li Wang liwang@redhat.com
Tue Mar 17 10:42:13 CET 2026


On Fri, Mar 13, 2026 at 03:25:59PM +0100, Petr Vorel wrote:
> Both C API and tst_test.sh shell API run test only once.
> Fix shell loader API also to run setup only once.
> This reuses functionality added in the previous commit.
> 
> Fixes: 8202494493 ("shell lib: Add basic support for test setup")
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> 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


-- 
Regards,
Li Wang



More information about the ltp mailing list