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 2/2] getitimer01: add checking for nonzero timer
Date: Tue, 25 Oct 2022 20:18:53 +0800	[thread overview]
Message-ID: <20221025121853.3590372-2-liwang@redhat.com> (raw)
In-Reply-To: <20221025121853.3590372-1-liwang@redhat.com>

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 <liwang@redhat.com>
---
 .../kernel/syscalls/getitimer/getitimer01.c   | 59 +++++++++++++++----
 1 file changed, 46 insertions(+), 13 deletions(-)

diff --git a/testcases/kernel/syscalls/getitimer/getitimer01.c b/testcases/kernel/syscalls/getitimer/getitimer01.c
index 5ecfac55c..41903db07 100644
--- a/testcases/kernel/syscalls/getitimer/getitimer01.c
+++ b/testcases/kernel/syscalls/getitimer/getitimer01.c
@@ -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)},
+		{}
+	}
 };
-- 
2.35.3


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

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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 12:18 [LTP] [PATCH 1/2] setitimer01: add interval timer test Li Wang
2022-10-25 12:18 ` Li Wang [this message]
2022-11-04  7:08 ` 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-12  4:01 ` [LTP] [PATCH 2/2] getitimer01: add checking for nonzero timer Li Wang
2022-11-14 16:02   ` Richard Palethorpe

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-2-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