diff mbox

[API-NEXT,v5,6/6] validation: time: add test for odp_time_wait_ns() and odp_time_wait_until()

Message ID 1450440117-5588-7-git-send-email-ivan.khoronzhuk@linaro.org
State Accepted
Commit f726a512e2166996b1d1a7e7bde22bd79a455a9c
Headers show

Commit Message

Ivan Khoronzhuk Dec. 18, 2015, 12:01 p.m. UTC
This patch adds validation test for odp_time_wait_ns/until().
Also it visually demonstrates 5 second count.

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

Patch

diff --git a/test/validation/time/time.c b/test/validation/time/time.c
index 0fe8c5a..add1be8 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		20000000	    /* deviation for delay */
 
 static uint64_t res;
 
@@ -244,6 +245,56 @@  void time_test_odp_sum(void)
 	CU_ASSERT(odp_time_cmp(t2, sum) == 0);
 }
 
+void time_test_wait_until(void)
+{
+	int i;
+	odp_time_t lower_limit, upper_limit;
+	odp_time_t start_time, end_time, wait;
+	odp_time_t second = odp_time_local_from_ns(ODP_TIME_SEC_IN_NS);
+
+	start_time = odp_time_local();
+	wait = start_time;
+	for (i = 1; i < 6; i++) {
+		wait = odp_time_sum(wait, second);
+		odp_time_wait_until(wait);
+		printf("%d..", i);
+	}
+	end_time = odp_time_local();
+
+	wait = odp_time_diff(end_time, start_time);
+	lower_limit = odp_time_local_from_ns(5 * ODP_TIME_SEC_IN_NS -
+							DELAY_TOLERANCE);
+	upper_limit = odp_time_local_from_ns(5 * ODP_TIME_SEC_IN_NS +
+							DELAY_TOLERANCE);
+
+	CU_ASSERT(odp_time_cmp(wait, lower_limit) >= 0);
+	CU_ASSERT(odp_time_cmp(wait, upper_limit) <= 0);
+}
+
+void time_test_wait_ns(void)
+{
+	int i;
+	odp_time_t lower_limit, upper_limit;
+	odp_time_t start_time, end_time, diff;
+
+	start_time = odp_time_local();
+	for (i = 1; i < 6; i++) {
+		odp_time_wait_ns(ODP_TIME_SEC_IN_NS);
+		printf("%d..", i);
+	}
+	end_time = odp_time_local();
+
+	diff = odp_time_diff(end_time, start_time);
+
+	lower_limit = odp_time_local_from_ns(5 * ODP_TIME_SEC_IN_NS -
+							DELAY_TOLERANCE);
+	upper_limit = odp_time_local_from_ns(5 * ODP_TIME_SEC_IN_NS +
+							DELAY_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 +328,8 @@  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_until),
+	ODP_TEST_INFO(time_test_wait_ns),
 	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..c2330f8 100644
--- a/test/validation/time/time.h
+++ b/test/validation/time/time.h
@@ -17,6 +17,8 @@  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_until(void);
+void time_test_wait_ns(void);
 void time_test_odp_to_u64(void);
 
 /* test arrays: */