diff mbox

validation: add odp_time test

Message ID 1418665159-37208-1-git-send-email-mike.holmes@linaro.org
State Accepted
Commit 4d94d670b9618ad212316d94566dacabcbd586e7
Headers show

Commit Message

Mike Holmes Dec. 15, 2014, 5:39 p.m. UTC
Add odp_time_x API tests

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 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

Comments

Ola Liljedahl Dec. 15, 2014, 6:27 p.m. UTC | #1
On 15 December 2014 at 18:39, Mike Holmes <mike.holmes@linaro.org> wrote:
> Add odp_time_x API tests
>
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> ---
>  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
Speling?

> +
> +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);
How can assert that t1 is already greater than 0?

> +
> +       t2 = odp_time_cycles();
> +       CU_ASSERT(t2 > 0);
> +
> +       diff = odp_time_diff_cycles(t1, t2);
> +       CU_ASSERT(diff > 0);
Two calls to odp_time_cycles() this close cannot be guaranteed to
return different values.
> +
> +       t1 = 100;
> +       cycles = odp_time_ns_to_cycles(t1);
> +       CU_ASSERT(cycles > 0);
There's an implicit requirement of resolution here. Does this
requirement exist in the (API) spec?
What if the target only has e.g. a 1MHz cycle counter? Then 1 cycle is 1000ns.

> +
> +       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));
For this kind of test, I would probably check a cycle -> ns -> cycle
conversion instead. This should work as long as 1 cycle >= 1 ns.
Maybe we need to kinds of tests, one when cycle frequency >= 1GHz
(cycle resolution is <= 1ns) and another when cycle frequency <= 1GHz
(cycle resolution >= 1ns).

> +}
> +
> +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
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

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
+};