diff mbox

[API-NEXT,v3,7/7] validation: time: align tests with current time API

Message ID 1448313655-7949-8-git-send-email-ivan.khoronzhuk@linaro.org
State Superseded
Headers show

Commit Message

Ivan Khoronzhuk Nov. 23, 2015, 9:20 p.m. UTC
Add test for odp_time_sum, odp_time_cmp, odp_time_to_u64 APIs.
Sophisticate a little tests for odp_time_diff, odp_time_local_from_ns,
odp_time_local_to_ns APIs. Check time on monotony.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 test/validation/time/time.c | 224 +++++++++++++++++++++++++++++++++++++++-----
 test/validation/time/time.h |   7 +-
 2 files changed, 207 insertions(+), 24 deletions(-)

Comments

Ivan Khoronzhuk Nov. 30, 2015, 2:47 p.m. UTC | #1
On 30.11.15 16:17, Savolainen, Petri (Nokia - FI/Espoo) wrote:
>
>
>> -----Original Message-----
>> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of EXT
>> Ivan Khoronzhuk
>> Sent: Monday, November 23, 2015 11:21 PM
>> To: lng-odp@lists.linaro.org
>> Subject: [lng-odp] [API-NEXT PATCH v3 7/7] validation: time: align tests
>> with current time API
>>
>> Add test for odp_time_sum, odp_time_cmp, odp_time_to_u64 APIs.
>> Sophisticate a little tests for odp_time_diff, odp_time_local_from_ns,
>> odp_time_local_to_ns APIs. Check time on monotony.
>>
>> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
>> ---
>>   test/validation/time/time.c | 224
>> +++++++++++++++++++++++++++++++++++++++-----
>>   test/validation/time/time.h |   7 +-
>>   2 files changed, 207 insertions(+), 24 deletions(-)
>>
>> diff --git a/test/validation/time/time.c b/test/validation/time/time.c
>> index 3d05a6f..8f5dfe6 100644
>> --- a/test/validation/time/time.c
>> +++ b/test/validation/time/time.c
>> @@ -11,13 +11,114 @@
>>   #define TOLERANCE 1
>>   #define BUSY_LOOP_CNT 100
>>
>> +/* check that related conversions come back to the same value */
>> +void time_test_odp_conversion(void)
>> +{
>> +	uint64_t ns1, ns2;
>> +	odp_time_t time;
>> +	uint64_t upper_limit, lower_limit;
>> +
>> +	ns1 = 100;
>> +	time = odp_time_local_from_ns(ns1);
>> +
>> +	ns2 = odp_time_to_ns(time);
>> +
>> +	/* need to check within arithmetic tolerance that the same
>> +	 * value in ns is returned after conversions */
>> +	upper_limit = ns1 + TOLERANCE;
>> +	lower_limit = ns1 - TOLERANCE;
>> +	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
>> +
>> +	ns1 = 60 * 11 * ODP_TIME_SEC_IN_NS;
>> +	time = odp_time_local_from_ns(ns1);
>> +
>> +	ns2 = odp_time_to_ns(time);
>> +
>> +	/* need to check within arithmetic tolerance that the same
>> +	 * value in ns is returned after conversions */
>> +	upper_limit = ns1 + TOLERANCE;
>> +	lower_limit = ns1 - TOLERANCE;
>> +	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
>> +}
>> +
>> +void time_test_monotony(void)
>> +{
>> +	volatile int count = 0;
>> +	odp_time_t t1, t2, t3;
>> +	uint64_t ns1, ns2, ns3;
>> +
>> +	t1 = odp_time_local();
>> +
>> +	while (count < BUSY_LOOP_CNT) {
>> +		count++;
>> +	};
>> +
>> +	t2 = odp_time_local();
>> +
>> +	while (count < BUSY_LOOP_CNT * 5) {
>> +		count++;
>> +	};
>> +
>> +	t3 = odp_time_local();
>
>
> These loops are short in execution time. So, the test will very likely to pass also when local time would wrap e.g. every 4 sec.
I can increase BUSY_LOOP_CNT, replace 100 number that is based on some freq like 3GHz and minimum resolution.
The resolution API I'm going to add after this series is applied, so for now lets suppose that this is 10ms.

then BYSY_LOOP_CNT for testing minimum time is = 0.01 * 3GHz = 30000000.
For some boards it can take in 3 times longer.


>
> At least one test should run at least e.g. 4sec to verify wrap around.
I don't suppose here that 32-bit counter is used for time API, so check is redundancy. But,
for long time intervals I've used conversion functions, it's checked in time_test_conversion test.
It's done in order to not increase time for validating time API.
If you OK to increase validation test for time API at least on 5sec I have no objection.

Currently ODP doesn't have correct way to read frequency for all arches.
So lets count 4seconds based on some freq = 3GHz, then iteration_num = 4sec * 3000 = 12 000 000 000.
It's bigger than 4seconds as iteration takes more than one simple cycle.
Then:
BUSY_LOOP_CNT = 1000, and test for time more that 4 sec => BUSY_LOOP_CNT = 1000 * 12.

But pay attention, that it can take more than 4sec * 3 * 2cycles = 24 seconds on boards with 3 time less frequency.
So test can be longer on half of minute!.

I propose to leave test as is here, and hope that time_test_odp_conversion caught issues.
What do you say?
  
>
> -Petri
>
Ivan Khoronzhuk Dec. 1, 2015, 8:20 a.m. UTC | #2
On 01.12.15 09:56, Savolainen, Petri (Nokia - FI/Espoo) wrote:
>
>
>> -----Original Message-----
>> From: EXT Ivan Khoronzhuk [mailto:ivan.khoronzhuk@linaro.org]
>> Sent: Monday, November 30, 2015 4:47 PM
>> To: Savolainen, Petri (Nokia - FI/Espoo); lng-odp@lists.linaro.org
>> Subject: Re: [lng-odp] [API-NEXT PATCH v3 7/7] validation: time: align
>> tests with current time API
>>
>>
>>
>> On 30.11.15 16:17, Savolainen, Petri (Nokia - FI/Espoo) wrote:
>>>
>>>
>>>> -----Original Message-----
>>>> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of
>> EXT
>>>> Ivan Khoronzhuk
>>>> Sent: Monday, November 23, 2015 11:21 PM
>>>> To: lng-odp@lists.linaro.org
>>>> Subject: [lng-odp] [API-NEXT PATCH v3 7/7] validation: time: align
>> tests
>>>> with current time API
>>>>
>>>> Add test for odp_time_sum, odp_time_cmp, odp_time_to_u64 APIs.
>>>> Sophisticate a little tests for odp_time_diff, odp_time_local_from_ns,
>>>> odp_time_local_to_ns APIs. Check time on monotony.
>>>>
>>>> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
>>>> ---
>>>>    test/validation/time/time.c | 224
>>>> +++++++++++++++++++++++++++++++++++++++-----
>>>>    test/validation/time/time.h |   7 +-
>>>>    2 files changed, 207 insertions(+), 24 deletions(-)
>>>>
>>>> diff --git a/test/validation/time/time.c b/test/validation/time/time.c
>>>> index 3d05a6f..8f5dfe6 100644
>>>> --- a/test/validation/time/time.c
>>>> +++ b/test/validation/time/time.c
>>>> @@ -11,13 +11,114 @@
>>>>    #define TOLERANCE 1
>>>>    #define BUSY_LOOP_CNT 100
>>>>
>>>> +/* check that related conversions come back to the same value */
>>>> +void time_test_odp_conversion(void)
>>>> +{
>>>> +	uint64_t ns1, ns2;
>>>> +	odp_time_t time;
>>>> +	uint64_t upper_limit, lower_limit;
>>>> +
>>>> +	ns1 = 100;
>>>> +	time = odp_time_local_from_ns(ns1);
>>>> +
>>>> +	ns2 = odp_time_to_ns(time);
>>>> +
>>>> +	/* need to check within arithmetic tolerance that the same
>>>> +	 * value in ns is returned after conversions */
>>>> +	upper_limit = ns1 + TOLERANCE;
>>>> +	lower_limit = ns1 - TOLERANCE;
>>>> +	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
>>>> +
>>>> +	ns1 = 60 * 11 * ODP_TIME_SEC_IN_NS;
>>>> +	time = odp_time_local_from_ns(ns1);
>>>> +
>>>> +	ns2 = odp_time_to_ns(time);
>>>> +
>>>> +	/* need to check within arithmetic tolerance that the same
>>>> +	 * value in ns is returned after conversions */
>>>> +	upper_limit = ns1 + TOLERANCE;
>>>> +	lower_limit = ns1 - TOLERANCE;
>>>> +	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
>>>> +}
>>>> +
>>>> +void time_test_monotony(void)
>>>> +{
>>>> +	volatile int count = 0;
>>>> +	odp_time_t t1, t2, t3;
>>>> +	uint64_t ns1, ns2, ns3;
>>>> +
>>>> +	t1 = odp_time_local();
>>>> +
>>>> +	while (count < BUSY_LOOP_CNT) {
>>>> +		count++;
>>>> +	};
>>>> +
>>>> +	t2 = odp_time_local();
>>>> +
>>>> +	while (count < BUSY_LOOP_CNT * 5) {
>>>> +		count++;
>>>> +	};
>>>> +
>>>> +	t3 = odp_time_local();
>>>
>>>
>>> These loops are short in execution time. So, the test will very likely
>> to pass also when local time would wrap e.g. every 4 sec.
>> I can increase BUSY_LOOP_CNT, replace 100 number that is based on some
>> freq like 3GHz and minimum resolution.
>> The resolution API I'm going to add after this series is applied, so for
>> now lets suppose that this is 10ms.
>>
>> then BYSY_LOOP_CNT for testing minimum time is = 0.01 * 3GHz = 30000000.
>> For some boards it can take in 3 times longer.
>>
>>
>>>
>>> At least one test should run at least e.g. 4sec to verify wrap around.
>> I don't suppose here that 32-bit counter is used for time API, so check is
>> redundancy. But,
>> for long time intervals I've used conversion functions, it's checked in
>> time_test_conversion test.
>> It's done in order to not increase time for validating time API.
>> If you OK to increase validation test for time API at least on 5sec I have
>> no objection.
>>
>> Currently ODP doesn't have correct way to read frequency for all arches.
>> So lets count 4seconds based on some freq = 3GHz, then iteration_num =
>> 4sec * 3000 = 12 000 000 000.
>> It's bigger than 4seconds as iteration takes more than one simple cycle.
>> Then:
>> BUSY_LOOP_CNT = 1000, and test for time more that 4 sec => BUSY_LOOP_CNT =
>> 1000 * 12.
>>
>> But pay attention, that it can take more than 4sec * 3 * 2cycles = 24
>> seconds on boards with 3 time less frequency.
>> So test can be longer on half of minute!.
>
>
> You don't need to busy loop >4sec on every step. It's enough that the entire time API validation test duration is >4sec, which is reasonable when we are testing time accuracy. Even a duration of >1sec would be good to test, since all those timespec.sec + timespec.nsec calculations may have bugs that are visible only when .sec is incremented.
>
> -Petri
>
Ok. It be 30 000 000 minimum and 12 000 000 000 for 4+ sec.

>
>
>>
>> I propose to leave test as is here, and hope that time_test_odp_conversion
>> caught issues.
>> What do you say?
>>
>>>
>>> -Petri
>>>
>>
>> --
>> Regards,
>> Ivan Khoronzhuk
diff mbox

Patch

diff --git a/test/validation/time/time.c b/test/validation/time/time.c
index 3d05a6f..8f5dfe6 100644
--- a/test/validation/time/time.c
+++ b/test/validation/time/time.c
@@ -11,13 +11,114 @@ 
 #define TOLERANCE 1
 #define BUSY_LOOP_CNT 100
 
+/* check that related conversions come back to the same value */
+void time_test_odp_conversion(void)
+{
+	uint64_t ns1, ns2;
+	odp_time_t time;
+	uint64_t upper_limit, lower_limit;
+
+	ns1 = 100;
+	time = odp_time_local_from_ns(ns1);
+
+	ns2 = odp_time_to_ns(time);
+
+	/* need to check within arithmetic tolerance that the same
+	 * value in ns is returned after conversions */
+	upper_limit = ns1 + TOLERANCE;
+	lower_limit = ns1 - TOLERANCE;
+	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
+
+	ns1 = 60 * 11 * ODP_TIME_SEC_IN_NS;
+	time = odp_time_local_from_ns(ns1);
+
+	ns2 = odp_time_to_ns(time);
+
+	/* need to check within arithmetic tolerance that the same
+	 * value in ns is returned after conversions */
+	upper_limit = ns1 + TOLERANCE;
+	lower_limit = ns1 - TOLERANCE;
+	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
+}
+
+void time_test_monotony(void)
+{
+	volatile int count = 0;
+	odp_time_t t1, t2, t3;
+	uint64_t ns1, ns2, ns3;
+
+	t1 = odp_time_local();
+
+	while (count < BUSY_LOOP_CNT) {
+		count++;
+	};
+
+	t2 = odp_time_local();
+
+	while (count < BUSY_LOOP_CNT * 5) {
+		count++;
+	};
+
+	t3 = odp_time_local();
+
+	ns1 = odp_time_to_ns(t1);
+	ns2 = odp_time_to_ns(t2);
+	ns3 = odp_time_to_ns(t3);
+
+	CU_ASSERT(ns2 > ns1);
+	CU_ASSERT(ns3 > ns2);
+}
+
+void time_test_odp_cmp(void)
+{
+	/* volatile to stop optimization of busy loop */
+	volatile int count = 0;
+	odp_time_t t1, t2, t3;
+
+	t1 = odp_time_local();
+
+	while (count < BUSY_LOOP_CNT) {
+		count++;
+	};
+
+	t2 = odp_time_local();
+
+	while (count < BUSY_LOOP_CNT * 2) {
+		count++;
+	};
+
+	t3 = odp_time_local();
+
+	CU_ASSERT(odp_time_cmp(t2, t1) > 0);
+	CU_ASSERT(odp_time_cmp(t3, t2) > 0);
+	CU_ASSERT(odp_time_cmp(t3, t1) > 0);
+	CU_ASSERT(odp_time_cmp(t1, t2) < 0);
+	CU_ASSERT(odp_time_cmp(t2, t3) < 0);
+	CU_ASSERT(odp_time_cmp(t1, t3) < 0);
+	CU_ASSERT(odp_time_cmp(t1, t1) == 0);
+	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);
+
+	CU_ASSERT(odp_time_cmp(t2, t1) > 0);
+	CU_ASSERT(odp_time_cmp(t1, t2) < 0);
+
+	t1 = odp_time_local_from_ns(0);
+	CU_ASSERT(odp_time_cmp(t1, ODP_TIME_NULL) == 0);
+}
+
 /* check that a time difference gives a reasonable result */
 void time_test_odp_diff(void)
 {
 	/* volatile to stop optimization of busy loop */
 	volatile int count = 0;
 	odp_time_t diff, t1, t2;
+	uint64_t nsdiff, ns1, ns2, ns;
+	uint64_t upper_limit, lower_limit;
 
+	/* test timestamp diff */
 	t1 = odp_time_local();
 
 	while (count < BUSY_LOOP_CNT) {
@@ -29,43 +130,122 @@  void time_test_odp_diff(void)
 
 	diff = odp_time_diff(t2, t1);
 	CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0);
-}
 
-/* check that a negative time difference gives a reasonable result */
-void time_test_odp_negative_diff(void)
-{
-	odp_time_t diff, t1, t2;
+	ns1 = odp_time_to_ns(t1);
+	ns2 = odp_time_to_ns(t2);
+	ns = ns2 - ns1;
+	nsdiff = odp_time_to_ns(diff);
 
-	t1 = odp_time_local_from_ns(10);
-	t2 = odp_time_local_from_ns(5);
+	upper_limit = ns + TOLERANCE;
+	lower_limit = ns - TOLERANCE;
+	CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit));
+
+	/* test timestamp and interval diff */
+	ns1 = 54;
+	t1 = odp_time_local_from_ns(ns1);
+	ns = ns2 - ns1;
+
+	diff = odp_time_diff(t2, t1);
+	CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0);
+	nsdiff = odp_time_to_ns(diff);
+
+	upper_limit = ns + TOLERANCE;
+	lower_limit = ns - TOLERANCE;
+	CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit));
+
+	/* test interval diff */
+	ns2 = 60 * 10 * ODP_TIME_SEC_IN_NS;
+	ns = ns2 - ns1;
+
+	t2 = odp_time_local_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);
+
+	upper_limit = ns + TOLERANCE;
+	lower_limit = ns - TOLERANCE;
+	CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit));
+
+	/* same time has to diff to 0 */
+	diff = odp_time_diff(t2, t2);
+	CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) == 0);
+
+	diff = odp_time_diff(t2, ODP_TIME_NULL);
+	CU_ASSERT(odp_time_cmp(t2, diff) == 0);
 }
 
-/* check that related conversions come back to the same value */
-void time_test_odp_conversion(void)
+/* check that a time sum gives a reasonable result */
+void time_test_odp_sum(void)
 {
-	uint64_t ns1, ns2;
-	odp_time_t time;
+	odp_time_t sum, t1, t2;
+	uint64_t nssum, ns1, ns2, ns;
 	uint64_t upper_limit, lower_limit;
 
-	ns1 = 100;
-	time = odp_time_local_from_ns(ns1);
-	CU_ASSERT(odp_time_cmp(time, ODP_TIME_NULL) > 0);
+	/* sum timestamp and interval */
+	t1 = odp_time_local();
+	ns2 = 103;
+	t2 = odp_time_local_from_ns(ns2);
+	ns1 = odp_time_to_ns(t1);
+	ns = ns1 + ns2;
 
-	ns2 = odp_time_to_ns(time);
+	sum = odp_time_sum(t2, t1);
+	CU_ASSERT(odp_time_cmp(sum, ODP_TIME_NULL) > 0);
+	nssum = odp_time_to_ns(sum);
 
-	/* need to check within arithmetic tolerance that the same
-	 * value in ns is returned after conversions */
-	upper_limit = ns1 + TOLERANCE;
-	lower_limit = ns1 - TOLERANCE;
-	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));
+	upper_limit = ns + TOLERANCE;
+	lower_limit = ns - TOLERANCE;
+	CU_ASSERT((nssum <= upper_limit) && (nssum >= lower_limit));
+
+	/* sum intervals */
+	ns1 = 60 * 13 * ODP_TIME_SEC_IN_NS;
+	t1 = odp_time_local_from_ns(ns1);
+	ns = ns1 + ns2;
+
+	sum = odp_time_sum(t2, t1);
+	CU_ASSERT(odp_time_cmp(sum, ODP_TIME_NULL) > 0);
+	nssum = odp_time_to_ns(sum);
+
+	upper_limit = ns + TOLERANCE;
+	lower_limit = ns - TOLERANCE;
+	CU_ASSERT((nssum <= upper_limit) && (nssum >= lower_limit));
+
+	/* test on 0 */
+	sum = odp_time_sum(t2, ODP_TIME_NULL);
+	CU_ASSERT(odp_time_cmp(t2, sum) == 0);
+}
+
+void time_test_odp_to_u64(void)
+{
+	volatile int count = 0;
+	uint64_t val1, val2;
+	odp_time_t t1, t2;
+
+	t1 = odp_time_local();
+
+	val1 = odp_time_to_u64(t1);
+	CU_ASSERT(val1 > 0);
+
+	while (count < BUSY_LOOP_CNT) {
+		count++;
+	};
+
+	t2 = odp_time_local();
+	val2 = odp_time_to_u64(t2);
+	CU_ASSERT(val2 > 0);
+
+	CU_ASSERT(val2 > val1);
+
+	val1 = odp_time_to_u64(ODP_TIME_NULL);
+	CU_ASSERT(val1 == 0);
 }
 
 odp_testinfo_t time_suite_time[] = {
-	ODP_TEST_INFO(time_test_odp_diff),
-	ODP_TEST_INFO(time_test_odp_negative_diff),
 	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_odp_to_u64),
 	ODP_TEST_INFO_NULL
 };
 
diff --git a/test/validation/time/time.h b/test/validation/time/time.h
index b4e613c..b0c67b7 100644
--- a/test/validation/time/time.h
+++ b/test/validation/time/time.h
@@ -10,9 +10,12 @@ 
 #include <odp_cunit_common.h>
 
 /* test functions: */
-void time_test_odp_diff(void);
 void time_test_odp_conversion(void);
-void time_test_odp_negative_diff(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_odp_to_u64(void);
 
 /* test arrays: */
 extern odp_testinfo_t time_suite_time[];