public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] setitimer01: add interval timer test
Date: Tue, 25 Oct 2022 20:18:52 +0800	[thread overview]
Message-ID: <20221025121853.3590372-1-liwang@redhat.com> (raw)

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.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 .../kernel/syscalls/setitimer/setitimer01.c   | 56 ++++++++++++-------
 1 file changed, 36 insertions(+), 20 deletions(-)

diff --git a/testcases/kernel/syscalls/setitimer/setitimer01.c b/testcases/kernel/syscalls/setitimer/setitimer01.c
index f04cb5a69..a59a9af1b 100644
--- a/testcases/kernel/syscalls/setitimer/setitimer01.c
+++ b/testcases/kernel/syscalls/setitimer/setitimer01.c
@@ -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)
 			;
 	}
 
-- 
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2022-10-25 12:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 12:18 Li Wang [this message]
2022-10-25 12:18 ` [LTP] [PATCH 2/2] getitimer01: add checking for nonzero timer Li Wang
2022-11-04  7:08 ` [LTP] [PATCH 1/2] setitimer01: add interval timer test Li Wang
2022-11-07 12:11   ` Richard Palethorpe
2022-11-08  1:14     ` Li Wang
  -- strict thread matches above, loose matches on Subject: below --
2022-11-12  4:01 Li Wang
2022-11-14 14:32 ` Richard Palethorpe
2022-11-15  4:00   ` Li Wang
2022-11-15  8:44     ` Richard Palethorpe
2022-11-15 10:00       ` Li Wang
2022-11-15 10:08         ` Li Wang
2022-11-15 11:04           ` Richard Palethorpe
2022-11-16 10:25             ` Li Wang
2022-11-15  9:27     ` Andrea Cervesato via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221025121853.3590372-1-liwang@redhat.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox