Add odp_time_x API tests Signed-off-by: Mike Holmes <mike.hol...@linaro.org> --- v2: fix bad auto merge of Makefile.am clean up names
test/validation/.gitignore | 1 + test/validation/Makefile.am | 5 ++-- test/validation/odp_time.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 test/validation/odp_time.c diff --git a/test/validation/.gitignore b/test/validation/.gitignore index d08db73..40ea12d 100644 --- a/test/validation/.gitignore +++ b/test/validation/.gitignore @@ -8,3 +8,4 @@ odp_shm odp_system odp_pktio odp_buffer +odp_time diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index c0545b7..692e1a6 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,9 +6,9 @@ AM_LDFLAGS += -static TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} if ODP_CUNIT_ENABLED -TESTS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio_run odp_buffer odp_system +TESTS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio_run odp_buffer odp_system odp_time check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio odp_buffer odp_system +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio odp_buffer odp_system odp_time odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer endif @@ -27,3 +27,4 @@ dist_odp_buffer_SOURCES = buffer/odp_buffer_pool_test.c \ buffer/odp_packet_test.c \ odp_buffer.c common/odp_cunit_common.c dist_odp_system_SOURCES = odp_system.c common/odp_cunit_common.c +dist_odp_time_SOURCES = odp_time.c common/odp_cunit_common.c diff --git a/test/validation/odp_time.c b/test/validation/odp_time.c new file mode 100644 index 0000000..75be1f0 --- /dev/null +++ b/test/validation/odp_time.c @@ -0,0 +1,71 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp.h> +#include "odp_cunit_common.h" + +#define TOLERANCE 1 +#define BUSY_LOOP_CNT 100 + +/* check that a cycles difference gives a reasonable result */ +static void test_odp_cycles_diff(void) +{ + /* volatile to stop optimization of busy loop */ + volatile int count; + uint64_t diff, cycles1, cycles2; + + cycles1 = odp_time_cycles(); + + while (count < BUSY_LOOP_CNT) { + count++; + }; + + cycles2 = odp_time_cycles(); + CU_ASSERT(cycles2 > cycles1); + + diff = odp_time_diff_cycles(cycles1, cycles2); + CU_ASSERT(diff > 0); +} + +/* check that a negative cycles difference gives a reasonable result */ +static void test_odp_cycles_negative_diff(void) +{ + uint64_t diff, cycles1, cycles2; + cycles1 = 10; + cycles2 = 5; + diff = odp_time_diff_cycles(cycles1, cycles2); + CU_ASSERT(diff > 0); +} + +/* check that related conversions come back to the same value */ +static void test_odp_time_conversion(void) +{ + uint64_t ns1, ns2, cycles; + uint64_t upper_limit, lower_limit; + ns1 = 100; + cycles = odp_time_ns_to_cycles(ns1); + CU_ASSERT(cycles > 0); + + ns2 = odp_time_cycles_to_ns(cycles); + + /* 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)); +} + +CU_TestInfo test_odp_time[] = { + {"cycles diff", test_odp_cycles_diff}, + {"negative diff", test_odp_cycles_negative_diff}, + {"conversion", test_odp_time_conversion}, + 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