[LTP] [PATCH 1/2] setitimer01: add interval timer test
Li Wang
liwang@redhat.com
Sat Nov 12 05:01:06 CET 2022
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 <liwang@redhat.com>
---
.../kernel/syscalls/setitimer/setitimer01.c | 63 ++++++++++++-------
1 file changed, 39 insertions(+), 24 deletions(-)
diff --git a/testcases/kernel/syscalls/setitimer/setitimer01.c b/testcases/kernel/syscalls/setitimer/setitimer01.c
index 1f631d457..260590b0e 100644
--- a/testcases/kernel/syscalls/setitimer/setitimer01.c
+++ b/testcases/kernel/syscalls/setitimer/setitimer01.c
@@ -22,8 +22,10 @@
#include "tst_safe_clocks.h"
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,54 +42,66 @@ 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)
{
pid_t pid;
int status;
- long margin;
struct tcase *tc = &tcases[i];
+ tst_res(TINFO, "tc->which = %s", tc->des);
+
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(2 * time_sec, 2 * 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
* time_step afterward the elapsed time to make sure that
* at least counters take effect.
*/
- margin = tc->which == ITIMER_REAL ? 0 : time_step;
+ long margin = (tc->which == ITIMER_REAL) ? 0 : time_step;
- if (ovalue->it_value.tv_sec != 0 || ovalue->it_value.tv_usec > time_count + margin)
+ if (ovalue->it_value.tv_sec > time_sec ||
+ ovalue->it_value.tv_usec > time_usec + margin)
tst_res(TFAIL, "Ending counters are out of range");
- for (;;)
+ SAFE_SIGNAL(tc->signo, sig_routine);
+
+ set_setitimer_value(0, time_usec);
+ TST_EXP_PASS(sys_setitimer(tc->which, value, NULL));
+
+ while (sigcnt <= 10UL)
+ ;
+
+ SAFE_SIGNAL(tc->signo, SIG_DFL);
+
+ while (1)
;
}
@@ -114,10 +128,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 = {
--
2.35.3
More information about the ltp
mailing list