[LTP] [PATCH 2/6] lib: Add .max_runtime and tst_remaining_runtime()

Cyril Hrubis chrubis@suse.cz
Tue Oct 26 14:49:21 CEST 2021


Hi!
> > Fundamentally there are two types of tests in LTP. First type are tests
> > that are rather quick (much less than a second) and can live with
> > whatever default timeout we set up. Second type of tests are tests that
> > run in a loop until timeout or a number of iterations is reached, these
> > are the tests that are going to be converted to the .max_runtime added
> > by this patch and followups.
> >
> > This patch does:
> >
> > - adds .max_runtime to tst_test structure - this is the maximal runtime
> >   per test iteration
> 
> I'm looking at the series, but I'm not sure I see much difference between
> runtime and timeout. Other than some margin added by library (the MAX formula)
> is there some other difference?

Well it mostly makes the code simpler and clearer since we can, for
instance, map the -I option to the test runtime in the library, we got
rid of all the custom test options for that, etc.

But it also allows us to tune the timeouts based on the expected runtime
so that the test has enough time for a cleanup and we can do that in a
single place rather than in 20 different heuristics in a different
testcases.

> > diff --git a/testcases/kernel/syscalls/move_pages/move_pages12.c b/testcases/kernel/syscalls/move_pages/move_pages12.c
> > index 220130f4b..e43bc5888 100644
> > --- a/testcases/kernel/syscalls/move_pages/move_pages12.c
> > +++ b/testcases/kernel/syscalls/move_pages/move_pages12.c
> > @@ -153,7 +153,6 @@ static void do_test(unsigned int n)
> >         void *ptr;
> >         pid_t cpid = -1;
> >         int status;
> > -       unsigned int twenty_percent = (tst_timeout_remaining() / 5);
> >
> >         addr = SAFE_MMAP(NULL, tcases[n].tpages * hpsz, PROT_READ | PROT_WRITE,
> >                 MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
> > @@ -198,7 +197,7 @@ static void do_test(unsigned int n)
> >
> >                 SAFE_MUNMAP(addr, tcases[n].tpages * hpsz);
> >
> > -               if (tst_timeout_remaining() < twenty_percent)
> > +               if (!tst_remaining_runtime())
> >                         break;
> >         }
> >
> > @@ -339,6 +338,7 @@ static struct tst_test test = {
> >         .forks_child = 1,
> >         .setup = setup,
> >         .cleanup = cleanup,
> > +       .max_runtime = 60,
> 
> Where does 60 come from?

Ah, my bad, the code did tst_timeout_remaining() < aprox. 60 so this
should have been 300 instead. Good catch.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list