On 15.01.16 13:54, Savolainen, Petri (Nokia - FI/Espoo) wrote:


-----Original Message-----
From: lng-odp [mailto:lng-odp-boun...@lists.linaro.org] On Behalf Of EXT
Ivan Khoronzhuk
Sent: Friday, January 15, 2016 11:16 AM
To: lng-odp@lists.linaro.org
Subject: [lng-odp] [PATCH v2] validation: system: add validation tests for
odp_cpu_cycles_* calls

https://bugs.linaro.org/show_bug.cgi?id=1906

Signed-off-by: Ivan Khoronzhuk <ivan.khoronz...@linaro.org>
---
  test/validation/system/system.c | 118
++++++++++++++++++++++++++++++++++++++++
  test/validation/system/system.h |   4 ++
  2 files changed, 122 insertions(+)

diff --git a/test/validation/system/system.c
b/test/validation/system/system.c
index 7dc2cc0..4a382ac 100644
--- a/test/validation/system/system.c
+++ b/test/validation/system/system.c
@@ -10,6 +10,8 @@
  #include "test_debug.h"
  #include "system.h"

+#define TRY_NUM                        80
+
  void system_test_odp_version_numbers(void)
  {
        int char_ok = 0;
@@ -40,6 +42,118 @@ void system_test_odp_cpu_count(void)
        CU_ASSERT(0 < cpus);
  }

+void system_test_odp_cpu_cycles(void)
+{
+       uint64_t c2, c1;
+
+       c1 = odp_cpu_cycles();
+       odp_time_wait_ns(100);
+       c2 = odp_cpu_cycles();
+
+       CU_ASSERT(c2 != c1);
+}
+
+void system_test_odp_cpu_cycles_max(void)
+{
+       uint64_t c2, c1;
+       uint64_t max1, max2;
+
+       max1 = odp_cpu_cycles_max();
+       odp_time_wait_ns(100);
+       max2 = odp_cpu_cycles_max();
+
+       CU_ASSERT(max1 >= UINT32_MAX / 2);
+       CU_ASSERT(max1 == max2);
+
+       c1 = odp_cpu_cycles();
+       odp_time_wait_ns(1000);
+       c2 = odp_cpu_cycles();
+
+       CU_ASSERT(c1 < max1 && c2 < max1);

c <= max

c can be also max. It's the maximum (valid) value before it wraps back to zero.
Yep.




+}
+
+void system_test_odp_cpu_cycles_diff(void)
+{
+       int i;
+       uint64_t c2, c1;
+       uint64_t etalon, diff;

Etalon is not a common pick for a variable name. I think 'tmp' should be OK for 
this purpose.
Ok.



+
+       c2 = 100;
+       c1 = 39;
+
+       diff = odp_cpu_cycles_diff(c2, c2);
+       CU_ASSERT(diff == 0);
+
+       etalon = c2 - c1;
+       diff = odp_cpu_cycles_diff(c2, c1);
+       CU_ASSERT(diff == etalon);
+
+       etalon = c1 + (odp_cpu_cycles_max() - c2) + 1;
+       diff = odp_cpu_cycles_diff(c1, c2);
+       CU_ASSERT(diff == etalon);
+
+       c1 = odp_cpu_cycles();
+       if (!(odp_cpu_cycles_max() <= UINT32_MAX ||
+             (odp_cpu_cycles_max() - c1) <= UINT32_MAX))
+               return;

A debug message should be logged for this check. Either assert or warn that 
rest of the test cases will be skipped.
Ok.


+
+       /* must handle one wrap */
+       for (i = 0; i < TRY_NUM; i++) {
+               c1 = odp_cpu_cycles();
+               odp_time_wait_ns(100 * ODP_TIME_MSEC_IN_NS + i);
+               c2 = odp_cpu_cycles();
+
+               CU_ASSERT(c2 != c1);
+
+               if (c2 > c1)
+                       etalon = c2 - c1;
+               else
+                       etalon = c2 + (odp_cpu_cycles_max() - c1) + 1;
+
+               diff = odp_cpu_cycles_diff(c2, c1);
+               CU_ASSERT(diff == etalon);
+
+               /* wrap is detected and verified */
+               if (c2 < c1)
+                       break;
+       }
+
+       /* wrap has to be detected */
+       CU_ASSERT(i < TRY_NUM);
+}
+
+void system_test_odp_cpu_cycles_resolution(void)
+{
+       int i;
+       uint64_t rest;
+       uint64_t c2, c1;
+       uint64_t res, diff;
+
+       res = odp_cpu_cycles_resolution();
+       CU_ASSERT(res != 0);
+
+       /*
+        * must be a multiple of resolution in
+        * whole interval till wrap, in another

Max: 90
Res: 10

c2   max  c1   res
0 + (90 - 90) + 10  = 10

Resolution should hold also during a wrap. The cycles_diff implementation needs an 
update if resolution is >1.

The test under may or may not wrap (depends on timing).

-Petri

Ok. Will set

c1 = MAX - 2*res. c2 = odp_cpu_cycles();
diff = odp_cpu_cycles_diff(c2, c1);
rest = diff % res;
CU_ASSERT(rest == 0);

And also increase TRY NUM as in test for diff.


+        * case resolution is set incorrectly
+        */
+       for (i = 0; i < 10; i++) {
+               c1 = odp_cpu_cycles();
+               odp_time_wait_ns(100 * ODP_TIME_MSEC_IN_NS + i);
+               c2 = odp_cpu_cycles();
+
+               diff = odp_cpu_cycles_diff(c2, c1);
+               rest = diff % res;
+               CU_ASSERT(rest == 0);
+
+               rest = c1 % res;
+               CU_ASSERT(rest == 0);
+
+               rest = c2 % res;
+               CU_ASSERT(rest == 0);
+       }
+}
+
  void system_test_odp_sys_cache_line_size(void)
  {
        uint64_t cache_size;
@@ -91,6 +205,10 @@ odp_testinfo_t system_suite[] = {
        ODP_TEST_INFO(system_test_odp_sys_page_size),
        ODP_TEST_INFO(system_test_odp_sys_huge_page_size),
        ODP_TEST_INFO(system_test_odp_sys_cpu_hz),
+       ODP_TEST_INFO(system_test_odp_cpu_cycles),
+       ODP_TEST_INFO(system_test_odp_cpu_cycles_max),
+       ODP_TEST_INFO(system_test_odp_cpu_cycles_diff),
+       ODP_TEST_INFO(system_test_odp_cpu_cycles_resolution),
        ODP_TEST_INFO_NULL,
  };

diff --git a/test/validation/system/system.h
b/test/validation/system/system.h
index 869aaff..0c263f2 100644
--- a/test/validation/system/system.h
+++ b/test/validation/system/system.h
@@ -17,6 +17,10 @@ void system_test_odp_sys_cpu_model_str(void);
  void system_test_odp_sys_page_size(void);
  void system_test_odp_sys_huge_page_size(void);
  void system_test_odp_sys_cpu_hz(void);
+void system_test_odp_cpu_cycles_max(void);
+void system_test_odp_cpu_cycles(void);
+void system_test_odp_cpu_cycles_diff(void);
+void system_test_odp_cpu_cycles_resolution(void);

  /* test arrays: */
  extern odp_testinfo_t system_suite[];
--
1.9.1

_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

--
Regards,
Ivan Khoronzhuk
_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to