[2/4] time: Ignore interval nanoseconds on tst-itimer

Message ID 20210719163846.2954193-3-adhemerval.zanella@linaro.org
State Committed
Headers
Series 64-bit time_t tests improvements |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella July 19, 2021, 4:38 p.m. UTC
  Running the test on a 4.4 kernel within KVM, the precision used on
ITIMER_VIRTUAL and ITIMER_PROF seems to different than the one used
for ITIMER_REAL (it seems the same used for CLOCK_REALTIME_COARSE and
CLOCK_MONOTONIC_COARSE).  I did not see it on other kernels, for
instance 5.11 and 4.15.

To avoid trying to guess the resolution used, do not check the
nanosecond internal values for the specific timers.

Checked on i686-linux-gnu with a 4.4 kernel.
---
 time/tst-itimer.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Adhemerval Zanella Oct. 4, 2021, 11:43 a.m. UTC | #1
I will commit this patch shortly if no one opposes it.

On 19/07/2021 13:38, Adhemerval Zanella wrote:
> Running the test on a 4.4 kernel within KVM, the precision used on
> ITIMER_VIRTUAL and ITIMER_PROF seems to different than the one used
> for ITIMER_REAL (it seems the same used for CLOCK_REALTIME_COARSE and
> CLOCK_MONOTONIC_COARSE).  I did not see it on other kernels, for
> instance 5.11 and 4.15.
> 
> To avoid trying to guess the resolution used, do not check the
> nanosecond internal values for the specific timers.
> 
> Checked on i686-linux-gnu with a 4.4 kernel.
> ---
>  time/tst-itimer.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/time/tst-itimer.c b/time/tst-itimer.c
> index 929c2b74c7..554caa75f2 100644
> --- a/time/tst-itimer.c
> +++ b/time/tst-itimer.c
> @@ -74,6 +74,9 @@ do_test (void)
>  	{
>  	  TEST_COMPARE (it_old.it_interval.tv_sec, 10);
>  	  TEST_COMPARE (it_old.it_interval.tv_usec, 20);
> +	  /* Some systems might use a different precision for ITIMER_VIRTUAL
> +	     and ITIMER_iPROF and thus the value might be adjusted.  To avoid
> +	     trying to guess the resolution, we do not check it.  */
>  	}
>  
>        /* Create a periodic timer and check if the return value is the one
> @@ -87,7 +90,8 @@ do_test (void)
>        TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
>  		    0);
>        TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
> -      TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
> +      if (timers[i] == ITIMER_REAL)
> +	TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
>  
>        if (sizeof (time_t) == 4)
>  	continue;
>
  

Patch

diff --git a/time/tst-itimer.c b/time/tst-itimer.c
index 929c2b74c7..554caa75f2 100644
--- a/time/tst-itimer.c
+++ b/time/tst-itimer.c
@@ -74,6 +74,9 @@  do_test (void)
 	{
 	  TEST_COMPARE (it_old.it_interval.tv_sec, 10);
 	  TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+	  /* Some systems might use a different precision for ITIMER_VIRTUAL
+	     and ITIMER_iPROF and thus the value might be adjusted.  To avoid
+	     trying to guess the resolution, we do not check it.  */
 	}
 
       /* Create a periodic timer and check if the return value is the one
@@ -87,7 +90,8 @@  do_test (void)
       TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
 		    0);
       TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
-      TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+      if (timers[i] == ITIMER_REAL)
+	TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
 
       if (sizeof (time_t) == 4)
 	continue;