[ovs-dev] [PATCH] tests: Allow some difference in rounding in timeval test.

Jesse Gross jesse at nicira.com
Thu Jun 10 23:40:58 UTC 2010


We now use a time source that provides nanosecond granularity.
However, our test uses gettimeofday() for comparision, which has
microsecond granularity.  In some cases this can lead to different
values depending on the rounding.  This allows us to be off by one
to prevent intermittent test failures.
---
 tests/test-timeval.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tests/test-timeval.c b/tests/test-timeval.c
index f0552f8..b336f39 100644
--- a/tests/test-timeval.c
+++ b/tests/test-timeval.c
@@ -70,8 +70,12 @@ do_test(void)
         }
 
         if (gettimeofday_in_msec() - start_gtod >= TIME_UPDATE_INTERVAL) {
-            assert(time_msec() - start_time_msec >= TIME_UPDATE_INTERVAL);
-            assert(time_wall_msec() - start_time_wall >= TIME_UPDATE_INTERVAL);
+            /* gettimeofday() and time_msec() have different granularities in
+             * their time sources.  Depending on the rounding used this could
+             * result in a slight difference, so we allow for 1 ms of slop. */
+            assert(time_msec() - start_time_msec >= TIME_UPDATE_INTERVAL - 1);
+            assert(time_wall_msec() - start_time_wall >=
+                                                      TIME_UPDATE_INTERVAL - 1);
             break;
         }
     }
-- 
1.7.0.4





More information about the dev mailing list