public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] Correctly check setitimer params in setitimer01
@ 2022-11-10 10:27 Andrea Cervesato via ltp
  2022-11-11  9:41 ` Li Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Andrea Cervesato via ltp @ 2022-11-10 10:27 UTC (permalink / raw)
  To: ltp

We use CLOCK_MONOTONIC_COARSE as our time resolution for checking
setitimer counter boundaries.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Margin in ITIMER_REAL is 0
Add some comments

 .../kernel/syscalls/setitimer/setitimer01.c   | 52 +++++++++++++------
 1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/testcases/kernel/syscalls/setitimer/setitimer01.c b/testcases/kernel/syscalls/setitimer/setitimer01.c
index eb62f02c6..e967577ed 100644
--- a/testcases/kernel/syscalls/setitimer/setitimer01.c
+++ b/testcases/kernel/syscalls/setitimer/setitimer01.c
@@ -8,7 +8,7 @@
 /*\
  * [Description]
  *
- * Spawn a child and verify that setitimer() syscall passes, and it ends up
+ * Spawn a child, verify that setitimer() syscall passes and it ends up
  * counting inside expected boundaries. Then verify from the parent that our
  * syscall sent the correct signal to the child.
  */
@@ -22,7 +22,8 @@
 #include "tst_safe_clocks.h"
 
 static struct itimerval *value, *ovalue;
-static unsigned long time_step;
+static long time_step;
+static long time_count;
 
 static struct tcase {
 	int which;
@@ -56,7 +57,7 @@ static void verify_setitimer(unsigned int i)
 {
 	pid_t pid;
 	int status;
-	int usec = 3 * time_step;
+	long margin;
 	struct tcase *tc = &tcases[i];
 
 	pid = SAFE_FORK();
@@ -66,7 +67,7 @@ static void verify_setitimer(unsigned int i)
 
 		tst_no_corefile(0);
 
-		set_setitimer_value(usec, 0);
+		set_setitimer_value(time_count, 0);
 		TST_EXP_PASS(sys_setitimer(tc->which, value, NULL));
 
 		set_setitimer_value(5 * time_step, 7 * time_step);
@@ -76,7 +77,14 @@ static void verify_setitimer(unsigned int i)
 			ovalue->it_value.tv_sec,
 			ovalue->it_value.tv_usec);
 
-		if (ovalue->it_value.tv_sec != 0 || ovalue->it_value.tv_usec > 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;
+
+		if (ovalue->it_value.tv_sec != 0 || ovalue->it_value.tv_usec > time_count + margin)
 			tst_res(TFAIL, "Ending counters are out of range");
 
 		for (;;)
@@ -93,24 +101,34 @@ static void verify_setitimer(unsigned int i)
 
 static void setup(void)
 {
-	struct timespec res;
-
-	SAFE_CLOCK_GETRES(CLOCK_MONOTONIC, &res);
-
-	time_step = res.tv_nsec / 1000;
-	if (time_step < 10000)
-		time_step = 10000;
-
-	tst_res(TINFO, "clock resolution: %luns, time step: %luus",
-		res.tv_nsec,
-		time_step);
+	struct timespec time_res;
+
+	/*
+	 * We use CLOCK_MONOTONIC_COARSE resolution for all timers, since
+	 * we are sure its value is bigger than CLOCK_MONOTONIC and we can use
+	 * it for both realtime and virtual/prof timers resolutions.
+	 */
+	SAFE_CLOCK_GETRES(CLOCK_MONOTONIC_COARSE, &time_res);
+
+	time_step = time_res.tv_nsec / 1000;
+	if (time_step <= 0)
+		time_step = 1000;
+
+	time_count = 3 * time_step;
+
+	tst_res(TINFO, "clock resolution: %luns, "
+		"time step: %luus, "
+		"time count: %luus",
+		time_res.tv_nsec,
+		time_step,
+		time_count);
 }
 
 static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.forks_child = 1,
-	.test = verify_setitimer,
 	.setup = setup,
+	.test = verify_setitimer,
 	.bufs = (struct tst_buffers[]) {
 		{&value,  .size = sizeof(struct itimerval)},
 		{&ovalue, .size = sizeof(struct itimerval)},
-- 
2.35.3


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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH v3] Correctly check setitimer params in setitimer01
  2022-11-10 10:27 [LTP] [PATCH v3] Correctly check setitimer params in setitimer01 Andrea Cervesato via ltp
@ 2022-11-11  9:41 ` Li Wang
  2022-11-11 20:57   ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Li Wang @ 2022-11-11  9:41 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp


[-- Attachment #1.1: Type: text/plain, Size: 829 bytes --]

Andrea Cervesato via ltp <ltp@lists.linux.it> wrote:


>  static void setup(void)
>  {
> ...
> +       struct timespec time_res;
> +
> +       /*
> +        * We use CLOCK_MONOTONIC_COARSE resolution for all timers, since
> +        * we are sure its value is bigger than CLOCK_MONOTONIC and we can
> use
> +        * it for both realtime and virtual/prof timers resolutions.
> +        */
> +       SAFE_CLOCK_GETRES(CLOCK_MONOTONIC_COARSE, &time_res);
> +
> +       time_step = time_res.tv_nsec / 1000;
> +       if (time_step <= 0)
> +               time_step = 1000;
> +
> +       time_count = 3 * time_step;
> +
> +       tst_res(TINFO, "clock resolution: %luns, "
>


I would use "low-resolution" for this output, but
someone merge patch can help modify it.

Reviewed-by: Li Wang <liwang@redhat.com>


-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 1737 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH v3] Correctly check setitimer params in setitimer01
  2022-11-11  9:41 ` Li Wang
@ 2022-11-11 20:57   ` Petr Vorel
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2022-11-11 20:57 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

Hi all,

...
> > +       tst_res(TINFO, "clock resolution: %luns, "


> I would use "low-resolution" for this output, but
> someone merge patch can help modify it.
I fixed that + slightly reword docs and commit message before merge
(using imperative mood).

Thanks a lot to all!

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-11 20:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-10 10:27 [LTP] [PATCH v3] Correctly check setitimer params in setitimer01 Andrea Cervesato via ltp
2022-11-11  9:41 ` Li Wang
2022-11-11 20:57   ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox