tests: Allow some difference in rounding in timeval test.
authorJesse Gross <jesse@nicira.com>
Thu, 10 Jun 2010 23:35:34 +0000 (16:35 -0700)
committerJesse Gross <jesse@nicira.com>
Thu, 10 Jun 2010 23:37:14 +0000 (16:37 -0700)
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

index f0552f8..b336f39 100644 (file)
@@ -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;
         }
     }