[LTP] [PATCH] Add tst_get_max_clocks() routine based on tst_kconfig_check()
Cyril Hrubis
chrubis@suse.cz
Fri Sep 5 13:12:39 CEST 2025
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.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list