Add odp_time_x API tests

Signed-off-by: Mike Holmes <[email protected]>
---
 test/validation/.gitignore  |  1 +
 test/validation/Makefile.am |  4 +++-
 test/validation/odp_time.c  | 50 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 test/validation/odp_time.c

diff --git a/test/validation/.gitignore b/test/validation/.gitignore
index 32834ae..3c81566 100644
--- a/test/validation/.gitignore
+++ b/test/validation/.gitignore
@@ -5,3 +5,4 @@ odp_queue
 odp_crypto
 odp_schedule
 odp_shm
+odp_time
diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am
index d0b5426..8e78865 100644
--- a/test/validation/Makefile.am
+++ b/test/validation/Makefile.am
@@ -6,7 +6,7 @@ AM_LDFLAGS += -static
 if ODP_CUNIT_ENABLED
 TESTS = ${bin_PROGRAMS}
 check_PROGRAMS = ${bin_PROGRAMS}
-bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule
+bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_time
 odp_init_LDFLAGS = $(AM_LDFLAGS)
 odp_queue_LDFLAGS = $(AM_LDFLAGS)
 odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto
@@ -15,6 +15,7 @@ odp_shm_CFLAGS = $(AM_CFLAGS)
 odp_shm_LDFLAGS = $(AM_LDFLAGS)
 odp_schedule_CFLAGS = $(AM_CFLAGS)
 odp_schedule_LDFLAGS = $(AM_LDFLAGS)
+odp_time_LDFLAGS = $(AM_LDFLAGS)
 endif
 
 dist_odp_init_SOURCES = odp_init.c
@@ -25,6 +26,7 @@ dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \
                          odp_crypto.c common/odp_cunit_common.c
 dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.c
 dist_odp_schedule_SOURCES = odp_schedule.c common/odp_cunit_common.c
+dist_odp_time_SOURCES = odp_time.c common/odp_cunit_common.c
 
 #For Linux generic the unimplemented crypto API functions break the
 #regression TODO: https://bugs.linaro.org/show_bug.cgi?id=975
diff --git a/test/validation/odp_time.c b/test/validation/odp_time.c
new file mode 100644
index 0000000..dfb304f
--- /dev/null
+++ b/test/validation/odp_time.c
@@ -0,0 +1,50 @@
+/* Copyright (c) 2014, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include <odp.h>
+#include "odp_cunit_common.h"
+
+#define TOLLERANCE 1
+
+static void test_odp_time_basic(void)
+{
+       uint64_t t1, t2, diff, cycles;
+       uint64_t upper_limit, lower_limit;
+
+       t1 = odp_time_cycles();
+       CU_ASSERT(t1 > 0);
+
+       t2 = odp_time_cycles();
+       CU_ASSERT(t2 > 0);
+
+       diff = odp_time_diff_cycles(t1, t2);
+       CU_ASSERT(diff > 0);
+
+       t1 = 100;
+       cycles = odp_time_ns_to_cycles(t1);
+       CU_ASSERT(cycles > 0);
+
+       t2 = odp_time_cycles_to_ns(cycles);
+
+       /* need to check within arithmetic tolerance */
+       upper_limit = t1 + TOLLERANCE;
+       lower_limit = t1 - TOLLERANCE;
+       printf("\nTolerance %" PRId64 " upper %" PRId64 " lower\n",
+              upper_limit, lower_limit);
+       printf("%" PRId64 " ns -> %" PRId64 " cycles -> %" PRId64 " ns\n",
+              t1, cycles, t2);
+       CU_ASSERT((t2 <= upper_limit) && (t2 >= lower_limit));
+}
+
+CU_TestInfo test_odp_time[] = {
+       {"odp_time",  test_odp_time_basic},
+        CU_TEST_INFO_NULL
+};
+
+CU_SuiteInfo odp_testsuites[] = {
+               {"Time", NULL, NULL, NULL, NULL, test_odp_time},
+                CU_SUITE_INFO_NULL
+};
-- 
2.1.0


_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to