[LTP] [PATCH 1/2] tst_test: Add $LTP_SINGLE_ITERATION to limit variant

Li Wang wangli.ahau@gmail.com
Thu Apr 16 10:19:15 CEST 2026


Hi Petr,

Petr Vorel <pvorel@suse.cz> wrote:

> > Allow to test only single struct tst_test->test_variants.
> > This is a similar feature to $LTP_SINGLE_FS_TYPE.
>
> > Value is ignored when test does not specify test_variants.
> > When value is higher than test_variants value lastest variant is used.
>
> Gently ping for this patch. IMHO it can be useful in some corner case debugging.

Agreed.

> > --- a/lib/tst_test.c
> > +++ b/lib/tst_test.c
> > @@ -581,6 +581,7 @@ static void print_help(void)
> >       fprintf(stderr, "LTP_DEV              Path to the block device to be used (for .needs_device)\n");
> >       fprintf(stderr, "LTP_DEV_FS_TYPE      Filesystem used for testing (default: %s)\n", DEFAULT_FS_TYPE);
> >       fprintf(stderr, "LTP_SINGLE_FS_TYPE   Testing only - specifies filesystem instead all supported (for .all_filesystems)\n");
> > +     fprintf(stderr, "LTP_SINGLE_VARIANT   Testing only - specifies tst_variant to be run\n");

How about name it as: LTP_VARIANT_START ?

> >       fprintf(stderr, "LTP_TIMEOUT_MUL      Timeout multiplier (must be a number >=1)\n");
> >       fprintf(stderr, "LTP_RUNTIME_MUL      Runtime multiplier (must be a number >=1)\n");
> >       fprintf(stderr, "LTP_VIRT_OVERRIDE    Overrides virtual machine detection (values: \"\"|kvm|microsoft|xen|zvm)\n");
> > @@ -1887,6 +1888,7 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
> >       int ret = 0;
> >       unsigned int test_variants = 1;
> >       struct utsname uval;
> > +     const char *only_variant;
>
> >       lib_pid = getpid();
> >       tst_test = self;
> > @@ -1899,7 +1901,6 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
>
> >       tst_res(TINFO, "LTP version: "LTP_VERSION);
>
> > -
> >       uname(&uval);
> >       tst_res(TINFO, "Tested kernel: %s %s %s", uval.release, uval.version, uval.machine);
>
> > @@ -1908,10 +1909,20 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
>
> >       set_overall_timeout();
>
> > -     if (tst_test->test_variants)
> > +     if (tst_test->test_variants) {
> >               test_variants = tst_test->test_variants;
> > +             only_variant = getenv("LTP_SINGLE_VARIANT");
> > +             if (only_variant && only_variant[0] != '\0') {
> > +                     tst_variant = MIN(SAFE_STRTOL((char *)only_variant, 0, INT_MAX),
> > +                                                       test_variants - 1);

Maybe limit the only_variant to range 0~(tst_variants-1)?

I think it'd be better to give a hint of the range rather than
excutiona non-exist number e.g. 99 there.

> > +                     tst_res(TINFO, "WARNING: testing only variant %d of %d",
> > +                                     tst_variant, test_variants - 1);
> > +                     test_variants = tst_variant + 1;
> > +             }
> > +     }
> > +
> > +     for (; tst_variant < test_variants; tst_variant++) {

I guess we need to reset the tst_variant value to zero before each looping.
Because if a test restarts, or manipulates this global state elsewhere,
it won't reset to 0, causing unpredictable behavior or skipped tests.

Then, something maybe like:

 void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 {
        unsigned int test_variants = 1;
+       unsigned int variant_start = 0;
        struct utsname uval;

        tst_test = self;
@@ -2057,10 +2059,20 @@ void tst_run_tcases(int argc, char *argv[],
struct tst_test *self)

        set_overall_timeout();

-       if (tst_test->test_variants)
+       if (tst_test->test_variants) {
                test_variants = tst_test->test_variants;

-       for (tst_variant = 0; tst_variant < test_variants; tst_variant++) {
+               const char *only = getenv("LTP_SINGLE_VARIANT");
+               if (only && *only) {
+                       variant_start = SAFE_STRTOL((char *)only, 0,
test_variants - 1);
+                       test_variants = variant_start + 1;
+
+                       tst_res(TINFO, "WARNING: testing only variant %d of %d",
+                                       variant_start,
tst_test->test_variants - 1);
+               }
+       }
+
+       for (tst_variant = variant_start; tst_variant < test_variants;
tst_variant++) {
                if (tst_test->all_filesystems || count_fs_descs() > 1)
                        run_tcases_per_fs();
                else



-- 
Regards,
Li Wang


More information about the ltp mailing list