setitimer01: add interval timer test
PATCH 1/2 setitimer01: add interval timer test
First, split checking the return ovalue from testing the signal is delivered. The benefit is that we could use a long timeout value for verifying.
Second, add an interval timer test by handling the signal at least 10 times. After that recover the signal behavior to default and do deliver-signal checking.
--- .../kernel/syscalls/setitimer/setitimer01.c | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-)
testcases/kernel/syscalls/setitimer/setitimer01.c +36 -20
@@ -18,9 +18,11 @@#include "tst_test.h" #include "lapi/syscalls.h" -#define USEC1 10000 -#define USEC2 20000 +#define SEC1 300 +#define SEC2 600 +#define USEC 100 +static volatile unsigned long sigcnt;static struct itimerval *value, *ovalue; static struct tcase {
@@ -38,17 +40,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)
@@ -57,23 +59,37 @@ static void verify_setitimer(unsigned int i)int status;struct tcase *tc = &tcases[i]; - pid =SAFE_FORK (); +tst_res (TINFO ,"tc->which = %s" , tc->des); -if (pid ==0 ) { -tst_res (TINFO ,"tc->which = %s" , tc->des); +set_setitimer_value (SEC1 ,USEC ); +TST_EXP_PASS_SILENT (sys_setitimer (tc->which, value,NULL )); + +set_setitimer_value (SEC2 ,USEC ); +TST_EXP_PASS_SILENT (sys_setitimer (tc->which, value, ovalue)); +TST_EXP_EQ_LI (ovalue->it_interval.tv_sec,SEC1 ); +TST_EXP_EQ_LI (ovalue->it_interval.tv_usec,USEC ); + +if (ovalue->it_value.tv_sec + ovalue->it_value.tv_usec/1000000 <=SEC1 ) +tst_res (TPASS ,"old timer value is within the expected range" ); +else +tst_res (TFAIL ,"old timer value is not within the expected range" ); + + pid =SAFE_FORK (); +if (pid ==0 ) {tst_no_corefile (0 ); -set_setitimer_value (USEC1 ,0 ); +SAFE_SIGNAL (tc->signo, sig_routine); + +set_setitimer_value (0 ,USEC );TST_EXP_PASS (sys_setitimer (tc->which, value,NULL )); -set_setitimer_value (USEC2 ,USEC2 ); -TST_EXP_PASS (sys_setitimer (tc->which, value, ovalue)); +while (sigcnt <=10UL ) + ; -if (ovalue->it_value.tv_sec !=0 || ovalue->it_value.tv_usec >=USEC2 ) -tst_brk (TFAIL ,"old timer value is not within the expected range" ); +SAFE_SIGNAL (tc->signo,SIG_DFL ); -for (;;) +while (1 ) ; }
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 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.
--- .../kernel/syscalls/getitimer/getitimer01.c | 59 +++++++++++++++---- 1 file changed, 46 insertions(+), 13 deletions(-)
testcases/kernel/syscalls/getitimer/getitimer01.c +46 -13
@@ -13,24 +13,57 @@#include "tst_test.h" -static int itimer_name[] = { -ITIMER_REAL , -ITIMER_VIRTUAL , -ITIMER_PROF , +static struct itimerval *value; + +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) { -long unsigned int i; -struct itimerval value; + value->it_value.tv_sec = sec; + value->it_value.tv_usec = usec; + value->it_interval.tv_sec = sec; + value->it_interval.tv_usec = usec; +} -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 ); - } +static void verify_getitimer (unsigned int i) +{ +struct tcase *tc = &tcases[i]; + +tst_res (TINFO ,"tc->which = %s" , tc->des); +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 (100 ,100 ); +TST_EXP_PASS_SILENT (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,100 ); +TST_EXP_EQ_LI (value->it_interval.tv_usec,100 ); + +if (value->it_value.tv_sec + value->it_value.tv_usec/1000000 <=100 ) +tst_res (TPASS ,"timer value is within the expected range" ); +else +tst_res (TFAIL ,"timer value is not within the expected range" ); }static struct tst_test test = { - .test_all = run + .tcnt =ARRAY_SIZE (tcases), + .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
Plz ignore this patch, it needs code rebase after Anderea's work:
b606a7c7d setitimer01: Fix checking of setitimer() parameters
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hello Li,
Quoted 7 lines · Li Wang
Plz ignore this patch, it needs code rebase after Anderea's work:
b606a7c7dsetitimer01: Fix checking ofsetitimer()parametersSignature · 2 lines
Regards, Li Wang
I'll set to "changes requested" in patchwork. Plase can you update Patchwork in the future?
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 6 lines · Richard Palethorpe
Hello Li,
Quoted 2 lines · Li Wang
Plz ignore this patch, it needs code rebase after Anderea's work:
Quoted 9 lines
Quoted 5 lines
b606a7c7dsetitimer01: Fix checking ofsetitimer()parameters--
Regards,
Li WangI'll set to "changes requested" in patchwork. Plase can you update Patchwork in the future?
Yes, I should do that but I somehow forget. sorry~
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp