Add tst_get_max_clocks() routine based on tst_kconfig_check()
PATCH v2 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 +++++ .../syscalls/clock_adjtime/clock_adjtime02.c | 26 ++++++---- .../syscalls/clock_gettime/clock_gettime02.c | 43 +++++++++++------ .../syscalls/clock_settime/clock_settime02.c | 48 ++++++++++++------- .../syscalls/timer_create/timer_create02.c | 19 +++++--- 7 files changed, 100 insertions(+), 56 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 +16 -10
@@ -61,11 +61,14 @@ static long hz;static struct tst_timex saved, ttxc;static int supported;static void *bad_addr; +static clockid_t max_clocks1; +static clockid_t max_clocks2; +static clockid_t clk_realtime =CLOCK_REALTIME ;static void cleanup (void );struct test_case { -clockid_t clktype; +clockid_t *clktype;unsigned int modes;long lowlimit;long highlimit;
@@ -74,36 +77,36 @@ struct test_case {int droproot; }; -struct test_case tc[] = { +static struct test_case tc[] = { { - .clktype =TST_MAX_CLOCKS , + .clktype = &max_clocks1, .exp_err =EINVAL , }, { - .clktype =TST_MAX_CLOCKS +1 , + .clktype = &max_clocks2, .exp_err =EINVAL , }, { - .clktype =CLOCK_REALTIME , + .clktype = &clk_realtime, .modes =ADJ_ALL , .exp_err =EFAULT , }, { - .clktype =CLOCK_REALTIME , + .clktype = &clk_realtime, .modes =ADJ_TICK , .lowlimit =900000 , .delta =1 , .exp_err =EINVAL , }, { - .clktype =CLOCK_REALTIME , + .clktype = &clk_realtime, .modes =ADJ_TICK , .highlimit =1100000 , .delta =1 , .exp_err =EINVAL , }, { - .clktype =CLOCK_REALTIME , + .clktype = &clk_realtime, .modes =ADJ_ALL , .exp_err =EPERM , .droproot =1 ,
@@ -162,9 +165,9 @@ static void verify_clock_adjtime(unsigned int i)/* special case: EFAULT for bad addresses */ if (tc[i].exp_err ==EFAULT ) { -TEST (tv->clock_adjtime (tc[i].clktype, bad_addr)); +TEST (tv->clock_adjtime (*tc[i].clktype, bad_addr)); }else { -TEST (tv->clock_adjtime (tc[i].clktype,tst_timex_get (txcptr))); +TEST (tv->clock_adjtime (*tc[i].clktype,tst_timex_get (txcptr)));timex_show ("TEST" , txcptr); }
@@ -223,6 +226,9 @@ static void setup(void) tc[i].lowlimit /= hz; } } + + max_clocks1 =tst_get_max_clocks (); + max_clocks2 = max_clocks1 +1 ; }static void cleanup (void )
testcases/kernel/syscalls/clock_gettime/clock_gettime02.c +28 -15
113 lines not on this page · raw message
testcases/kernel/syscalls/clock_settime/clock_settime02.c +30 -18
134 lines not on this page · raw message
testcases/kernel/syscalls/timer_create/timer_create02.c +12 -7
@@ -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 ,
@@ -42,26 +43,28 @@ static struct sigevent sig_ev_inv_sig = { };static kernel_timer_t timer_id; +static clock_t max_clocks; +static clock_t clk_realtime =CLOCK_REALTIME ;static struct testcase { -clock_t clock; +clock_t *clock;struct sigevent *ev_ptr;kernel_timer_t *kt_ptr;int error;char *desc; } 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" }, - {CLOCK_REALTIME , &sig_ev_inv_not, &timer_id,EINVAL ,"wrong sigev_notify" }, - {CLOCK_REALTIME , &sig_ev_inv_sig, &timer_id,EINVAL ,"wrong sigev_signo" }, + {&clk_realtime,NULL , &timer_id,EFAULT ,"invalid sigevent struct" }, + {&clk_realtime, &sig_ev,NULL ,EFAULT ,"invalid timer ID" }, + {&max_clocks, &sig_ev, &timer_id,EINVAL ,"invalid clock" }, + {&clk_realtime, &sig_ev_inv_not, &timer_id,EINVAL ,"wrong sigev_notify" }, + {&clk_realtime, &sig_ev_inv_sig, &timer_id,EINVAL ,"wrong sigev_signo" }, };static void run (unsigned int n) {struct testcase *tc = &tcases[n]; -TEST (tst_syscall (__NR_timer_create, tc->clock, tc->ev_ptr, tc->kt_ptr)); +TEST (tst_syscall (__NR_timer_create, *tc->clock, tc->ev_ptr, tc->kt_ptr));if (TST_RET !=-1 ||TST_ERR != tc->error) { tst_res(TFAIL | TTERRNO,
@@ -84,6 +87,8 @@ static void setup(void)if (!tcases[i].kt_ptr) tcases[i].kt_ptr =tst_get_bad_addr (NULL ); } + + max_clocks =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!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh, Cyril,
include/tst_clocks.h time_t tst_fs_timestamp_start(void); · line 50
Quoted 5 lines
+++
b/include/tst_clocks.hinclude/tst_clocks.h +1
-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 );
Function would deserve to have have kernel doc, but merged to get it fixed quickly.
Thanks for the fix!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp