[LTP] [PATCH] Add tst_get_max_clocks() routine based on tst_kconfig_check()

Avinesh Kumar akumar@suse.de
Fri Sep 5 16:58:46 CEST 2025


On Friday, September 5, 2025 1:12:39 PM CEST Cyril Hrubis wrote:
> Hi!
> > +int tst_get_max_clocks(void)
> > +{
> > +	static const char * const kconf_aux[] = {"CONFIG_POSIX_AUX_CLOCKS=y", NULL};
> > +
> > +	if (!tst_kconfig_check(kconf_aux))
> > +		return MAX_CLOCKS + MAX_AUX_CLOCKS;
> > +	else
> > +		return MAX_CLOCKS;
> > +}
> > diff --git a/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c
> > index 0c5e6ac21..ba62bf716 100644
> > --- a/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c
> > +++ b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c
> > @@ -76,11 +76,11 @@ struct test_case {
> >  
> >  struct test_case tc[] = {
> >  	{
> > -	 .clktype = TST_MAX_CLOCKS,
> > +	 .clktype = 0,
> >  	 .exp_err = EINVAL,
> >  	},
> >  	{
> > -	 .clktype = TST_MAX_CLOCKS + 1,
> > +	 .clktype = 0,
> >  	 .exp_err = EINVAL,
> >  	},
> >  	{
> > @@ -223,6 +223,9 @@ static void setup(void)
> >  			tc[i].lowlimit /= hz;
> >  		}
> >  	}
> > +
> > +	tc[0].clktype = tst_get_max_clocks();
> > +	tc[1].clktype = tst_get_max_clocks() + 1;
> 
> We usually frown upon hardcoded array indexes. There are couple of ways
> how to avoid that. The easiest is probably to store a pointers to clock
> types instead of the values in the test_case structure. Have a look at
> how we pass the fd in accept01.c for an example.
> 
> 
Hi Cyril,

Thank you for suggesting the right approach. I have sent v2.

Regards,
Avinesh





More information about the ltp mailing list