setitimer01: add interval timer test
PATCH v2 1/2 setitimer01: add interval timer test
Split checking the return ovalue from testing the signal is delivered, so that we could use two time value for verifying.
Also, adding interval timer test by handling the signal at least 10 times. After that recover the signal behavior to default and do deliver-signal checking.
---
Notes:
v1 --> v2
* use prime number in set_setitimer_value
* print the time at the begining and end of test
* sperately compare result for tv_sec elapse or not
* print more info when TFAIL
.../kernel/syscalls/setitimer/setitimer01.c | 85 ++++++++++++++----- 1 file changed, 62 insertions(+), 23 deletions(-)
testcases/kernel/syscalls/setitimer/setitimer01.c +62 -23
@@ -21,9 +21,12 @@#include "lapi/syscalls.h" #include "tst_safe_clocks.h" +static struct timeval tv;static struct itimerval *value, *ovalue; +static volatile unsigned long sigcnt;static long time_step; -static long time_count; +static long time_sec; +static long time_usec; static struct tcase { int which;
@@ -40,17 +43,17 @@ static int sys_setitimer(int which, void *new_value, void *old_value)return tst_syscall (__NR_setitimer, which, new_value, old_value); } -static void set_setitimer_value (int usec,int o_usec) +static void sig_routine(int signo LTP_ATTRIBUTE_UNUSED) { - value->it_value.tv_sec =0 ; - value->it_value.tv_usec = usec; - value->it_interval.tv_sec =0 ; - value->it_interval.tv_usec =0 ; + sigcnt++; +} - ovalue->it_value.tv_sec = o_usec; - ovalue->it_value.tv_usec = o_usec; - ovalue->it_interval.tv_sec =0 ; - ovalue->it_interval.tv_usec =0 ; +static void set_setitimer_value (int sec,int usec) +{ + value->it_value.tv_sec = sec; + value->it_value.tv_usec = usec; + value->it_interval.tv_sec = sec; + value->it_interval.tv_usec = usec; }static void verify_setitimer (unsigned int i)
@@ -60,22 +63,31 @@ static void verify_setitimer(unsigned int i)long margin;struct tcase *tc = &tcases[i]; +tst_res (TINFO ,"tc->which = %s" , tc->des); + +if (tc->which ==ITIMER_REAL ) { +if (gettimeofday (&tv,NULL ) ==-1 ) +tst_brk (TBROK |TERRNO ,"gettimeofday(&tv1, NULL) failed" ); +else +tst_res (TINFO ,"Test begin time: %ld.%lds" , tv.tv_sec, tv.tv_usec); + } + pid =SAFE_FORK ();if (pid ==0 ) { -tst_res (TINFO ,"tc->which = %s" , tc->des); -tst_no_corefile (0 ); -set_setitimer_value (time_count,0 ); +set_setitimer_value (time_sec, time_usec);TST_EXP_PASS (sys_setitimer (tc->which, value,NULL )); -set_setitimer_value (5 * time_step,7 * time_step); +set_setitimer_value (5 * time_sec,7 * time_usec);TST_EXP_PASS (sys_setitimer (tc->which, value, ovalue)); -tst_res (TINFO ,"tv_sec=%ld, tv_usec=%ld" , - ovalue->it_value.tv_sec, - ovalue->it_value.tv_usec); +TST_EXP_EQ_LI (ovalue->it_interval.tv_sec, time_sec); +TST_EXP_EQ_LI (ovalue->it_interval.tv_usec, time_usec); + +tst_res (TINFO ,"ovalue->it_value.tv_sec=%ld, ovalue->it_value.tv_usec=%ld" , + ovalue->it_value.tv_sec, ovalue->it_value.tv_usec);/* * ITIMER_VIRTUAL and ITIMER_PROF timers always expire a
@@ -84,10 +96,29 @@ static void verify_setitimer(unsigned int i)*/ margin = tc->which ==ITIMER_REAL ?0 : time_step; -if (ovalue->it_value.tv_sec !=0 || ovalue->it_value.tv_usec > time_count + margin) -tst_res (TFAIL ,"Ending counters are out of range" ); +if (ovalue->it_value.tv_sec == time_sec) { +if (ovalue->it_value.tv_usec <0 || + ovalue->it_value.tv_usec > time_usec + margin) +tst_res (TFAIL ,"ovalue->it_value.tv_usec is out of range: %ld" , + ovalue->it_value.tv_usec); + }else { +if (ovalue->it_value.tv_sec <0 || + ovalue->it_value.tv_sec > time_sec) +tst_res (TFAIL ,"ovalue->it_value.tv_sec is out of range: %ld" , + ovalue->it_value.tv_sec); + } + +SAFE_SIGNAL (tc->signo, sig_routine); + +set_setitimer_value (0 , time_usec); +TST_EXP_PASS (sys_setitimer (tc->which, value,NULL )); -for (;;) +while (sigcnt <=10UL ) + ; + +SAFE_SIGNAL (tc->signo,SIG_DFL ); + +while (1 ) ; }
@@ -97,6 +128,13 @@ static void verify_setitimer(unsigned int i)tst_res (TPASS ,"Child received signal: %s" ,tst_strsig (tc->signo)); else tst_res(TFAIL, "Child: %s", tst_strstatus(status)); + +if (tc->which ==ITIMER_REAL ) { +if (gettimeofday (&tv,NULL ) ==-1 ) +tst_brk (TBROK |TERRNO ,"gettimeofday(&tv1, NULL) failed" ); +else +tst_res (TINFO ,"Test end time: %ld.%lds" , tv.tv_sec, tv.tv_usec); + } }static void setup (void )
@@ -114,10 +152,11 @@ static void setup(void)if (time_step <=0 ) time_step =1000 ; - time_count =3 * time_step; +tst_res (TINFO ,"clock low-resolution: %luns, time step: %luus" , + time_res.tv_nsec, time_step); -tst_res (TINFO ,"low-resolution: %luns, time step: %luus, time count: %luus" , - time_res.tv_nsec, time_step, time_count); + time_sec =9 + time_step /1000 ; + time_usec =3 * time_step; }static struct tst_test test = {
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 getitimer01: add checking for nonzero timer
By default a new process disabled the timer and getitimer() returned zero value. But we also need to check if the timer is correct when reset to nonzero.
---
Notes:
v1 --> v2
* reset itimer value to zero to make parameter '-i' works
* print the time at the begining and end of test
* sperately compare result for tv_sec elapse or not
* print more info when TFAIL
.../kernel/syscalls/getitimer/getitimer01.c | 108 ++++++++++++++++-- 1 file changed, 96 insertions(+), 12 deletions(-)
testcases/kernel/syscalls/getitimer/getitimer01.c +96 -12
@@ -12,25 +12,109 @@*/ #include "tst_test.h" +#include "tst_safe_clocks.h" -static int itimer_name[] = { -ITIMER_REAL , -ITIMER_VIRTUAL , -ITIMER_PROF , +#define SEC 100 +#define USEC 10000 + +static struct timeval tv; +static struct itimerval *value; +static long jiffy; + +static struct tcase { +int which; +char *des; +} tcases[] = { + {ITIMER_REAL ,"ITIMER_REAL" }, + {ITIMER_VIRTUAL ,"ITIMER_VIRTUAL" }, + {ITIMER_PROF ,"ITIMER_PROF" }, }; -static void run (void ) +static void set_setitimer_value (int sec,int usec) +{ + value->it_value.tv_sec = sec; + value->it_value.tv_usec = usec; + value->it_interval.tv_sec = sec; + value->it_interval.tv_usec = usec; +} + +static void verify_getitimer (unsigned int i) { -long unsigned int i; -struct itimerval value; +struct tcase *tc = &tcases[i]; + +tst_res (TINFO ,"tc->which = %s" , tc->des); -for (i =0 ; i <ARRAY_SIZE (itimer_name); i++) { -TST_EXP_PASS (getitimer (itimer_name[i], &value)); -TST_EXP_EQ_LI (value.it_value.tv_sec,0 ); -TST_EXP_EQ_LI (value.it_value.tv_usec,0 ); +if (tc->which ==ITIMER_REAL ) { +if (gettimeofday (&tv,NULL ) ==-1 ) +tst_brk (TBROK |TERRNO ,"gettimeofday(&tv1, NULL) failed" ); +else +tst_res (TINFO ,"Test begin time: %ld.%lds" , tv.tv_sec, tv.tv_usec); } + +TST_EXP_PASS (getitimer (tc->which, value)); +TST_EXP_EQ_LI (value->it_value.tv_sec,0 ); +TST_EXP_EQ_LI (value->it_value.tv_usec,0 ); +TST_EXP_EQ_LI (value->it_interval.tv_sec,0 ); +TST_EXP_EQ_LI (value->it_interval.tv_usec,0 ); + +set_setitimer_value (SEC ,USEC ); +TST_EXP_PASS (setitimer (tc->which, value,NULL )); + +set_setitimer_value (0 ,0 ); +TST_EXP_PASS (getitimer (tc->which, value)); + +TST_EXP_EQ_LI (value->it_interval.tv_sec,SEC ); +TST_EXP_EQ_LI (value->it_interval.tv_usec,USEC ); + +tst_res (TINFO ,"value->it_value.tv_sec=%ld, value->it_value.tv_usec=%ld" , + value->it_value.tv_sec, value->it_value.tv_usec); + +/* +* ITIMER_VIRTUAL and ITIMER_PROF timers always expire a +* TICK_NSEC (jiffy) afterward the elapsed time to make +* sure that at least time counters take effect. +*/ +long margin = (tc->which ==ITIMER_REAL ) ?0 : jiffy; + +if (value->it_value.tv_sec ==SEC ) { +if (value->it_value.tv_usec <0 || + value->it_value.tv_usec >USEC + margin) +tst_brk (TFAIL ,"value->it_value.tv_usec is out of range: %ld" , + value->it_value.tv_usec); + }else { +if (value->it_value.tv_sec <0 || + value->it_value.tv_sec >SEC ) +tst_brk (TFAIL ,"value->it_value.tv_sec is out of range: %ld" , + value->it_value.tv_sec); + } + +tst_res (TPASS ,"timer value is within the expected range" ); + +if (tc->which ==ITIMER_REAL ) { +if (gettimeofday (&tv,NULL ) ==-1 ) +tst_brk (TBROK |TERRNO ,"gettimeofday(&tv1, NULL) failed" ); +else +tst_res (TINFO ,"Test end time: %ld.%lds" , tv.tv_sec, tv.tv_usec); + } + +set_setitimer_value (0 ,0 ); +TST_EXP_PASS_SILENT (setitimer (tc->which, value,NULL )); +} + +static void setup (void ) +{ +struct timespec time_res; + +SAFE_CLOCK_GETRES (CLOCK_MONOTONIC_COARSE , &time_res); + jiffy = (time_res.tv_nsec +999 ) /1000 ; }static struct tst_test test = { - .test_all = run + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .test = verify_getitimer, + .bufs = (struct tst_buffers []) { + {&value, .size =sizeof (struct itimerval )}, + {} + } };
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Richard Palethorpe
AppliedRe: [LTP] [PATCH v2 2/2] getitimer01: add checking for nonzero timer
Hello,
Quoted 5 lines · Li Wang
By default a new process disabled the timer and
getitimer()returned zero value. But we also need to check if the timer is correct when reset to nonzero.Signed-off-by Li Wang <[email protected]>
Quoted 8 lines
---
Notes:
v1 --> v2
* reset itimer value to zero to make parameter '-i' works
* print the time at the begining and end of test
* sperately compare result fortv_secelapse or not
* print more info when TFAIL
Merged, thanks!
Quoted 130 lines
.../kernel/syscalls/getitimer/getitimer01.c | 108 ++++++++++++++++-- 1 file changed, 96 insertions(+), 12 deletions(-)testcases/kernel/syscalls/getitimer/getitimer01.c +96
-12@@ -12,25 +12,109 @@*/ #include "tst_test.h" +#include "tst_safe_clocks.h" -static int itimer_name[] = { -ITIMER_REAL , -ITIMER_VIRTUAL , -ITIMER_PROF , +#define SEC 100 +#define USEC 10000 + +static struct timeval tv; +static struct itimerval *value; +static long jiffy; + +static struct tcase { +int which; +char *des; +} tcases[] = { + {ITIMER_REAL ,"ITIMER_REAL" }, + {ITIMER_VIRTUAL ,"ITIMER_VIRTUAL" }, + {ITIMER_PROF ,"ITIMER_PROF" }, }; -static void run (void ) +static void set_setitimer_value (int sec,int usec) +{ + value->it_value.tv_sec = sec; + value->it_value.tv_usec = usec; + value->it_interval.tv_sec = sec; + value->it_interval.tv_usec = usec; +} + +static void verify_getitimer (unsigned int i) { -long unsigned int i; -struct itimerval value; +struct tcase *tc = &tcases[i]; + +tst_res (TINFO ,"tc->which = %s" , tc->des); -for (i =0 ; i <ARRAY_SIZE (itimer_name); i++) { -TST_EXP_PASS (getitimer (itimer_name[i], &value)); -TST_EXP_EQ_LI (value.it_value.tv_sec,0 ); -TST_EXP_EQ_LI (value.it_value.tv_usec,0 ); +if (tc->which ==ITIMER_REAL ) { +if (gettimeofday (&tv,NULL ) ==-1 ) +tst_brk (TBROK |TERRNO ,"gettimeofday(&tv1, NULL) failed" ); +else +tst_res (TINFO ,"Test begin time: %ld.%lds" , tv.tv_sec, tv.tv_usec); } + +TST_EXP_PASS (getitimer (tc->which, value)); +TST_EXP_EQ_LI (value->it_value.tv_sec,0 ); +TST_EXP_EQ_LI (value->it_value.tv_usec,0 ); +TST_EXP_EQ_LI (value->it_interval.tv_sec,0 ); +TST_EXP_EQ_LI (value->it_interval.tv_usec,0 ); + +set_setitimer_value (SEC ,USEC ); +TST_EXP_PASS (setitimer (tc->which, value,NULL )); + +set_setitimer_value (0 ,0 ); +TST_EXP_PASS (getitimer (tc->which, value)); + +TST_EXP_EQ_LI (value->it_interval.tv_sec,SEC ); +TST_EXP_EQ_LI (value->it_interval.tv_usec,USEC ); + +tst_res (TINFO ,"value->it_value.tv_sec=%ld, value->it_value.tv_usec=%ld" , + value->it_value.tv_sec, value->it_value.tv_usec); + +/* +* ITIMER_VIRTUAL and ITIMER_PROF timers always expire a +* TICK_NSEC (jiffy) afterward the elapsed time to make +* sure that at least time counters take effect. +*/ +long margin = (tc->which ==ITIMER_REAL ) ?0 : jiffy; + +if (value->it_value.tv_sec ==SEC ) { +if (value->it_value.tv_usec <0 || + value->it_value.tv_usec >USEC + margin) +tst_brk (TFAIL ,"value->it_value.tv_usec is out of range: %ld" , + value->it_value.tv_usec); + }else { +if (value->it_value.tv_sec <0 || + value->it_value.tv_sec >SEC ) +tst_brk (TFAIL ,"value->it_value.tv_sec is out of range: %ld" , + value->it_value.tv_sec); + } + +tst_res (TPASS ,"timer value is within the expected range" ); + +if (tc->which ==ITIMER_REAL ) { +if (gettimeofday (&tv,NULL ) ==-1 ) +tst_brk (TBROK |TERRNO ,"gettimeofday(&tv1, NULL) failed" ); +else +tst_res (TINFO ,"Test end time: %ld.%lds" , tv.tv_sec, tv.tv_usec); + } + +set_setitimer_value (0 ,0 ); +TST_EXP_PASS_SILENT (setitimer (tc->which, value,NULL )); +} + +static void setup (void ) +{ +struct timespec time_res; + +SAFE_CLOCK_GETRES (CLOCK_MONOTONIC_COARSE , &time_res); + jiffy = (time_res.tv_nsec +999 ) /1000 ; }static struct tst_test test = { - .test_all = run + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .test = verify_getitimer, + .bufs = (struct tst_buffers []) { + {&value, .size =sizeof (struct itimerval )}, + {} + } };
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Richard Palethorpe
AppliedHello,
Quoted 8 lines · Li Wang
Split checking the return ovalue from testing the signal is delivered, so that we could use two time value for verifying.
Also, adding interval timer test by handling the signal at least 10 times. After that recover the signal behavior to default and do deliver-signal checking.
Signed-off-by Li Wang <[email protected]>
Quoted 8 lines
---
Notes:
v1 --> v2
* use prime number inset_setitimer_value
* print the time at the begining and end of test
* sperately compare result fortv_secelapse or not
* print more info when TFAIL
Merged, thanks!
Quoted 150 lines
.../kernel/syscalls/setitimer/setitimer01.c | 85 ++++++++++++++----- 1 file changed, 62 insertions(+), 23 deletions(-)testcases/kernel/syscalls/setitimer/setitimer01.c +62
-23@@ -21,9 +21,12 @@#include "lapi/syscalls.h" #include "tst_safe_clocks.h" +static struct timeval tv;static struct itimerval *value, *ovalue; +static volatile unsigned long sigcnt;static long time_step; -static long time_count; +static long time_sec; +static long time_usec; static struct tcase { int which;@@ -40,17 +43,17 @@ static int sys_setitimer(int which, void *new_value, void *old_value)return tst_syscall (__NR_setitimer, which, new_value, old_value); } -static void set_setitimer_value (int usec,int o_usec) +static void sig_routine(int signo LTP_ATTRIBUTE_UNUSED) { - value->it_value.tv_sec =0 ; - value->it_value.tv_usec = usec; - value->it_interval.tv_sec =0 ; - value->it_interval.tv_usec =0 ; + sigcnt++; +} - ovalue->it_value.tv_sec = o_usec; - ovalue->it_value.tv_usec = o_usec; - ovalue->it_interval.tv_sec =0 ; - ovalue->it_interval.tv_usec =0 ; +static void set_setitimer_value (int sec,int usec) +{ + value->it_value.tv_sec = sec; + value->it_value.tv_usec = usec; + value->it_interval.tv_sec = sec; + value->it_interval.tv_usec = usec; }static void verify_setitimer (unsigned int i)@@ -60,22 +63,31 @@ static void verify_setitimer(unsigned int i)long margin;struct tcase *tc = &tcases[i]; +tst_res (TINFO ,"tc->which = %s" , tc->des); + +if (tc->which ==ITIMER_REAL ) { +if (gettimeofday (&tv,NULL ) ==-1 ) +tst_brk (TBROK |TERRNO ,"gettimeofday(&tv1, NULL) failed" ); +else +tst_res (TINFO ,"Test begin time: %ld.%lds" , tv.tv_sec, tv.tv_usec); + } + pid =SAFE_FORK ();if (pid ==0 ) { -tst_res (TINFO ,"tc->which = %s" , tc->des); -tst_no_corefile (0 ); -set_setitimer_value (time_count,0 ); +set_setitimer_value (time_sec, time_usec);TST_EXP_PASS (sys_setitimer (tc->which, value,NULL )); -set_setitimer_value (5 * time_step,7 * time_step); +set_setitimer_value (5 * time_sec,7 * time_usec);TST_EXP_PASS (sys_setitimer (tc->which, value, ovalue)); -tst_res (TINFO ,"tv_sec=%ld, tv_usec=%ld" , - ovalue->it_value.tv_sec, - ovalue->it_value.tv_usec); +TST_EXP_EQ_LI (ovalue->it_interval.tv_sec, time_sec); +TST_EXP_EQ_LI (ovalue->it_interval.tv_usec, time_usec); + +tst_res (TINFO ,"ovalue->it_value.tv_sec=%ld, ovalue->it_value.tv_usec=%ld" , + ovalue->it_value.tv_sec, ovalue->it_value.tv_usec);/* * ITIMER_VIRTUAL and ITIMER_PROF timers always expire a @@ -84,10 +96,29 @@ static void verify_setitimer(unsigned int i)*/ margin = tc->which ==ITIMER_REAL ?0 : time_step; -if (ovalue->it_value.tv_sec !=0 || ovalue->it_value.tv_usec > time_count + margin) -tst_res (TFAIL ,"Ending counters are out of range" ); +if (ovalue->it_value.tv_sec == time_sec) { +if (ovalue->it_value.tv_usec <0 || + ovalue->it_value.tv_usec > time_usec + margin) +tst_res (TFAIL ,"ovalue->it_value.tv_usec is out of range: %ld" , + ovalue->it_value.tv_usec); + }else { +if (ovalue->it_value.tv_sec <0 || + ovalue->it_value.tv_sec > time_sec) +tst_res (TFAIL ,"ovalue->it_value.tv_sec is out of range: %ld" , + ovalue->it_value.tv_sec); + } + +SAFE_SIGNAL (tc->signo, sig_routine); + +set_setitimer_value (0 , time_usec); +TST_EXP_PASS (sys_setitimer (tc->which, value,NULL )); -for (;;) +while (sigcnt <=10UL ) + ; + +SAFE_SIGNAL (tc->signo,SIG_DFL ); + +while (1 ) ; }@@ -97,6 +128,13 @@ static void verify_setitimer(unsigned int i)tst_res (TPASS ,"Child received signal: %s" ,tst_strsig (tc->signo)); else tst_res(TFAIL, "Child: %s", tst_strstatus(status)); + +if (tc->which ==ITIMER_REAL ) { +if (gettimeofday (&tv,NULL ) ==-1 ) +tst_brk (TBROK |TERRNO ,"gettimeofday(&tv1, NULL) failed" ); +else +tst_res (TINFO ,"Test end time: %ld.%lds" , tv.tv_sec, tv.tv_usec); + } }static void setup (void )@@ -114,10 +152,11 @@ static void setup(void)if (time_step <=0 ) time_step =1000 ; - time_count =3 * time_step; +tst_res (TINFO ,"clock low-resolution: %luns, time step: %luus" , + time_res.tv_nsec, time_step); -tst_res (TINFO ,"low-resolution: %luns, time step: %luus, time count: %luus" , - time_res.tv_nsec, time_step, time_count); + time_sec =9 + time_step /1000 ; + time_usec =3 * time_step; }static struct tst_test test = {
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp