diff mbox

[API-NEXT,v2,6/6] validation: time: add test for odp_time_wait()

Message ID 1450182567-7646-7-git-send-email-ivan.khoronzhuk@linaro.org
State New
Headers show

Commit Message

Ivan Khoronzhuk Dec. 15, 2015, 12:29 p.m. UTC
This patch adds validation test for odp_time_wait(). Also it visually
demonstrates 5 second count.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 test/validation/time/time.c | 26 ++++++++++++++++++++++++++
 test/validation/time/time.h |  1 +
 2 files changed, 27 insertions(+)
diff mbox

Patch

diff --git a/test/validation/time/time.c b/test/validation/time/time.c
index 0fe8c5a..482a91d 100644
--- a/test/validation/time/time.c
+++ b/test/validation/time/time.c
@@ -12,6 +12,7 @@ 
 #define BUSY_LOOP_CNT_LONG	12000000000 /* used for t > 4 sec */
 #define MIN_TIME_RATE		32000
 #define MAX_TIME_RATE		15000000000
+#define DELAY_TOLERANCE		50	    /* deviation for delay */
 
 static uint64_t res;
 
@@ -244,6 +245,30 @@  void time_test_odp_sum(void)
 	CU_ASSERT(odp_time_cmp(t2, sum) == 0);
 }
 
+void time_test_wait(void)
+{
+	int i;
+	odp_time_t start_time, end_time, diff;
+	odp_time_t lower_limit, upper_limit, tolerance;
+	odp_time_t second = odp_time_local_from_ns(ODP_TIME_SEC_IN_NS);
+
+	start_time = odp_time_local();
+	for (i = 1; i < 6; i++) {
+		odp_time_wait(second);
+		printf("%d..", i);
+	}
+	end_time = odp_time_local();
+
+	diff = odp_time_diff(end_time, start_time);
+	tolerance = odp_time_local_from_ns(DELAY_TOLERANCE);
+
+	lower_limit = odp_time_diff(diff, tolerance);
+	upper_limit = odp_time_sum(diff, tolerance);
+
+	CU_ASSERT(odp_time_cmp(diff, lower_limit) >= 0);
+	CU_ASSERT(odp_time_cmp(diff, upper_limit) <= 0);
+}
+
 void time_test_odp_to_u64(void)
 {
 	volatile int count = 0;
@@ -277,6 +302,7 @@  odp_testinfo_t time_suite_time[] = {
 	ODP_TEST_INFO(time_test_odp_cmp),
 	ODP_TEST_INFO(time_test_odp_diff),
 	ODP_TEST_INFO(time_test_odp_sum),
+	ODP_TEST_INFO(time_test_wait),
 	ODP_TEST_INFO(time_test_odp_to_u64),
 	ODP_TEST_INFO_NULL
 };
diff --git a/test/validation/time/time.h b/test/validation/time/time.h
index cf9495b..a97a3f3 100644
--- a/test/validation/time/time.h
+++ b/test/validation/time/time.h
@@ -17,6 +17,7 @@  void time_test_monotony(void);
 void time_test_odp_cmp(void);
 void time_test_odp_diff(void);
 void time_test_odp_sum(void);
+void time_test_wait(void);
 void time_test_odp_to_u64(void);
 
 /* test arrays: */