Add tst_get_max_clocks() routine based on tst_kconfig_check()
PATCH 1/1 Add tst_get_max_clocks() routine based on tst_kconfig_check()
current logic for defining TST_MAX_CLOCKS is based on checking the kernel version provided by glibc headers which is not right as there are mismatches possible between kernel version being tested and version provided by headers.
Instead use tst_kconfig_check() routine for checking if the CONFIG_POSIX_AUX_CLOCKS config option is set and define max clocks accordingly in the tests for invalid clock types.
--- include/lapi/common_timers.h | 6 ------ include/tst_clocks.h | 2 ++ lib/tst_clocks.c | 12 ++++++++++++ .../kernel/syscalls/clock_adjtime/clock_adjtime02.c | 7 +++++-- .../kernel/syscalls/clock_gettime/clock_gettime02.c | 7 +++++-- .../kernel/syscalls/clock_settime/clock_settime02.c | 7 +++++-- .../kernel/syscalls/timer_create/timer_create02.c | 5 ++++- 7 files changed, 33 insertions(+), 13 deletions(-)
include/lapi/common_timers.h +0 -6
@@ -33,12 +33,6 @@ static const clock_t clock_list[] = {#define MAX_AUX_CLOCKS 8 -#if LINUX_VERSION_CODE >=KERNEL_VERSION (6 ,17 ,0 ) -#define TST_MAX_CLOCKS (MAX_CLOCKS + MAX_AUX_CLOCKS) -#else -#define TST_MAX_CLOCKS (MAX_CLOCKS) -#endif -#define CLOCK_TO_STR (def_name) \ case def_name: \ return #def_name;
include/tst_clocks.h +2 -0
@@ -48,4 +48,6 @@ time_t tst_fs_timestamp_start(void);*/ time_t tst_fs_timestamp_end (void ); +int tst_get_max_clocks (void ); +#endif /* TST_CLOCKS__ */
lib/tst_clocks.c +12 -0
@@ -11,6 +11,8 @@#include "tst_clocks.h" #include "lapi/syscalls.h" #include "lapi/posix_clocks.h" +#include "lapi/common_timers.h" +#include "tst_kconfig.h" typedef int (*mysyscall )(clockid_t clk_id,void *ts);
@@ -168,3 +170,13 @@ time_t tst_fs_timestamp_end(void) {return tst_clock_get_timestamp (CLOCK_REALTIME ); } + +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 ; +}
testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c +5 -2
@@ -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 ; }static void cleanup (void )
testcases/kernel/syscalls/clock_gettime/clock_gettime02.c +5 -2
@@ -34,11 +34,11 @@ struct test_case {static struct test_case tc[] = { { - .clktype =TST_MAX_CLOCKS , + .clktype =0 , .exp_err =EINVAL , }, { - .clktype =TST_MAX_CLOCKS +1 , + .clktype =0 , .exp_err =EINVAL , },/*
@@ -103,6 +103,9 @@ static void setup(void)tst_res (TINFO ,"Testing variant: %d: %s" , tst_variant, variants[tst_variant].desc); bad_addr =tst_get_bad_addr (NULL ); + + tc[0 ].clktype =tst_get_max_clocks (); + tc[1 ].clktype =tst_get_max_clocks () +1 ; }static void verify_clock_gettime (unsigned int i)
testcases/kernel/syscalls/clock_settime/clock_settime02.c +5 -2
@@ -59,11 +59,11 @@ struct test_case tc[] = { .exp_err = EINVAL, }, { /* case 06: MAXCLOCK */ - .type = TST_MAX_CLOCKS, + .type = 0, .exp_err = EINVAL, }, { /* case 07: MAXCLOCK+1 */ - .type = TST_MAX_CLOCKS + 1, + .type = 0, .exp_err = EINVAL, }, /* Linux specific */
@@ -106,6 +106,9 @@ static void setup(void)tst_res (TINFO ,"Testing variant: %s" , variants[tst_variant].desc); bad_addr =tst_get_bad_addr (NULL ); + + tc[5 ].type =tst_get_max_clocks (); + tc[6 ].type =tst_get_max_clocks () +1 ; }static void verify_clock_settime (unsigned int i)
testcases/kernel/syscalls/timer_create/timer_create02.c +4 -1
@@ -25,6 +25,7 @@#include <signal.h> #include "tst_test.h" #include "lapi/common_timers.h" +#include "tst_safe_clocks.h" static struct sigevent sig_ev = { .sigev_notify =SIGEV_NONE ,
@@ -52,7 +53,7 @@ static struct testcase { } tcases[] = { {CLOCK_REALTIME, NULL, &timer_id, EFAULT, "invalid sigevent struct"}, {CLOCK_REALTIME, &sig_ev, NULL, EFAULT, "invalid timer ID"}, - {TST_MAX_CLOCKS, &sig_ev, &timer_id, EINVAL, "invalid clock"}, + {0, &sig_ev, &timer_id, EINVAL, "invalid clock"}, {CLOCK_REALTIME, &sig_ev_inv_not, &timer_id, EINVAL, "wrong sigev_notify"}, {CLOCK_REALTIME, &sig_ev_inv_sig, &timer_id, EINVAL, "wrong sigev_signo"}, };
@@ -84,6 +85,8 @@ static void setup(void)if (!tcases[i].kt_ptr) tcases[i].kt_ptr =tst_get_bad_addr (NULL ); } + + tcases[2 ].clock =tst_get_max_clocks (); }static struct tst_test test = {
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 28 lines
lib/tst_clocks.c +9
-0+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 ; +}testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c +2
-2@@ -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 , }, {
testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c static void setup(void) · line 228
Quoted 6 lines
testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c +3
-0@@ -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.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 32 lines · CEST Cyril Hrubis
Hi!
Quoted 31 lines
lib/tst_clocks.c +9
-0+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 ; +}testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c +2
-2@@ -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; } }
Quoted 10 lines
testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c static void setup(void) · line 228
Quoted 3 lines
testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c +3
-0+ + 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_casestructure. Have a look at how we pass the fd inaccept01.cfor an example.
Hi Cyril,
Thank you for suggesting the right approach. I have sent v2.
Regards,
Avinesh
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp