diff mbox

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

Message ID 1450440867-5891-3-git-send-email-ivan.khoronzhuk@linaro.org
State New
Headers show

Commit Message

Ivan Khoronzhuk Dec. 18, 2015, 12:14 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 | 160 +++++++++++++++++++++++++++++++++-----------
 test/validation/time/time.h |  23 ++++---
 2 files changed, 137 insertions(+), 46 deletions(-)

Comments

Ivan Khoronzhuk Dec. 21, 2015, 10:59 a.m. UTC | #1
On 21.12.15 10:50, Savolainen, Petri (Nokia - FI/Espoo) wrote:
>
>
>> -----Original Message-----
>> From: EXT Ivan Khoronzhuk [mailto:ivan.khoronzhuk@linaro.org]
>> Sent: Friday, December 18, 2015 2:14 PM
>> To: lng-odp@lists.linaro.org
>> Cc: Savolainen, Petri (Nokia - FI/Espoo); Ivan Khoronzhuk
>> Subject: [lng-odp] [API-NEXT PATCH 2/2] validation: time: update to tes
>> global time API also
>>
>> 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 | 160 +++++++++++++++++++++++++++++++++------
>> -----
>>   test/validation/time/time.h |  23 ++++---
>>   2 files changed, 137 insertions(+), 46 deletions(-)
>>
>> diff --git a/test/validation/time/time.c b/test/validation/time/time.c
>> index add1be8..8ef095e 100644
>> --- a/test/validation/time/time.c
>> +++ b/test/validation/time/time.c
>> @@ -14,9 +14,10 @@
>>   #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)
>> +void time_test_constants(void)
>>   {
>>   	uint64_t ns;
>>
>> @@ -26,11 +27,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(uint64_t time_res(void), uint64_t res)
>                               ^^^^^^^^^^^^^^^^^^^^^^^
>
>
> I'd typedef all these callback function prototypes. Some of those prototypes are defined multiple times.
>  Also  the function parameter list is more readable when callbacks are typedef'ed.
>
>
> -Petri
IMHO, it's more readable when it's not typedefed.

>
>
>
>
>
>>   {
>>   	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 +39,26 @@ void time_test_res(void)
>>   	res = res ? res : 1;
>>   }
diff mbox

Patch

diff --git a/test/validation/time/time.c b/test/validation/time/time.c
index add1be8..8ef095e 100644
--- a/test/validation/time/time.c
+++ b/test/validation/time/time.c
@@ -14,9 +14,10 @@ 
 #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)
+void time_test_constants(void)
 {
 	uint64_t ns;
 
@@ -26,11 +27,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(uint64_t time_res(void), 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 +39,26 @@  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(odp_time_t time_from_ns(uint64_t 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 +69,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 +84,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(odp_time_t time(void))
 {
 	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 +122,36 @@  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(odp_time_t time(void),
+			  odp_time_t time_from_ns(uint64_t 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 +163,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(odp_time_t time(void),
+			   odp_time_t time_from_ns(uint64_t ns),
+			   uint64_t res)
 {
 	/* volatile to stop optimization of busy loop */
 	volatile int count = 0;
@@ -150,13 +195,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 +218,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 +233,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 +250,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(odp_time_t time(void),
+			  odp_time_t time_from_ns(uint64_t 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 +286,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,6 +302,16 @@  void time_test_odp_sum(void)
 	CU_ASSERT(odp_time_cmp(t2, sum) == 0);
 }
 
+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);
+}
+
 void time_test_wait_until(void)
 {
 	int i;
@@ -295,13 +362,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(odp_time_t time(void))
 {
 	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 +377,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 +387,34 @@  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_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_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_to_u64),
 	ODP_TEST_INFO_NULL
 };
 
diff --git a/test/validation/time/time.h b/test/validation/time/time.h
index c2330f8..b734139 100644
--- a/test/validation/time/time.h
+++ b/test/validation/time/time.h
@@ -10,16 +10,23 @@ 
 #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_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_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[];