diff mbox

[API-NEXT,v2,2/2] validation: time: update to tes global time API

Message ID 1450700273-20473-3-git-send-email-ivan.khoronzhuk@linaro.org
State Accepted
Commit 5dfe37d912f9d7329c361eb14709ed0e84a90a8d
Headers show

Commit Message

Ivan Khoronzhuk Dec. 21, 2015, 12:17 p.m. UTC
Mostly global time API is tested in the same way, so reuse
existent functions.

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

Patch

diff --git a/test/validation/time/time.c b/test/validation/time/time.c
index add1be8..8b469b0 100644
--- a/test/validation/time/time.c
+++ b/test/validation/time/time.c
@@ -14,9 +14,14 @@ 
 #define MAX_TIME_RATE		15000000000
 #define DELAY_TOLERANCE		20000000	    /* deviation for delay */
 
-static uint64_t res;
+static uint64_t local_res;
+static uint64_t global_res;
 
-void time_test_odp_constants(void)
+typedef odp_time_t time_cb(void);
+typedef uint64_t time_res_cb(void);
+typedef odp_time_t time_from_ns_cb(uint64_t ns);
+
+void time_test_constants(void)
 {
 	uint64_t ns;
 
@@ -26,11 +31,11 @@  void time_test_odp_constants(void)
 	CU_ASSERT(ns == ODP_TIME_USEC_IN_NS);
 }
 
-void time_test_res(void)
+static void time_test_res(time_res_cb time_res, uint64_t res)
 {
 	uint64_t rate;
 
-	rate = odp_time_local_res();
+	rate = time_res();
 	CU_ASSERT(rate > MIN_TIME_RATE);
 	CU_ASSERT(rate < MAX_TIME_RATE);
 
@@ -38,15 +43,25 @@  void time_test_res(void)
 	res = res ? res : 1;
 }
 
+void time_test_local_res(void)
+{
+	time_test_res(odp_time_local_res, local_res);
+}
+
+void time_test_global_res(void)
+{
+	time_test_res(odp_time_global_res, global_res);
+}
+
 /* check that related conversions come back to the same value */
-void time_test_odp_conversion(void)
+static void time_test_conversion(time_from_ns_cb time_from_ns, uint64_t res)
 {
 	uint64_t ns1, ns2;
 	odp_time_t time;
 	uint64_t upper_limit, lower_limit;
 
 	ns1 = 100;
-	time = odp_time_local_from_ns(ns1);
+	time = time_from_ns(ns1);
 
 	ns2 = odp_time_to_ns(time);
 
@@ -57,7 +72,7 @@  void time_test_odp_conversion(void)
 	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
 
 	ns1 = 60 * 11 * ODP_TIME_SEC_IN_NS;
-	time = odp_time_local_from_ns(ns1);
+	time = time_from_ns(ns1);
 
 	ns2 = odp_time_to_ns(time);
 
@@ -72,25 +87,35 @@  void time_test_odp_conversion(void)
 	CU_ASSERT(ns1 == 0);
 }
 
-void time_test_monotony(void)
+void time_test_local_conversion(void)
+{
+	time_test_conversion(odp_time_local_from_ns, local_res);
+}
+
+void time_test_global_conversion(void)
+{
+	time_test_conversion(odp_time_global_from_ns, global_res);
+}
+
+static void time_test_monotony(time_cb time)
 {
 	volatile uint64_t count = 0;
 	odp_time_t t1, t2, t3;
 	uint64_t ns1, ns2, ns3;
 
-	t1 = odp_time_local();
+	t1 = time();
 
 	while (count < BUSY_LOOP_CNT) {
 		count++;
 	};
 
-	t2 = odp_time_local();
+	t2 = time();
 
 	while (count < BUSY_LOOP_CNT_LONG) {
 		count++;
 	};
 
-	t3 = odp_time_local();
+	t3 = time();
 
 	ns1 = odp_time_to_ns(t1);
 	ns2 = odp_time_to_ns(t2);
@@ -100,25 +125,35 @@  void time_test_monotony(void)
 	CU_ASSERT(ns3 > ns2);
 }
 
-void time_test_odp_cmp(void)
+void time_test_local_monotony(void)
+{
+	time_test_monotony(odp_time_local);
+}
+
+void time_test_global_monotony(void)
+{
+	time_test_monotony(odp_time_global);
+}
+
+static void time_test_cmp(time_cb time, time_from_ns_cb time_from_ns)
 {
 	/* volatile to stop optimization of busy loop */
 	volatile int count = 0;
 	odp_time_t t1, t2, t3;
 
-	t1 = odp_time_local();
+	t1 = time();
 
 	while (count < BUSY_LOOP_CNT) {
 		count++;
 	};
 
-	t2 = odp_time_local();
+	t2 = time();
 
 	while (count < BUSY_LOOP_CNT * 2) {
 		count++;
 	};
 
-	t3 = odp_time_local();
+	t3 = time();
 
 	CU_ASSERT(odp_time_cmp(t2, t1) > 0);
 	CU_ASSERT(odp_time_cmp(t3, t2) > 0);
@@ -130,18 +165,30 @@  void time_test_odp_cmp(void)
 	CU_ASSERT(odp_time_cmp(t2, t2) == 0);
 	CU_ASSERT(odp_time_cmp(t3, t3) == 0);
 
-	t2 = odp_time_local_from_ns(60 * 10 * ODP_TIME_SEC_IN_NS);
-	t1 = odp_time_local_from_ns(3);
+	t2 = time_from_ns(60 * 10 * ODP_TIME_SEC_IN_NS);
+	t1 = time_from_ns(3);
 
 	CU_ASSERT(odp_time_cmp(t2, t1) > 0);
 	CU_ASSERT(odp_time_cmp(t1, t2) < 0);
 
-	t1 = odp_time_local_from_ns(0);
+	t1 = time_from_ns(0);
 	CU_ASSERT(odp_time_cmp(t1, ODP_TIME_NULL) == 0);
 }
 
+void time_test_local_cmp(void)
+{
+	time_test_cmp(odp_time_local, odp_time_local_from_ns);
+}
+
+void time_test_global_cmp(void)
+{
+	time_test_cmp(odp_time_global, odp_time_global_from_ns);
+}
+
 /* check that a time difference gives a reasonable result */
-void time_test_odp_diff(void)
+static void time_test_diff(time_cb time,
+			   time_from_ns_cb time_from_ns,
+			   uint64_t res)
 {
 	/* volatile to stop optimization of busy loop */
 	volatile int count = 0;
@@ -150,13 +197,13 @@  void time_test_odp_diff(void)
 	uint64_t upper_limit, lower_limit;
 
 	/* test timestamp diff */
-	t1 = odp_time_local();
+	t1 = time();
 
 	while (count < BUSY_LOOP_CNT) {
 		count++;
 	};
 
-	t2 = odp_time_local();
+	t2 = time();
 	CU_ASSERT(odp_time_cmp(t2, t1) > 0);
 
 	diff = odp_time_diff(t2, t1);
@@ -173,7 +220,7 @@  void time_test_odp_diff(void)
 
 	/* test timestamp and interval diff */
 	ns1 = 54;
-	t1 = odp_time_local_from_ns(ns1);
+	t1 = time_from_ns(ns1);
 	ns = ns2 - ns1;
 
 	diff = odp_time_diff(t2, t1);
@@ -188,7 +235,7 @@  void time_test_odp_diff(void)
 	ns2 = 60 * 10 * ODP_TIME_SEC_IN_NS;
 	ns = ns2 - ns1;
 
-	t2 = odp_time_local_from_ns(ns2);
+	t2 = time_from_ns(ns2);
 	diff = odp_time_diff(t2, t1);
 	CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0);
 	nsdiff = odp_time_to_ns(diff);
@@ -205,17 +252,29 @@  void time_test_odp_diff(void)
 	CU_ASSERT(odp_time_cmp(t2, diff) == 0);
 }
 
+void time_test_local_diff(void)
+{
+	time_test_diff(odp_time_local, odp_time_local_from_ns, local_res);
+}
+
+void time_test_global_diff(void)
+{
+	time_test_diff(odp_time_global, odp_time_global_from_ns, global_res);
+}
+
 /* check that a time sum gives a reasonable result */
-void time_test_odp_sum(void)
+static void time_test_sum(time_cb time,
+			  time_from_ns_cb time_from_ns,
+			  uint64_t res)
 {
 	odp_time_t sum, t1, t2;
 	uint64_t nssum, ns1, ns2, ns;
 	uint64_t upper_limit, lower_limit;
 
 	/* sum timestamp and interval */
-	t1 = odp_time_local();
+	t1 = time();
 	ns2 = 103;
-	t2 = odp_time_local_from_ns(ns2);
+	t2 = time_from_ns(ns2);
 	ns1 = odp_time_to_ns(t1);
 	ns = ns1 + ns2;
 
@@ -229,7 +288,7 @@  void time_test_odp_sum(void)
 
 	/* sum intervals */
 	ns1 = 60 * 13 * ODP_TIME_SEC_IN_NS;
-	t1 = odp_time_local_from_ns(ns1);
+	t1 = time_from_ns(ns1);
 	ns = ns1 + ns2;
 
 	sum = odp_time_sum(t2, t1);
@@ -245,32 +304,50 @@  void time_test_odp_sum(void)
 	CU_ASSERT(odp_time_cmp(t2, sum) == 0);
 }
 
-void time_test_wait_until(void)
+void time_test_local_sum(void)
+{
+	time_test_sum(odp_time_local, odp_time_local_from_ns, local_res);
+}
+
+void time_test_global_sum(void)
+{
+	time_test_sum(odp_time_global, odp_time_global_from_ns, global_res);
+}
+
+static void time_test_wait_until(time_cb time, time_from_ns_cb time_from_ns)
 {
 	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);
+	odp_time_t second = time_from_ns(ODP_TIME_SEC_IN_NS);
 
-	start_time = odp_time_local();
+	start_time = time();
 	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();
+	end_time = time();
 
 	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);
+	lower_limit = time_from_ns(5 * ODP_TIME_SEC_IN_NS - DELAY_TOLERANCE);
+	upper_limit = time_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_local_wait_until(void)
+{
+	time_test_wait_until(odp_time_local, odp_time_local_from_ns);
+}
+
+void time_test_global_wait_until(void)
+{
+	time_test_wait_until(odp_time_global, odp_time_global_from_ns);
+}
+
 void time_test_wait_ns(void)
 {
 	int i;
@@ -295,13 +372,13 @@  void time_test_wait_ns(void)
 	CU_ASSERT(odp_time_cmp(diff, upper_limit) <= 0);
 }
 
-void time_test_odp_to_u64(void)
+static void time_test_to_u64(time_cb time)
 {
 	volatile int count = 0;
 	uint64_t val1, val2;
 	odp_time_t t1, t2;
 
-	t1 = odp_time_local();
+	t1 = time();
 
 	val1 = odp_time_to_u64(t1);
 	CU_ASSERT(val1 > 0);
@@ -310,7 +387,7 @@  void time_test_odp_to_u64(void)
 		count++;
 	};
 
-	t2 = odp_time_local();
+	t2 = time();
 	val2 = odp_time_to_u64(t2);
 	CU_ASSERT(val2 > 0);
 
@@ -320,17 +397,35 @@  void time_test_odp_to_u64(void)
 	CU_ASSERT(val1 == 0);
 }
 
+void time_test_local_to_u64(void)
+{
+	time_test_to_u64(odp_time_local);
+}
+
+void time_test_global_to_u64(void)
+{
+	time_test_to_u64(odp_time_global);
+}
+
 odp_testinfo_t time_suite_time[] = {
-	ODP_TEST_INFO(time_test_odp_constants),
-	ODP_TEST_INFO(time_test_res),
-	ODP_TEST_INFO(time_test_odp_conversion),
-	ODP_TEST_INFO(time_test_monotony),
-	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_constants),
+	ODP_TEST_INFO(time_test_local_res),
+	ODP_TEST_INFO(time_test_local_conversion),
+	ODP_TEST_INFO(time_test_local_monotony),
+	ODP_TEST_INFO(time_test_local_cmp),
+	ODP_TEST_INFO(time_test_local_diff),
+	ODP_TEST_INFO(time_test_local_sum),
+	ODP_TEST_INFO(time_test_local_wait_until),
 	ODP_TEST_INFO(time_test_wait_ns),
-	ODP_TEST_INFO(time_test_odp_to_u64),
+	ODP_TEST_INFO(time_test_local_to_u64),
+	ODP_TEST_INFO(time_test_global_res),
+	ODP_TEST_INFO(time_test_global_conversion),
+	ODP_TEST_INFO(time_test_global_monotony),
+	ODP_TEST_INFO(time_test_global_cmp),
+	ODP_TEST_INFO(time_test_global_diff),
+	ODP_TEST_INFO(time_test_global_sum),
+	ODP_TEST_INFO(time_test_global_wait_until),
+	ODP_TEST_INFO(time_test_global_to_u64),
 	ODP_TEST_INFO_NULL
 };
 
diff --git a/test/validation/time/time.h b/test/validation/time/time.h
index c2330f8..d75b0f5 100644
--- a/test/validation/time/time.h
+++ b/test/validation/time/time.h
@@ -10,16 +10,24 @@ 
 #include <odp_cunit_common.h>
 
 /* test functions: */
-void time_test_odp_constants(void);
-void time_test_res(void);
-void time_test_odp_conversion(void);
-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_constants(void);
+void time_test_local_res(void);
+void time_test_global_res(void);
+void time_test_local_conversion(void);
+void time_test_global_conversion(void);
+void time_test_local_monotony(void);
+void time_test_global_monotony(void);
+void time_test_local_cmp(void);
+void time_test_global_cmp(void);
+void time_test_local_diff(void);
+void time_test_global_diff(void);
+void time_test_local_sum(void);
+void time_test_global_sum(void);
+void time_test_local_wait_until(void);
+void time_test_global_wait_until(void);
 void time_test_wait_ns(void);
-void time_test_odp_to_u64(void);
+void time_test_local_to_u64(void);
+void time_test_global_to_u64(void);
 
 /* test arrays: */
 extern odp_testinfo_t time_suite_time[];