validation: time: use timer resolution instead of TOLERANCE

Message ID 1439567936-8168-1-git-send-email-ivan.khoronzhuk@linaro.org
State New
Headers show

Commit Message

Ivan Khoronzhuk Aug. 14, 2015, 3:58 p.m.
The TOLERANCE hardcodes a timer resolution, so replace it on
real timer resolution that can be got by odp_time_tick_to_ns(1).

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---

Based on
"api: time: change API to use ticks instead of cycles"
https://lists.linaro.org/pipermail/lng-odp/2015-August/014198.html

 test/validation/time/time.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Patch

diff --git a/test/validation/time/time.c b/test/validation/time/time.c
index 89aef00..fa7e372 100644
--- a/test/validation/time/time.c
+++ b/test/validation/time/time.c
@@ -8,7 +8,6 @@ 
 #include "odp_cunit_common.h"
 #include "time.h"
 
-#define TOLERANCE 1
 #define BUSY_LOOP_CNT 100
 
 /* check that a counts difference gives a reasonable result */
@@ -45,9 +44,12 @@  static void time_test_odp_counts_negative_diff(void)
 /* check that related conversions come back to the same value */
 static void time_test_odp_time_conversion(void)
 {
-	uint64_t ns1, ns2, tick;
+	uint64_t ns1, ns2, res, tick;
 	uint64_t upper_limit, lower_limit;
 
+	/* get timer resolution */
+	res = odp_time_tick_to_ns(1) + 1;
+
 	ns1 = 100;
 	tick = odp_time_ns_to_tick(ns1);
 	CU_ASSERT(tick > 0);
@@ -56,8 +58,8 @@  static void time_test_odp_time_conversion(void)
 
 	/* need to check within arithmetic tolerance that the same
 	 * value in ns is returned after conversions */
-	upper_limit = ns1 + TOLERANCE;
-	lower_limit = ns1 - TOLERANCE;
+	upper_limit = ns1 + res;
+	lower_limit = ns1 - res;
 	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
 }