diff options
author | Zoltan Kiss <zoltan.kiss@linaro.org> | 2015-07-28 14:14:35 +0100 |
---|---|---|
committer | Zoltan Kiss <zoltan.kiss@linaro.org> | 2015-07-28 14:14:35 +0100 |
commit | c1edf60d492c08430af8d2c42a1600e54d4028b7 (patch) | |
tree | 87455045c3434c1affe07b75e02c964239aaa029 /test/validation | |
parent | 213d8044006e93b859a28a788325c38686912b65 (diff) | |
parent | 89dc8af475d8cbdadb0efac6a1396d74a525dc30 (diff) |
Merge git://git.linaro.org/lng/odp
Sync up with latest ODP mainline
Diffstat (limited to 'test/validation')
116 files changed, 2405 insertions, 1800 deletions
diff --git a/test/validation/.gitignore b/test/validation/.gitignore index 34ea143f1..7e563b8b3 100644 --- a/test/validation/.gitignore +++ b/test/validation/.gitignore @@ -1,21 +1,2 @@ *.log *.trs -odp_ver_abt_log_dbg -odp_buffer -odp_classification -odp_cpumask -odp_crypto -odp_init -odp_init_abort -odp_init_log -odp_packet -odp_pktio -odp_pool -odp_queue -odp_random -odp_scheduler -odp_shared_memory -odp_synchronizers -odp_time -odp_timer -odp_thread diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 2585eac70..5d8e93b28 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -1,68 +1,20 @@ -include $(top_srcdir)/test/Makefile.inc - -AM_CFLAGS += -I$(srcdir)/common -AM_LDFLAGS += -static - -TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} TEST_DIR=${builddir} - -EXECUTABLES = odp_buffer \ -## odp_classification \ - odp_cpumask \ - odp_crypto \ - odp_init \ - odp_init_abort \ - odp_init_log \ - odp_packet \ - odp_pool \ - odp_queue \ - odp_random \ - odp_scheduler \ - odp_shared_memory \ - odp_synchronizers \ - odp_time \ - odp_timer \ - odp_thread \ - odp_ver_abt_log_dbg - -COMPILE_ONLY = odp_pktio - -TESTSCRIPTS = odp_pktio_run - -if test_vald -TESTS = $(EXECUTABLES) $(TESTSCRIPTS) -endif - -dist_bin_SCRIPTS = odp_pktio_run - -bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) - -ODP_CU_COMMON=common/odp_cunit_common.c - -odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer -dist_odp_buffer_SOURCES = odp_buffer.c $(ODP_CU_COMMON) -odp_classification_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/classification -dist_odp_classification_SOURCES = classification/odp_classification_tests.c \ - classification/odp_classification_basic.c \ - odp_classification.c $(ODP_CU_COMMON) -odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto -dist_odp_crypto_SOURCES = crypto/odp_crypto_test_inp.c \ - odp_crypto.c $(ODP_CU_COMMON) -dist_odp_init_SOURCES = init/odp_init.c $(ODP_CU_COMMON) -dist_odp_init_abort_SOURCES = init/odp_init_abort.c $(ODP_CU_COMMON) -dist_odp_init_log_SOURCES = init/odp_init_log.c $(ODP_CU_COMMON) -dist_odp_queue_SOURCES = odp_queue.c $(ODP_CU_COMMON) -dist_odp_random_SOURCES = odp_random.c $(ODP_CU_COMMON) -dist_odp_scheduler_SOURCES = odp_scheduler.c $(ODP_CU_COMMON) -dist_odp_shared_memory_SOURCES = odp_shared_memory.c $(ODP_CU_COMMON) -dist_odp_synchronizers_SOURCES = odp_synchronizers.c $(ODP_CU_COMMON) -dist_odp_time_SOURCES = odp_time.c $(ODP_CU_COMMON) -dist_odp_timer_SOURCES = odp_timer.c $(ODP_CU_COMMON) -dist_odp_pktio_SOURCES = odp_pktio.c $(ODP_CU_COMMON) -dist_odp_packet_SOURCES = odp_packet.c $(ODP_CU_COMMON) -dist_odp_pool_SOURCES = odp_pool.c $(ODP_CU_COMMON) -dist_odp_cpumask_SOURCES = odp_cpumask.c $(ODP_CU_COMMON) -dist_odp_thread_SOURCES = odp_thread.c $(ODP_CU_COMMON) -odp_ver_abt_log_dbg_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/ver_abt_log_dbg -dist_odp_ver_abt_log_dbg_SOURCES = ver_abt_log_dbg/odp_system.c \ - ver_abt_log_dbg/odp_errno.c \ - ver_abt_log_dbg/odp_ver_abt_log_dbg.c $(ODP_CU_COMMON) +ODP_MODULES = buffer \ +## classification \ + cpumask \ + crypto \ + errno \ + init \ + queue \ + packet \ + pktio \ + pool \ + random \ + scheduler \ + synchronizers \ + thread \ + time \ + timer \ + shmem \ + system + +SUBDIRS = common $(ODP_MODULES) diff --git a/test/validation/Makefile.inc b/test/validation/Makefile.inc new file mode 100644 index 000000000..ac8081404 --- /dev/null +++ b/test/validation/Makefile.inc @@ -0,0 +1,11 @@ +include $(top_srcdir)/test/Makefile.inc + +COMMON_DIR = $(top_builddir)/test/validation/common + +AM_CFLAGS += -I$(top_srcdir)/test/validation/common +AM_LDFLAGS += -static + +LIBCUNIT_COMMON = $(COMMON_DIR)/libcunit_common.la +LIBCPUMASK_COMMON = $(COMMON_DIR)/libcpumask_common.la +LIBTHRMASK_COMMON = $(COMMON_DIR)/libthrmask_common.la +LIBODP = $(LIB)/libodphelper.la $(LIB)/libodp.la diff --git a/test/validation/buffer/.gitignore b/test/validation/buffer/.gitignore new file mode 100644 index 000000000..0e8ac15c1 --- /dev/null +++ b/test/validation/buffer/.gitignore @@ -0,0 +1 @@ +buffer_main diff --git a/test/validation/buffer/Makefile.am b/test/validation/buffer/Makefile.am new file mode 100644 index 000000000..e1b1233cd --- /dev/null +++ b/test/validation/buffer/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libbuffer.la +libbuffer_la_SOURCES = buffer.c + +bin_PROGRAMS = buffer_main$(EXEEXT) +dist_buffer_main_SOURCES = buffer_main.c +buffer_main_LDADD = libbuffer.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_buffer.c b/test/validation/buffer/buffer.c index f2c0c9b5a..f67c55fc0 100644 --- a/test/validation/odp_buffer.c +++ b/test/validation/buffer/buffer.c @@ -6,6 +6,7 @@ #include <odp.h> #include "odp_cunit_common.h" +#include "buffer.h" /* Helper macro for CU_TestInfo initialization */ #define _CU_TEST_INFO(test_func) {#test_func, test_func} @@ -14,7 +15,7 @@ static odp_pool_t raw_pool; static odp_buffer_t raw_buffer = ODP_BUFFER_INVALID; static const size_t raw_buffer_size = 1500; -static int buffer_testsuite_init(void) +static int buffer_suite_init(void) { odp_pool_param_t params = { .buf = { @@ -25,7 +26,7 @@ static int buffer_testsuite_init(void) .type = ODP_POOL_BUFFER, }; - raw_pool = odp_pool_create("raw_pool", ODP_SHM_INVALID, ¶ms); + raw_pool = odp_pool_create("raw_pool", ¶ms); if (raw_pool == ODP_POOL_INVALID) return -1; raw_buffer = odp_buffer_alloc(raw_pool); @@ -34,7 +35,7 @@ static int buffer_testsuite_init(void) return 0; } -static int buffer_testsuite_finalize(void) +static int buffer_suite_term(void) { odp_buffer_free(raw_buffer); if (odp_pool_destroy(raw_pool) != 0) @@ -42,7 +43,7 @@ static int buffer_testsuite_finalize(void) return 0; } -static void buffer_pool_alloc(void) +static void buffer_test_pool_alloc(void) { odp_pool_t pool; const int num = 3; @@ -60,7 +61,7 @@ static void buffer_pool_alloc(void) .type = ODP_POOL_BUFFER, }; - pool = odp_pool_create("buffer_pool_alloc", ODP_SHM_INVALID, ¶ms); + pool = odp_pool_create("buffer_pool_alloc", ¶ms); odp_pool_print(pool); /* Try to allocate num items from the pool */ @@ -94,7 +95,7 @@ static void buffer_pool_alloc(void) CU_ASSERT(odp_pool_destroy(pool) == 0); } -static void buffer_pool_free(void) +static void buffer_test_pool_free(void) { odp_pool_t pool; odp_buffer_t buffer; @@ -107,7 +108,7 @@ static void buffer_pool_free(void) .type = ODP_POOL_BUFFER, }; - pool = odp_pool_create("buffer_pool_free", ODP_SHM_INVALID, ¶ms); + pool = odp_pool_create("buffer_pool_free", ¶ms); /* Allocate the only buffer from the pool */ buffer = odp_buffer_alloc(pool); @@ -126,7 +127,7 @@ static void buffer_pool_free(void) CU_ASSERT(odp_pool_destroy(pool) == 0); } -static void buffer_management_basic(void) +static void buffer_test_management_basic(void) { odp_event_t ev = odp_buffer_to_event(raw_buffer); @@ -141,18 +142,23 @@ static void buffer_management_basic(void) CU_ASSERT(odp_event_to_u64(ev) != odp_event_to_u64(ODP_EVENT_INVALID)); } -static CU_TestInfo buffer_tests[] = { - _CU_TEST_INFO(buffer_pool_alloc), - _CU_TEST_INFO(buffer_pool_free), - _CU_TEST_INFO(buffer_management_basic), +static CU_TestInfo buffer_suite[] = { + _CU_TEST_INFO(buffer_test_pool_alloc), + _CU_TEST_INFO(buffer_test_pool_free), + _CU_TEST_INFO(buffer_test_management_basic), CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { +static CU_SuiteInfo buffer_suites[] = { { .pName = "buffer tests", - .pTests = buffer_tests, - .pInitFunc = buffer_testsuite_init, - .pCleanupFunc = buffer_testsuite_finalize, + .pTests = buffer_suite, + .pInitFunc = buffer_suite_init, + .pCleanupFunc = buffer_suite_term, }, CU_SUITE_INFO_NULL, }; + +int buffer_main(void) +{ + return odp_cunit_run(buffer_suites); +} diff --git a/test/validation/buffer/buffer.h b/test/validation/buffer/buffer.h new file mode 100644 index 000000000..6269c63de --- /dev/null +++ b/test/validation/buffer/buffer.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_BUFFER_H_ +#define _ODP_TEST_BUFFER_H_ + +int buffer_main(void); + +#endif diff --git a/test/validation/buffer/buffer_main.c b/test/validation/buffer/buffer_main.c new file mode 100644 index 000000000..b9b514647 --- /dev/null +++ b/test/validation/buffer/buffer_main.c @@ -0,0 +1,11 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "buffer.h" + +int main(void) +{ + return buffer_main(); +} diff --git a/test/validation/buffer/odp_buffer_pool_test.c b/test/validation/buffer/odp_buffer_pool_test.c deleted file mode 100644 index ebeae7521..000000000 --- a/test/validation/buffer/odp_buffer_pool_test.c +++ /dev/null @@ -1,269 +0,0 @@ -/* Copyright (c) 2014, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "odp_buffer_tests.h" - -static int pool_name_number = 1; -static const int default_buffer_size = 1500; -static const int default_buffer_num = 1000; - -odp_pool_t pool_create(int num, int size, int type) -{ - odp_pool_t pool; - char pool_name[ODP_POOL_NAME_LEN]; - odp_pool_param_t param; - - memset(¶m, 0, sizeof(param)); - - switch (type) { - case ODP_POOL_BUFFER: - param.buf.size = size; - param.buf.align = ODP_CACHE_LINE_SIZE; - param.buf.num = num; - break; - case ODP_POOL_PACKET: - param.pkt.seg_len = size; - param.pkt.len = size; - param.pkt.num = num; - break; - case ODP_POOL_TIMEOUT: - param.tmo.num = num; - break; - default: - CU_FAIL("Bad pool type"); - return ODP_POOL_INVALID; - } - - param.type = type; - - snprintf(pool_name, sizeof(pool_name), - "test_buffer_pool-%d", pool_name_number++); - - pool = odp_pool_create(pool_name, ODP_SHM_INVALID, ¶m); - CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); - - return pool; -} - -static void pool_create_destroy_type(int type) -{ - odp_pool_t pool; - pool = pool_create(default_buffer_num, default_buffer_size, type); - - CU_ASSERT(odp_pool_destroy(pool) == 0); -} - -static void pool_create_destroy_raw(void) -{ - pool_create_destroy_type(ODP_POOL_BUFFER); -} - -static void pool_create_destroy_packet(void) -{ - pool_create_destroy_type(ODP_POOL_PACKET); -} - -static void pool_create_destroy_timeout(void) -{ - pool_create_destroy_type(ODP_POOL_TIMEOUT); -} - -static void pool_create_destroy_raw_shm(void) -{ - odp_pool_t pool; - odp_shm_t test_shm; - odp_pool_param_t params = { - .buf = { - .size = 1500, - .align = ODP_CACHE_LINE_SIZE, - .num = 10, - }, - .type = ODP_POOL_BUFFER, - }; - - test_shm = odp_shm_reserve("test_shm", - params.buf.size * params.buf.num * 2, - ODP_CACHE_LINE_SIZE, - 0); - CU_ASSERT_FATAL(test_shm != ODP_SHM_INVALID); - - pool = odp_pool_create("test_shm_pool", test_shm, ¶ms); - CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); - - CU_ASSERT(odp_pool_destroy(pool) == 0); - CU_ASSERT(odp_shm_free(test_shm) == 0); -} - -static void pool_lookup_info_print(void) -{ - odp_pool_t pool; - const char pool_name[] = "pool_for_lookup_test"; - odp_pool_info_t info; - odp_pool_param_t params = { - .buf = { - .size = default_buffer_size, - .align = ODP_CACHE_LINE_SIZE, - .num = default_buffer_num, - }, - .type = ODP_POOL_BUFFER, - }; - - pool = odp_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); - CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); - - pool = odp_pool_lookup(pool_name); - CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); - - CU_ASSERT_FATAL(odp_pool_info(pool, &info) == 0); - CU_ASSERT(strncmp(pool_name, info.name, sizeof(pool_name)) == 0); - CU_ASSERT(info.shm == ODP_SHM_INVALID); - CU_ASSERT(params.buf.size <= info.params.buf.size); - CU_ASSERT(params.buf.align <= info.params.buf.align); - CU_ASSERT(params.buf.num <= info.params.buf.num); - CU_ASSERT(params.type == info.params.type); - - odp_pool_print(pool); - - CU_ASSERT(odp_pool_destroy(pool) == 0); -} - -static void pool_alloc_type(int type) -{ - odp_pool_t pool; - const int num = 3; - const size_t size = 1500; - odp_buffer_t buffer[num]; - odp_packet_t packet[num]; - odp_timeout_t tmo[num]; - odp_event_t ev; - int index; - char wrong_type = 0, wrong_size = 0; - - pool = pool_create(num, size, type); - odp_pool_print(pool); - - /* Try to allocate num items from the pool */ - for (index = 0; index < num; index++) { - switch (type) { - case ODP_POOL_BUFFER: - buffer[index] = odp_buffer_alloc(pool); - - if (buffer[index] == ODP_BUFFER_INVALID) - break; - - ev = odp_buffer_to_event(buffer[index]); - if (odp_event_type(ev) != ODP_EVENT_BUFFER) - wrong_type = 1; - if (odp_buffer_size(buffer[index]) < size) - wrong_size = 1; - if (wrong_type || wrong_size) - odp_buffer_print(buffer[index]); - break; - case ODP_POOL_PACKET: - packet[index] = odp_packet_alloc(pool, size); - - if (packet[index] == ODP_PACKET_INVALID) - break; - - ev = odp_packet_to_event(packet[index]); - if (odp_event_type(ev) != ODP_EVENT_PACKET) - wrong_type = 1; - break; - case ODP_POOL_TIMEOUT: - tmo[index] = odp_timeout_alloc(pool); - - if (tmo[index] == ODP_TIMEOUT_INVALID) - break; - - ev = odp_timeout_to_event(tmo[index]); - if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) - wrong_type = 1; - break; - default: - break; - } - - } - - /* Check that the pool had at least num items */ - CU_ASSERT(index == num); - /* index points out of buffer[] or it point to an invalid buffer */ - index--; - - /* Check that the pool had correct buffers */ - CU_ASSERT(wrong_type == 0); - CU_ASSERT(wrong_size == 0); - - switch (type) { - case ODP_POOL_BUFFER: - for (; index >= 0; index--) - odp_buffer_free(buffer[index]); - break; - case ODP_POOL_PACKET: - for (; index >= 0; index--) - odp_packet_free(packet[index]); - break; - case ODP_POOL_TIMEOUT: - for (; index >= 0; index--) - odp_timeout_free(tmo[index]); - break; - default: - break; - } - - CU_ASSERT(odp_pool_destroy(pool) == 0); -} - -static void pool_alloc_buffer_raw(void) -{ - pool_alloc_type(ODP_POOL_BUFFER); -} - -static void pool_alloc_buffer_packet(void) -{ - pool_alloc_type(ODP_POOL_PACKET); -} - -static void pool_alloc_buffer_timeout(void) -{ - pool_alloc_type(ODP_POOL_TIMEOUT); -} - -static void pool_free_buffer(void) -{ - odp_pool_t pool; - odp_buffer_t buffer; - pool = pool_create(1, 64, ODP_POOL_BUFFER); - - /* Allocate the only buffer from the pool */ - buffer = odp_buffer_alloc(pool); - CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); - - /** @todo: is it correct to assume the pool had only one buffer? */ - CU_ASSERT_FATAL(odp_buffer_alloc(pool) == ODP_BUFFER_INVALID) - - odp_buffer_free(buffer); - - /* Check that the buffer was returned back to the pool */ - buffer = odp_buffer_alloc(pool); - CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); - - odp_buffer_free(buffer); - CU_ASSERT(odp_pool_destroy(pool) == 0); -} - -CU_TestInfo buffer_pool_tests[] = { - _CU_TEST_INFO(pool_create_destroy_raw), - _CU_TEST_INFO(pool_create_destroy_packet), - _CU_TEST_INFO(pool_create_destroy_timeout), - _CU_TEST_INFO(pool_create_destroy_raw_shm), - _CU_TEST_INFO(pool_lookup_info_print), - _CU_TEST_INFO(pool_alloc_buffer_raw), - _CU_TEST_INFO(pool_alloc_buffer_packet), - _CU_TEST_INFO(pool_alloc_buffer_timeout), - _CU_TEST_INFO(pool_free_buffer), - CU_TEST_INFO_NULL, -}; diff --git a/test/validation/classification/.gitignore b/test/validation/classification/.gitignore new file mode 100644 index 000000000..e2cdfefe1 --- /dev/null +++ b/test/validation/classification/.gitignore @@ -0,0 +1 @@ +classification_main diff --git a/test/validation/classification/Makefile.am b/test/validation/classification/Makefile.am new file mode 100644 index 000000000..ba468faf7 --- /dev/null +++ b/test/validation/classification/Makefile.am @@ -0,0 +1,10 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libclassification.la +libclassification_la_SOURCES = odp_classification_basic.c \ + odp_classification_tests.c \ + classification.c + +bin_PROGRAMS = classification_main$(EXEEXT) +dist_classification_main_SOURCES = classification_main.c +classification_main_LDADD = libclassification.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/classification/classification.c b/test/validation/classification/classification.c new file mode 100644 index 000000000..2582aaa0b --- /dev/null +++ b/test/validation/classification/classification.c @@ -0,0 +1,27 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp.h> +#include <odp_cunit_common.h> +#include "odp_classification_testsuites.h" +#include "classification.h" + +static CU_SuiteInfo classification_suites[] = { + { .pName = "classification basic", + .pTests = classification_suite_basic, + }, + { .pName = "classification tests", + .pTests = classification_suite, + .pInitFunc = classification_suite_init, + .pCleanupFunc = classification_suite_term, + }, + CU_SUITE_INFO_NULL, +}; + +int classification_main(void) +{ + return odp_cunit_run(classification_suites); +} diff --git a/test/validation/classification/classification.h b/test/validation/classification/classification.h new file mode 100644 index 000000000..63ad0221b --- /dev/null +++ b/test/validation/classification/classification.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_CLASSIFICATION_H_ +#define _ODP_TEST_CLASSIFICATION_H_ + +int classification_main(void); + +#endif diff --git a/test/validation/classification/classification_main.c b/test/validation/classification/classification_main.c new file mode 100644 index 000000000..712fada7f --- /dev/null +++ b/test/validation/classification/classification_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "classification.h" + +int main(void) +{ + return classification_main(); +} diff --git a/test/validation/classification/odp_classification_basic.c b/test/validation/classification/odp_classification_basic.c index b327e35be..99202eefc 100644 --- a/test/validation/classification/odp_classification_basic.c +++ b/test/validation/classification/odp_classification_basic.c @@ -8,7 +8,7 @@ #define PMR_SET_NUM 5 -static void classification_create_cos(void) +static void classification_test_create_cos(void) { odp_cos_t cos; char name[ODP_COS_NAME_LEN]; @@ -19,7 +19,7 @@ static void classification_create_cos(void) odp_cos_destroy(cos); } -static void classification_destroy_cos(void) +static void classification_test_destroy_cos(void) { odp_cos_t cos; char name[ODP_COS_NAME_LEN]; @@ -33,7 +33,7 @@ static void classification_destroy_cos(void) CU_ASSERT(retval < 0); } -static void classification_create_pmr_match(void) +static void classification_test_create_pmr_match(void) { odp_pmr_t pmr; uint16_t val; @@ -46,7 +46,7 @@ static void classification_create_pmr_match(void) odp_pmr_destroy(pmr); } -static void classification_destroy_pmr(void) +static void classification_test_destroy_pmr(void) { odp_pmr_t pmr; uint16_t val; @@ -62,7 +62,7 @@ static void classification_destroy_pmr(void) CU_ASSERT(retval < 0); } -static void classification_cos_set_queue(void) +static void classification_test_cos_set_queue(void) { int retval; char cosname[ODP_COS_NAME_LEN]; @@ -87,7 +87,7 @@ static void classification_cos_set_queue(void) odp_queue_destroy(queue_cos); } -static void classification_cos_set_drop(void) +static void classification_test_cos_set_drop(void) { int retval; char cosname[ODP_COS_NAME_LEN]; @@ -103,7 +103,7 @@ static void classification_cos_set_drop(void) odp_cos_destroy(cos_drop); } -static void classification_pmr_match_set_create(void) +static void classification_test_pmr_match_set_create(void) { odp_pmr_set_t pmr_set; int retval; @@ -127,7 +127,7 @@ static void classification_pmr_match_set_create(void) CU_ASSERT(retval == 0); } -static void classification_pmr_match_set_destroy(void) +static void classification_test_pmr_match_set_destroy(void) { odp_pmr_set_t pmr_set; int retval; @@ -153,14 +153,14 @@ static void classification_pmr_match_set_destroy(void) CU_ASSERT(retval == 0); } -CU_TestInfo classification_basic[] = { - _CU_TEST_INFO(classification_create_cos), - _CU_TEST_INFO(classification_destroy_cos), - _CU_TEST_INFO(classification_create_pmr_match), - _CU_TEST_INFO(classification_destroy_pmr), - _CU_TEST_INFO(classification_cos_set_queue), - _CU_TEST_INFO(classification_cos_set_drop), - _CU_TEST_INFO(classification_pmr_match_set_create), - _CU_TEST_INFO(classification_pmr_match_set_destroy), +CU_TestInfo classification_suite_basic[] = { + _CU_TEST_INFO(classification_test_create_cos), + _CU_TEST_INFO(classification_test_destroy_cos), + _CU_TEST_INFO(classification_test_create_pmr_match), + _CU_TEST_INFO(classification_test_destroy_pmr), + _CU_TEST_INFO(classification_test_cos_set_queue), + _CU_TEST_INFO(classification_test_cos_set_drop), + _CU_TEST_INFO(classification_test_pmr_match_set_create), + _CU_TEST_INFO(classification_test_pmr_match_set_destroy), CU_TEST_INFO_NULL, }; diff --git a/test/validation/classification/odp_classification_tests.c b/test/validation/classification/odp_classification_tests.c index 131ac91f6..a4072c4bf 100644 --- a/test/validation/classification/odp_classification_tests.c +++ b/test/validation/classification/odp_classification_tests.c @@ -109,7 +109,8 @@ void enqueue_loop_interface(odp_packet_t pkt) odp_queue_t defqueue = odp_pktio_outq_getdef(pktio_loop); ev = odp_packet_to_event(pkt); - CU_ASSERT(odp_queue_enq(defqueue, ev) == 0); + if (!(CU_ASSERT(odp_queue_enq(defqueue, ev) == 0))) + odp_packet_free(pkt); } static inline @@ -267,7 +268,7 @@ odp_packet_t create_packet(bool vlan) return pkt; } -int classification_tests_init(void) +int classification_suite_init(void) { odp_pool_t pool; odp_pool_param_t param; @@ -283,8 +284,7 @@ int classification_tests_init(void) param.pkt.num = SHM_PKT_NUM_BUFS; param.type = ODP_POOL_PACKET; - pool = odp_pool_create("classification_pool", - ODP_SHM_NULL, ¶m); + pool = odp_pool_create("classification_pool", ¶m); if (ODP_POOL_INVALID == pool) { fprintf(stderr, "Packet pool creation failed.\n"); return -1; @@ -323,7 +323,7 @@ int classification_tests_init(void) return 0; } -int classification_tests_finalize(void) +int classification_suite_term(void) { int i; int retcode = 0; @@ -564,7 +564,7 @@ void test_pktio_error_cos(void) odp_packet_free(pkt); } -static void classification_pktio_set_skip(void) +static void classification_test_pktio_set_skip(void) { int retval; size_t offset = 5; @@ -581,7 +581,7 @@ static void classification_pktio_set_skip(void) CU_ASSERT(retval == 0); } -static void classification_pktio_set_headroom(void) +static void classification_test_pktio_set_headroom(void) { size_t headroom; int retval; @@ -793,7 +793,7 @@ void test_pktio_pmr_match_set_cos(void) odp_packet_free(pkt); } -static void classification_pmr_terms_avail(void) +static void classification_test_pmr_terms_avail(void) { int retval; /* Since this API called at the start of the suite the return value @@ -802,15 +802,15 @@ static void classification_pmr_terms_avail(void) CU_ASSERT(retval > 0); } -static void classification_pmr_terms_cap(void) +static void classification_test_pmr_terms_cap(void) { unsigned long long retval; /* Need to check different values for different platforms */ retval = odp_pmr_terms_cap(); - CU_ASSERT(retval | (1 << ODP_PMR_IPPROTO)); + CU_ASSERT(retval & (1 << ODP_PMR_IPPROTO)); } -static void classification_pktio_configure(void) +static void classification_test_pktio_configure(void) { /* Configure the Different CoS for the pktio interface */ if (TEST_DEFAULT) @@ -826,7 +826,8 @@ static void classification_pktio_configure(void) if (TEST_PMR_SET) configure_pktio_pmr_match_set_cos(); } -static void classification_pktio_test(void) + +static void classification_test_pktio_test(void) { /* Test Different CoS on the pktio interface */ if (TEST_DEFAULT) @@ -843,12 +844,12 @@ static void classification_pktio_test(void) test_pktio_pmr_match_set_cos(); } -CU_TestInfo classification_tests[] = { - _CU_TEST_INFO(classification_pmr_terms_avail), - _CU_TEST_INFO(classification_pktio_set_skip), - _CU_TEST_INFO(classification_pktio_set_headroom), - _CU_TEST_INFO(classification_pmr_terms_cap), - _CU_TEST_INFO(classification_pktio_configure), - _CU_TEST_INFO(classification_pktio_test), +CU_TestInfo classification_suite[] = { + _CU_TEST_INFO(classification_test_pmr_terms_avail), + _CU_TEST_INFO(classification_test_pktio_set_skip), + _CU_TEST_INFO(classification_test_pktio_set_headroom), + _CU_TEST_INFO(classification_test_pmr_terms_cap), + _CU_TEST_INFO(classification_test_pktio_configure), + _CU_TEST_INFO(classification_test_pktio_test), CU_TEST_INFO_NULL, }; diff --git a/test/validation/classification/odp_classification_testsuites.h b/test/validation/classification/odp_classification_testsuites.h index 0ac5edacc..f603f3004 100644 --- a/test/validation/classification/odp_classification_testsuites.h +++ b/test/validation/classification/odp_classification_testsuites.h @@ -14,11 +14,11 @@ /* Helper macro for CU_TestInfo initialization */ #define _CU_TEST_INFO(test_func) {#test_func, test_func} -extern CU_TestInfo classification_tests[]; -extern CU_TestInfo classification_basic[]; +extern CU_TestInfo classification_suite[]; +extern CU_TestInfo classification_suite_basic[]; -extern int classification_tests_init(void); -extern int classification_tests_finalize(void); +int classification_suite_init(void); +int classification_suite_term(void); odp_packet_t create_packet(bool vlan); void configure_pktio_default_cos(void); diff --git a/test/validation/common/Makefile.am b/test/validation/common/Makefile.am new file mode 100644 index 000000000..2cb0956a1 --- /dev/null +++ b/test/validation/common/Makefile.am @@ -0,0 +1,11 @@ +AUTOMAKE_OPTIONS = foreign +include $(top_srcdir)/test/Makefile.inc + +noinst_LTLIBRARIES = libcunit_common.la libcpumask_common.la libthrmask_common.la + +libcunit_common_la_SOURCES = odp_cunit_common.c + +libcpumask_common_la_SOURCES = mask_common.c + +libthrmask_common_la_SOURCES = mask_common.c +libthrmask_common_la_CFLAGS = $(AM_CFLAGS) -DTEST_THRMASK diff --git a/test/validation/common/mask_common.c b/test/validation/common/mask_common.c new file mode 100644 index 000000000..fce7725bb --- /dev/null +++ b/test/validation/common/mask_common.c @@ -0,0 +1,472 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp.h> + +#include "odp_cunit_common.h" +#include "mask_common.h" + +/* + * The following strings are used to build masks with odp_*mask_from_str(). + * Both 0x prefixed and non prefixed hex values are supported. + */ +#define TEST_MASK_NONE "0x0" +#define TEST_MASK_0 "0x1" +#define TEST_MASK_1 "0x2" +#define TEST_MASK_2 "0x4" +#define TEST_MASK_0_2 "0x5" +#define TEST_MASK_0_3 "0x9" +#define TEST_MASK_1_2 "0x6" +#define TEST_MASK_1_3 "0xA" +#define TEST_MASK_0_1_2 "0x7" +#define TEST_MASK_0_2_4_6 "0x55" +#define TEST_MASK_1_2_4_6 "0x56" + +#define TEST_MASK_0_NO_PREFIX "1" + +/* padding pattern used to check buffer overflow: */ +#define FILLING_PATTERN 0x55 + +/* + * returns the length of a string, excluding terminating NULL. + * As its C lib strlen equivalent. Just rewritten here to avoid C lib + * dependency in ODP tests (for platform independent / bare metal testing) + */ +static unsigned int stringlen(const char *str) +{ + unsigned int i = 0; + + while (str[i] != 0) + i++; + return i; +} + +/* + * builds a string containing a 0x prefixed hex number where a single bit + * (corresponding to a cpu or thread) is set. + * The string is null terminated. + * bit_set_str(0) returns "0x1". + * bit_set_str(10) returns "0x400". + * The buffer should be at least ceil(offs/4)+3 bytes long, + * to accommodate with 4 bits per nibble + "0x" prefix + null. + */ +#define BITS_PER_NIBBLE 4 +static void bit_set_str(char *buff, int offs) +{ + const char *hex_nibble = "1248"; + int i = 0; + + buff[i++] = '0'; + buff[i++] = 'x'; + buff[i++] = hex_nibble[offs % BITS_PER_NIBBLE]; + while (offs > 3) { + buff[i++] = '0'; + offs -= BITS_PER_NIBBLE; + } + buff[i++] = 0; /* null */ +} + +/* + * Returns the maximum number of CPUs that a mask can contain. + */ +unsigned mask_capacity(void) +{ + _odp_mask_t mask; + + _odp_mask_setall(&mask); + + return _odp_mask_count(&mask); +} + +MASK_TESTFUNC(to_from_str) +{ + _odp_mask_t mask; + int32_t str_sz; + unsigned int buf_sz; /* buf size for the 2 following bufs */ + char *buf_in; + char *buf_out; + unsigned int cpu; + unsigned int i; + + /* makes sure the mask has room for at least 1 CPU...: */ + CU_ASSERT_FATAL(mask_capacity() > 0); + + /* allocate memory for the buffers containing the mask strings: + 1 char per nibble, i.e. 1 char per 4 cpus +extra for "0x" and null:*/ + buf_sz = (mask_capacity() >> 2) + 20; + buf_in = malloc(buf_sz); + buf_out = malloc(buf_sz); + CU_ASSERT_FATAL(buf_in && buf_out); + + /* test 1 CPU at a time for all possible cpu positions in the mask */ + for (cpu = 0; cpu < mask_capacity(); cpu++) { + /* init buffer for overwrite check: */ + for (i = 0; i < buf_sz; i++) + buf_out[i] = FILLING_PATTERN; + + /* generate a hex string with that cpu set: */ + bit_set_str(buf_in, cpu); + + /* generate mask: */ + _odp_mask_from_str(&mask, buf_in); + + /* reverse cpu mask computation to get string back: */ + str_sz = _odp_mask_to_str(&mask, buf_out, + stringlen(buf_in) + 1); + + /* check that returned size matches original (with NULL): */ + CU_ASSERT(str_sz == (int32_t)stringlen(buf_in) + 1); + + /* check that returned string matches original (with NULL): */ + CU_ASSERT_NSTRING_EQUAL(buf_out, buf_in, stringlen(buf_in) + 1); + + /* check that no extra buffer writes occurred: */ + CU_ASSERT(buf_out[stringlen(buf_in) + 2] == FILLING_PATTERN); + } + + /* re-init buffer for overwrite check: */ + for (i = 0; i < buf_sz; i++) + buf_out[i] = FILLING_PATTERN; + + /* check for buffer overflow when too small buffer given: */ + _odp_mask_from_str(&mask, TEST_MASK_0); + str_sz = _odp_mask_to_str(&mask, buf_out, stringlen(TEST_MASK_0)); + + CU_ASSERT(str_sz == -1); + + for (i = 0; i < buf_sz; i++) + CU_ASSERT(buf_out[i] == FILLING_PATTERN); + + /* check for handling of missing "0x" prefix: */ + _odp_mask_from_str(&mask, TEST_MASK_0_NO_PREFIX); + + str_sz = _odp_mask_to_str(&mask, buf_out, + stringlen(TEST_MASK_0) + 1); + + CU_ASSERT_NSTRING_EQUAL(buf_out, TEST_MASK_0, + stringlen(TEST_MASK_0) + 1); + + free(buf_out); + free(buf_in); +} + +MASK_TESTFUNC(equal) +{ + _odp_mask_t mask1; + _odp_mask_t mask2; + _odp_mask_t mask3; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask3, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + CU_ASSERT_FALSE(_odp_mask_equal(&mask1, &mask3)); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + _odp_mask_from_str(&mask2, TEST_MASK_0_2); + _odp_mask_from_str(&mask3, TEST_MASK_1_2); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + CU_ASSERT_FALSE(_odp_mask_equal(&mask1, &mask3)); + + if (mask_capacity() < 8) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_0_2_4_6); + _odp_mask_from_str(&mask2, TEST_MASK_0_2_4_6); + _odp_mask_from_str(&mask3, TEST_MASK_1_2_4_6); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + CU_ASSERT_FALSE(_odp_mask_equal(&mask1, &mask3)); +} + +MASK_TESTFUNC(zero) +{ + _odp_mask_t mask1; + _odp_mask_t mask2; + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_zero(&mask2); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); +} + +MASK_TESTFUNC(set) +{ + _odp_mask_t mask1; + _odp_mask_t mask2; + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_set(&mask1, 0); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask2, TEST_MASK_0_3); + _odp_mask_set(&mask1, 3); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + + /* make sure that re-asserting a cpu has no impact: */ + _odp_mask_set(&mask1, 3); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); +} + +MASK_TESTFUNC(clr) +{ + _odp_mask_t mask1; + _odp_mask_t mask2; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_clr(&mask1, 0); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_clr(&mask1, 2); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_clr(&mask1, 0); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + + /* make sure that re-clearing a cpu has no impact: */ + _odp_mask_clr(&mask1, 0); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); +} + +MASK_TESTFUNC(isset) +{ + _odp_mask_t mask1; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_isset(&mask1, 0)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT_FALSE(_odp_mask_isset(&mask1, 0)); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + CU_ASSERT(_odp_mask_isset(&mask1, 0)); + CU_ASSERT_FALSE(_odp_mask_isset(&mask1, 1)); + CU_ASSERT(_odp_mask_isset(&mask1, 2)); + CU_ASSERT_FALSE(_odp_mask_isset(&mask1, 3)); +} + +MASK_TESTFUNC(count) +{ + _odp_mask_t mask1; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_count(&mask1) == 1); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_count(&mask1) == 0); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + CU_ASSERT(_odp_mask_count(&mask1) == 2); +} + +MASK_TESTFUNC(and) +{ + _odp_mask_t mask1; + _odp_mask_t mask2; + _odp_mask_t mask3; + _odp_mask_t mask4; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_0); + _odp_mask_and(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_and(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_and(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + _odp_mask_from_str(&mask2, TEST_MASK_1_2); + _odp_mask_from_str(&mask4, TEST_MASK_2); + _odp_mask_and(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); +} + +MASK_TESTFUNC(or) +{ + _odp_mask_t mask1; + _odp_mask_t mask2; + _odp_mask_t mask3; + _odp_mask_t mask4; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_0); + _odp_mask_or(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_0); + _odp_mask_or(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_or(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + _odp_mask_from_str(&mask2, TEST_MASK_1); + _odp_mask_from_str(&mask4, TEST_MASK_0_1_2); + _odp_mask_or(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); +} + +MASK_TESTFUNC(xor) +{ + _odp_mask_t mask1; + _odp_mask_t mask2; + _odp_mask_t mask3; + _odp_mask_t mask4; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_xor(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_0); + _odp_mask_xor(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_xor(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_2); + _odp_mask_from_str(&mask2, TEST_MASK_1_2); + _odp_mask_from_str(&mask4, TEST_MASK_1); + _odp_mask_xor(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); +} + +MASK_TESTFUNC(copy) +{ + _odp_mask_t mask1; + _odp_mask_t mask2; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_copy(&mask2, &mask1); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); +} + +MASK_TESTFUNC(first) +{ + _odp_mask_t mask1; + + /* check when there is no first */ + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_first(&mask1) == -1); + + /* single CPU case: */ + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_first(&mask1) == 0); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_1_3); + CU_ASSERT(_odp_mask_first(&mask1) == 1); +} + +MASK_TESTFUNC(last) +{ + _odp_mask_t mask1; + + /* check when there is no last: */ + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_last(&mask1) == -1); + + /* single CPU case: */ + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_last(&mask1) == 0); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_1_3); + CU_ASSERT(_odp_mask_last(&mask1) == 3); +} + +MASK_TESTFUNC(next) +{ + unsigned int i; + int expected[] = {1, 3, 3, -1}; + _odp_mask_t mask1; + + /* case when the mask does not contain any CPU: */ + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_next(&mask1, -1) == -1); + + /* case when the mask just contain CPU 0: */ + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_next(&mask1, -1) == 0); + CU_ASSERT(_odp_mask_next(&mask1, 0) == -1); + + if (mask_capacity() < 4) + return; + + _odp_mask_from_str(&mask1, TEST_MASK_1_3); + + for (i = 0; i < sizeof(expected) / sizeof(int); i++) + CU_ASSERT(_odp_mask_next(&mask1, i) == expected[i]); +} + +MASK_TESTFUNC(setall) +{ + int num; + int max = mask_capacity(); + _odp_mask_t mask; + + _odp_mask_setall(&mask); + num = _odp_mask_count(&mask); + + CU_ASSERT(num > 0); + CU_ASSERT(num <= max); +} diff --git a/test/validation/common/mask_common.h b/test/validation/common/mask_common.h new file mode 100644 index 000000000..e7a38a7c7 --- /dev/null +++ b/test/validation/common/mask_common.h @@ -0,0 +1,61 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_MASK_COMMON_H_ +#define ODP_MASK_COMMON_H_ + +/* + * The same set of tests are used for testing both the odp_thrmask_ and + * odp_cpumask_ APIs. + * + * To build the thrmask tests TEST_THRMASK must be defined. + */ +#ifdef TEST_THRMASK +typedef odp_thrmask_t _odp_mask_t; +#define MASK_API_PREFIX(n) odp_thrmask_##n +#define MASK_TESTFUNC(n) void thread_test_odp_thrmask_##n(void) +#else +typedef odp_cpumask_t _odp_mask_t; +#define MASK_API_PREFIX(n) odp_cpumask_##n +#define MASK_TESTFUNC(n) void cpumask_test_odp_cpumask_##n(void) +#endif + +#define _odp_mask_from_str MASK_API_PREFIX(from_str) +#define _odp_mask_to_str MASK_API_PREFIX(to_str) +#define _odp_mask_equal MASK_API_PREFIX(equal) +#define _odp_mask_zero MASK_API_PREFIX(zero) +#define _odp_mask_set MASK_API_PREFIX(set) +#define _odp_mask_clr MASK_API_PREFIX(clr) +#define _odp_mask_isset MASK_API_PREFIX(isset) +#define _odp_mask_count MASK_API_PREFIX(count) +#define _odp_mask_and MASK_API_PREFIX(and) +#define _odp_mask_or MASK_API_PREFIX(or) +#define _odp_mask_xor MASK_API_PREFIX(xor) +#define _odp_mask_copy MASK_API_PREFIX(copy) +#define _odp_mask_first MASK_API_PREFIX(first) +#define _odp_mask_next MASK_API_PREFIX(next) +#define _odp_mask_last MASK_API_PREFIX(last) +#define _odp_mask_setall MASK_API_PREFIX(setall) + +unsigned mask_capacity(void); + +MASK_TESTFUNC(to_from_str); +MASK_TESTFUNC(equal); +MASK_TESTFUNC(zero); +MASK_TESTFUNC(set); +MASK_TESTFUNC(clr); +MASK_TESTFUNC(isset); +MASK_TESTFUNC(count); +MASK_TESTFUNC(and); +MASK_TESTFUNC(or); +MASK_TESTFUNC(xor); +MASK_TESTFUNC(copy); +MASK_TESTFUNC(first); +MASK_TESTFUNC(last); +MASK_TESTFUNC(next); +MASK_TESTFUNC(setall); + +#endif diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c index eac2d81ba..d995ad3d2 100644 --- a/test/validation/common/odp_cunit_common.c +++ b/test/validation/common/odp_cunit_common.c @@ -4,12 +4,6 @@ * SPDX-License-Identifier: BSD-3-Clause */ -/** - * @file - * - * ODP test application common - */ - #include <string.h> #include <odp.h> #include <odp_cunit_common.h> @@ -17,17 +11,27 @@ /* Globals */ static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; +/* + * global init/term functions which may be registered + * defaults to functions performing odp init/term. + */ +static int tests_global_init(void); +static int tests_global_term(void); +static struct { + int (*global_init_ptr)(void); + int (*global_term_ptr)(void); +} global_init_term = {tests_global_init, tests_global_term}; + /** create test thread */ int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg) { odp_cpumask_t cpumask; /* Create and init additional threads */ - odph_linux_cpumask_default(&cpumask, arg->numthrds); - odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr, - (void *)arg); + odp_cpumask_def_worker(&cpumask, arg->numthrds); - return 0; + return odph_linux_pthread_create(thread_tbl, &cpumask, func_ptr, + (void *)arg); } /** exit from test thread */ @@ -39,13 +43,13 @@ int odp_cunit_thread_exit(pthrd_arg *arg) return 0; } -ODP_WEAK_SYMBOL int tests_global_init(void) +static int tests_global_init(void) { if (0 != odp_init_global(NULL, NULL)) { fprintf(stderr, "error: odp_init_global() failed.\n"); return -1; } - if (0 != odp_init_local()) { + if (0 != odp_init_local(ODP_THREAD_CONTROL)) { fprintf(stderr, "error: odp_init_local() failed.\n"); return -1; } @@ -53,7 +57,7 @@ ODP_WEAK_SYMBOL int tests_global_init(void) return 0; } -ODP_WEAK_SYMBOL int tests_global_term(void) +static int tests_global_term(void) { if (0 != odp_term_local()) { fprintf(stderr, "error: odp_term_local() failed.\n"); @@ -68,20 +72,40 @@ ODP_WEAK_SYMBOL int tests_global_term(void) return 0; } -int main(void) +/* + * register tests_global_init and tests_global_term functions. + * If some of these functions are not registered, the defaults functions + * (tests_global_init() and tests_global_term()) defined above are used. + * One should use these register functions when defining these hooks. + * Note that passing NULL as function pointer is valid and will simply + * prevent the default (odp init/term) to be done. + */ +void odp_cunit_register_global_init(int (*func_init_ptr)(void)) +{ + global_init_term.global_init_ptr = func_init_ptr; +} + +void odp_cunit_register_global_term(int (*func_term_ptr)(void)) +{ + global_init_term.global_term_ptr = func_term_ptr; +} + +int odp_cunit_run(CU_SuiteInfo testsuites[]) { int ret; printf("\tODP API version: %s\n", odp_version_api_str()); printf("\tODP implementation version: %s\n", odp_version_impl_str()); - if (0 != tests_global_init()) + /* call test executable init hook, if any */ + if (global_init_term.global_init_ptr && + ((*global_init_term.global_init_ptr)() != 0)) return -1; CU_set_error_action(CUEA_ABORT); CU_initialize_registry(); - CU_register_suites(odp_testsuites); + CU_register_suites(testsuites); CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); @@ -89,7 +113,9 @@ int main(void) CU_cleanup_registry(); - if (0 != tests_global_term()) + /* call test executable terminason hook, if any */ + if (global_init_term.global_term_ptr && + ((*global_init_term.global_term_ptr)() != 0)) return -1; return (ret) ? -1 : 0; diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h index 127020d12..7c2a9dd89 100644 --- a/test/validation/common/odp_cunit_common.h +++ b/test/validation/common/odp_cunit_common.h @@ -13,16 +13,13 @@ #ifndef ODP_CUNICT_COMMON_H #define ODP_CUNICT_COMMON_H +#include <stdint.h> #include "CUnit/Basic.h" #define MAX_WORKERS 32 /**< Maximum number of work threads */ -/** - * Array of testsuites provided by a test application. Array must be terminated - * by CU_SUITE_INFO_NULL and must be suitable to be used by - * CU_register_suites(). - */ -extern CU_SuiteInfo odp_testsuites[]; +/* the function, called by module main(), to run the testsuites: */ +int odp_cunit_run(CU_SuiteInfo testsuites[]); typedef struct { uint32_t foo; @@ -40,21 +37,21 @@ typedef struct { /** create thread fro start_routine function */ extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg); extern int odp_cunit_thread_exit(pthrd_arg *); + /** - * Global tests initialization. - * - * Initialize global resources needed by all testsuites. Default weak definition - * do nothing. Test application can override it by defining a strong version. - * The function is called by the common main() just after ODP global/local - * initialization. + * Global tests initialization/termination. * - * @note: This function is a workaround for Crypto test and other applications - * should try not to use it, because it will complicate migration to a - * single test application in future. Normally each testsuite have to - * prepare its environment in its own init function. + * Initialize global resources needed by the test executable. Default + * definition does ODP init / term (both global and local). + * Test executables can override it by calling one of the register function + * below. + * The functions are called at the very beginning and very end of the test + * execution. Passing NULL to odp_cunit_register_global_init() and/or + * odp_cunit_register_global_term() is legal and will simply prevent the + * default (ODP init/term) to be done. */ -extern int tests_global_init(void); +void odp_cunit_register_global_init(int (*func_init_ptr)(void)); -extern int tests_global_term(void); +void odp_cunit_register_global_term(int (*func_term_ptr)(void)); #endif /* ODP_CUNICT_COMMON_H */ diff --git a/test/validation/cpumask/.gitignore b/test/validation/cpumask/.gitignore new file mode 100644 index 000000000..655a1640f --- /dev/null +++ b/test/validation/cpumask/.gitignore @@ -0,0 +1 @@ +cpumask_main diff --git a/test/validation/cpumask/Makefile.am b/test/validation/cpumask/Makefile.am new file mode 100644 index 000000000..795d9ffc8 --- /dev/null +++ b/test/validation/cpumask/Makefile.am @@ -0,0 +1,9 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libcpumask.la +libcpumask_la_SOURCES = cpumask.c +libcpumask_la_LIBADD = $(LIBCPUMASK_COMMON) + +bin_PROGRAMS = cpumask_main$(EXEEXT) +dist_cpumask_main_SOURCES = cpumask_main.c +cpumask_main_LDADD = libcpumask.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/cpumask/cpumask.c b/test/validation/cpumask/cpumask.c new file mode 100644 index 000000000..76b764859 --- /dev/null +++ b/test/validation/cpumask/cpumask.c @@ -0,0 +1,105 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp.h> + +#include "odp_cunit_common.h" +#include "cpumask.h" +#include "mask_common.h" + +/* default worker paramiter to get all that may be available */ +#define ALL_AVAILABLE 0 + +static void cpumask_test_odp_cpumask_def_control(void) +{ + unsigned num; + unsigned mask_count; + unsigned max_cpus = mask_capacity(); + odp_cpumask_t mask; + + num = odp_cpumask_def_control(&mask, ALL_AVAILABLE); + mask_count = odp_cpumask_count(&mask); + + CU_ASSERT(mask_count == num); + CU_ASSERT(num > 0); + CU_ASSERT(num <= max_cpus); +} + +static void cpumask_test_odp_cpumask_def_worker(void) +{ + unsigned num; + unsigned mask_count; + unsigned max_cpus = mask_capacity(); + odp_cpumask_t mask; + + num = odp_cpumask_def_worker(&mask, ALL_AVAILABLE); + mask_count = odp_cpumask_count(&mask); + + CU_ASSERT(mask_count == num); + CU_ASSERT(num > 0); + CU_ASSERT(num <= max_cpus); +} + +static void cpumask_test_odp_cpumask_def(void) +{ + unsigned mask_count; + unsigned num_worker; + unsigned num_control; + unsigned max_cpus = mask_capacity(); + unsigned available_cpus = odp_cpu_count(); + unsigned requested_cpus; + odp_cpumask_t mask; + + CU_ASSERT(available_cpus <= max_cpus); + + if (available_cpus > 1) + requested_cpus = available_cpus - 1; + else + requested_cpus = available_cpus; + num_worker = odp_cpumask_def_worker(&mask, requested_cpus); + mask_count = odp_cpumask_count(&mask); + CU_ASSERT(mask_count == num_worker); + + num_control = odp_cpumask_def_control(&mask, 1); + mask_count = odp_cpumask_count(&mask); + CU_ASSERT(mask_count == num_control); + + CU_ASSERT(num_control == 1); + CU_ASSERT(num_worker <= available_cpus); + CU_ASSERT(num_worker > 0); +} + +static CU_TestInfo cpumask_suite[] = { + {"odp_cpumask_to/from_str()", cpumask_test_odp_cpumask_to_from_str}, + {"odp_cpumask_equal()", cpumask_test_odp_cpumask_equal}, + {"odp_cpumask_zero()", cpumask_test_odp_cpumask_zero}, + {"odp_cpumask_set()", cpumask_test_odp_cpumask_set}, + {"odp_cpumask_clr()", cpumask_test_odp_cpumask_clr}, + {"odp_cpumask_isset()", cpumask_test_odp_cpumask_isset}, + {"odp_cpumask_count()", cpumask_test_odp_cpumask_count}, + {"odp_cpumask_and()", cpumask_test_odp_cpumask_and}, + {"odp_cpumask_or()", cpumask_test_odp_cpumask_or}, + {"odp_cpumask_xor()", cpumask_test_odp_cpumask_xor}, + {"odp_cpumask_copy()", cpumask_test_odp_cpumask_copy}, + {"odp_cpumask_first()", cpumask_test_odp_cpumask_first}, + {"odp_cpumask_last()", cpumask_test_odp_cpumask_last}, + {"odp_cpumask_next()", cpumask_test_odp_cpumask_next}, + {"odp_cpumask_setall()", cpumask_test_odp_cpumask_setall}, + {"odp_cpumask_def_control()", cpumask_test_odp_cpumask_def_control}, + {"odp_cpumask_def_worker()", cpumask_test_odp_cpumask_def_worker}, + {"odp_cpumask_def()", cpumask_test_odp_cpumask_def}, + CU_TEST_INFO_NULL, +}; + +static CU_SuiteInfo cpumask_suites[] = { + {"Cpumask", NULL, NULL, NULL, NULL, cpumask_suite}, + CU_SUITE_INFO_NULL, +}; + +int cpumask_main(void) +{ + return odp_cunit_run(cpumask_suites); +} diff --git a/test/validation/cpumask/cpumask.h b/test/validation/cpumask/cpumask.h new file mode 100644 index 000000000..2c6fb4adc --- /dev/null +++ b/test/validation/cpumask/cpumask.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_CPUMASK_H_ +#define _ODP_TEST_CPUMASK_H_ + +int cpumask_main(void); + +#endif diff --git a/test/validation/cpumask/cpumask_main.c b/test/validation/cpumask/cpumask_main.c new file mode 100644 index 000000000..ceac674d8 --- /dev/null +++ b/test/validation/cpumask/cpumask_main.c @@ -0,0 +1,11 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "cpumask.h" + +int main(void) +{ + return cpumask_main(); +} diff --git a/test/validation/crypto/.gitignore b/test/validation/crypto/.gitignore new file mode 100644 index 000000000..0ac55e35e --- /dev/null +++ b/test/validation/crypto/.gitignore @@ -0,0 +1 @@ +crypto_main diff --git a/test/validation/crypto/Makefile.am b/test/validation/crypto/Makefile.am new file mode 100644 index 000000000..6c7a94ba1 --- /dev/null +++ b/test/validation/crypto/Makefile.am @@ -0,0 +1,9 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libcrypto.la +libcrypto_la_SOURCES = crypto.c \ + odp_crypto_test_inp.c + +bin_PROGRAMS = crypto_main$(EXEEXT) +dist_crypto_main_SOURCES = crypto_main.c +crypto_main_LDADD = libcrypto.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_crypto.c b/test/validation/crypto/crypto.c index 2a20ea141..996543259 100644 --- a/test/validation/odp_crypto.c +++ b/test/validation/crypto/crypto.c @@ -7,22 +7,23 @@ #include <odp.h> #include "odp_cunit_common.h" #include "odp_crypto_test_inp.h" +#include "crypto.h" -#define SHM_PKT_POOL_SIZE (512*2048*2) +#define SHM_PKT_POOL_SIZE (512 * 2048 * 2) #define SHM_PKT_POOL_BUF_SIZE (1024 * 32) -#define SHM_COMPL_POOL_SIZE (128*1024) +#define SHM_COMPL_POOL_SIZE (128 * 1024) #define SHM_COMPL_POOL_BUF_SIZE 128 -CU_SuiteInfo odp_testsuites[] = { - {ODP_CRYPTO_SYNC_INP, suite_sync_inp_init, NULL, NULL, NULL, - test_array_inp}, - {ODP_CRYPTO_ASYNC_INP, suite_async_inp_init, NULL, NULL, NULL, - test_array_inp}, +static CU_SuiteInfo crypto_suites[] = { + {ODP_CRYPTO_SYNC_INP, crypto_suite_sync_init, NULL, NULL, NULL, + crypto_suite}, + {ODP_CRYPTO_ASYNC_INP, crypto_suite_async_init, NULL, NULL, NULL, + crypto_suite}, CU_SUITE_INFO_NULL, }; -int tests_global_init(void) +static int crypto_init(void) { odp_pool_param_t params; odp_pool_t pool; @@ -32,7 +33,7 @@ int tests_global_init(void) fprintf(stderr, "error: odp_init_global() failed.\n"); return -1; } - if (0 != odp_init_local()) { + if (0 != odp_init_local(ODP_THREAD_CONTROL)) { fprintf(stderr, "error: odp_init_local() failed.\n"); return -1; } @@ -40,10 +41,10 @@ int tests_global_init(void) memset(¶ms, 0, sizeof(params)); params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; params.pkt.len = SHM_PKT_POOL_BUF_SIZE; - params.pkt.num = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; + params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUF_SIZE; params.type = ODP_POOL_PACKET; - pool = odp_pool_create("packet_pool", ODP_SHM_NULL, ¶ms); + pool = odp_pool_create("packet_pool", ¶ms); if (ODP_POOL_INVALID == pool) { fprintf(stderr, "Packet pool creation failed.\n"); @@ -59,7 +60,7 @@ int tests_global_init(void) return 0; } -int tests_global_term(void) +static int crypto_term(void) { odp_pool_t pool; odp_queue_t out_queue; @@ -92,3 +93,10 @@ int tests_global_term(void) return 0; } + +int crypto_main(void) +{ + odp_cunit_register_global_init(crypto_init); + odp_cunit_register_global_term(crypto_term); + return odp_cunit_run(crypto_suites); +} diff --git a/test/validation/crypto/crypto.h b/test/validation/crypto/crypto.h new file mode 100644 index 000000000..9ab641b15 --- /dev/null +++ b/test/validation/crypto/crypto.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_CRYPTO_H_ +#define _ODP_TEST_CRYPTO_H_ + +int crypto_main(void); + +#endif diff --git a/test/validation/crypto/crypto_main.c b/test/validation/crypto/crypto_main.c new file mode 100644 index 000000000..644e666f6 --- /dev/null +++ b/test/validation/crypto/crypto_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "crypto.h" + +int main(void) +{ + return crypto_main(); +} diff --git a/test/validation/crypto/odp_crypto_test_inp.c b/test/validation/crypto/odp_crypto_test_inp.c index 5f688d67b..c1c08af50 100644 --- a/test/validation/crypto/odp_crypto_test_inp.c +++ b/test/validation/crypto/odp_crypto_test_inp.c @@ -132,7 +132,7 @@ cleanup: * In addition the test verifies if the implementation can use the * packet buffer as completion event buffer.*/ #define ASYNC_INP_ENC_ALG_3DES_CBC "ENC_ALG_3DES_CBC" -static void enc_alg_3des_cbc(void) +static void crypto_test_enc_alg_3des_cbc(void) { odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, auth_key = { .data = NULL, .length = 0 }; @@ -165,7 +165,7 @@ static void enc_alg_3des_cbc(void) * operation for 3DES_CBC algorithm. IV for the operation is the operation IV. * */ #define ASYNC_INP_ENC_ALG_3DES_CBC_OVR_IV "ENC_ALG_3DES_CBC_OVR_IV" -static void enc_alg_3des_cbc_ovr_iv(void) +static void crypto_test_enc_alg_3des_cbc_ovr_iv(void) { odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, auth_key = { .data = NULL, .length = 0 }; @@ -199,7 +199,7 @@ static void enc_alg_3des_cbc_ovr_iv(void) * packet buffer as completion event buffer. * */ #define ASYNC_INP_DEC_ALG_3DES_CBC "DEC_ALG_3DES_CBC" -static void dec_alg_3des_cbc(void) +static void crypto_test_dec_alg_3des_cbc(void) { odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, auth_key = { .data = NULL, .length = 0 }; @@ -234,7 +234,7 @@ static void dec_alg_3des_cbc(void) * packet buffer as completion event buffer. * */ #define ASYNC_INP_DEC_ALG_3DES_CBC_OVR_IV "DEC_ALG_3DES_CBC_OVR_IV" -static void dec_alg_3des_cbc_ovr_iv(void) +static void crypto_test_dec_alg_3des_cbc_ovr_iv(void) { odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, auth_key = { .data = NULL, .length = 0 }; @@ -270,7 +270,7 @@ static void dec_alg_3des_cbc_ovr_iv(void) * packet buffer as completion event buffer. * */ #define ASYNC_INP_ALG_HMAC_MD5 "ALG_HMAC_MD5" -static void alg_hmac_md5(void) +static void crypto_test_alg_hmac_md5(void) { odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, auth_key = { .data = NULL, .length = 0 }; @@ -298,7 +298,7 @@ static void alg_hmac_md5(void) } } -int suite_sync_inp_init(void) +int crypto_suite_sync_init(void) { suite_context.pool = odp_pool_lookup("packet_pool"); if (suite_context.pool == ODP_POOL_INVALID) @@ -309,7 +309,7 @@ int suite_sync_inp_init(void) return 0; } -int suite_async_inp_init(void) +int crypto_suite_async_init(void) { suite_context.pool = odp_pool_lookup("packet_pool"); if (suite_context.pool == ODP_POOL_INVALID) @@ -322,11 +322,13 @@ int suite_async_inp_init(void) return 0; } -CU_TestInfo test_array_inp[] = { - {ASYNC_INP_ENC_ALG_3DES_CBC, enc_alg_3des_cbc }, - {ASYNC_INP_DEC_ALG_3DES_CBC, dec_alg_3des_cbc }, - {ASYNC_INP_ENC_ALG_3DES_CBC_OVR_IV, enc_alg_3des_cbc_ovr_iv }, - {ASYNC_INP_DEC_ALG_3DES_CBC_OVR_IV, dec_alg_3des_cbc_ovr_iv }, - {ASYNC_INP_ALG_HMAC_MD5, alg_hmac_md5 }, +CU_TestInfo crypto_suite[] = { + {ASYNC_INP_ENC_ALG_3DES_CBC, crypto_test_enc_alg_3des_cbc }, + {ASYNC_INP_DEC_ALG_3DES_CBC, crypto_test_dec_alg_3des_cbc }, + {ASYNC_INP_ENC_ALG_3DES_CBC_OVR_IV, + crypto_test_enc_alg_3des_cbc_ovr_iv }, + {ASYNC_INP_DEC_ALG_3DES_CBC_OVR_IV, + crypto_test_dec_alg_3des_cbc_ovr_iv }, + {ASYNC_INP_ALG_HMAC_MD5, crypto_test_alg_hmac_md5 }, CU_TEST_INFO_NULL, }; diff --git a/test/validation/crypto/odp_crypto_test_inp.h b/test/validation/crypto/odp_crypto_test_inp.h index a3a5d8de7..d46994fb7 100644 --- a/test/validation/crypto/odp_crypto_test_inp.h +++ b/test/validation/crypto/odp_crypto_test_inp.h @@ -13,9 +13,9 @@ #define ODP_CRYPTO_SYNC_INP "odp_crypto_sync_inp" /* Suite test array */ -extern CU_TestInfo test_array_inp[]; +extern CU_TestInfo crypto_suite[]; -int suite_sync_inp_init(void); -int suite_async_inp_init(void); +int crypto_suite_sync_init(void); +int crypto_suite_async_init(void); #endif diff --git a/test/validation/crypto/test_vectors.h b/test/validation/crypto/test_vectors.h index 369fc16b0..490a3bcd5 100644 --- a/test/validation/crypto/test_vectors.h +++ b/test/validation/crypto/test_vectors.h @@ -4,6 +4,9 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#ifndef _ODP_TEST_CRYPTO_VECTORS_H_ +#define _ODP_TEST_CRYPTO_VECTORS_H_ + #include "test_vectors_len.h" /* TDES-CBC reference vectors, according to * "http://csrc.nist.gov/groups/STM/cavp/documents/des/DESMMT.pdf" @@ -83,3 +86,5 @@ static uint8_t hmac_md5_reference_digest[][HMAC_MD5_DIGEST_LEN] = { { 0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88, 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 } }; + +#endif diff --git a/test/validation/errno/.gitignore b/test/validation/errno/.gitignore new file mode 100644 index 000000000..12256e38c --- /dev/null +++ b/test/validation/errno/.gitignore @@ -0,0 +1 @@ +errno_main diff --git a/test/validation/errno/Makefile.am b/test/validation/errno/Makefile.am new file mode 100644 index 000000000..ab3ef8878 --- /dev/null +++ b/test/validation/errno/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = liberrno.la +liberrno_la_SOURCES = errno.c + +bin_PROGRAMS = errno_main$(EXEEXT) +dist_errno_main_SOURCES = errno_main.c +errno_main_LDADD = liberrno.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/ver_abt_log_dbg/odp_errno.c b/test/validation/errno/errno.c index 368f26e89..ac1d93caf 100644 --- a/test/validation/ver_abt_log_dbg/odp_errno.c +++ b/test/validation/errno/errno.c @@ -7,9 +7,10 @@ #include <odp.h> #include "odp_cunit_common.h" -static void test_odp_errno_sunny_day(void) +static void errno_test_odp_errno_sunny_day(void) { int my_errno; + odp_errno_zero(); my_errno = odp_errno(); CU_ASSERT_TRUE(my_errno == 0); @@ -17,7 +18,17 @@ static void test_odp_errno_sunny_day(void) CU_ASSERT_PTR_NOT_NULL(odp_errno_str(my_errno)); } -CU_TestInfo test_odp_errno[] = { - {"sunny day", test_odp_errno_sunny_day}, +CU_TestInfo errno_suite[] = { + {"sunny day", errno_test_odp_errno_sunny_day}, CU_TEST_INFO_NULL, }; + +CU_SuiteInfo errno_suites[] = { + {"Errno", NULL, NULL, NULL, NULL, errno_suite}, + CU_SUITE_INFO_NULL, +}; + +int errno_main(void) +{ + return odp_cunit_run(errno_suites); +} diff --git a/test/validation/errno/errno.h b/test/validation/errno/errno.h new file mode 100644 index 000000000..592376838 --- /dev/null +++ b/test/validation/errno/errno.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_ERRNO_H_ +#define _ODP_TEST_ERRNO_H_ + +int errno_main(void); + +#endif diff --git a/test/validation/errno/errno_main.c b/test/validation/errno/errno_main.c new file mode 100644 index 000000000..0e82422b1 --- /dev/null +++ b/test/validation/errno/errno_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "errno.h" + +int main(void) +{ + return errno_main(); +} diff --git a/test/validation/init/.gitignore b/test/validation/init/.gitignore new file mode 100644 index 000000000..f433708b0 --- /dev/null +++ b/test/validation/init/.gitignore @@ -0,0 +1,3 @@ +init_main_abort +init_main_log +init_main_ok diff --git a/test/validation/init/Makefile.am b/test/validation/init/Makefile.am new file mode 100644 index 000000000..a54e29aea --- /dev/null +++ b/test/validation/init/Makefile.am @@ -0,0 +1,14 @@ +include ../Makefile.inc +noinst_LTLIBRARIES = libinit.la +libinit_la_SOURCES = init.c + +# most platforms are expected not to support multiple ODP inits +# following each other: therefore 3 separate binaries are +# created, each containing its ODP init test. +bin_PROGRAMS = init_main_abort$(EXEEXT) init_main_log$(EXEEXT) init_main_ok$(EXEEXT) +dist_init_main_abort_SOURCES = init_main_abort.c +dist_init_main_log_SOURCES = init_main_log.c +dist_init_main_ok_SOURCES = init_main_ok.c +init_main_abort_LDADD = libinit.la $(LIBCUNIT_COMMON) $(LIBODP) +init_main_log_LDADD = libinit.la $(LIBCUNIT_COMMON) $(LIBODP) +init_main_ok_LDADD = libinit.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/init/init.c b/test/validation/init/init.c new file mode 100644 index 000000000..169bd5c58 --- /dev/null +++ b/test/validation/init/init.c @@ -0,0 +1,151 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <stdarg.h> +#include <stdlib.h> +#include <odp.h> +#include <CUnit/Basic.h> +#include "odp_cunit_common.h" +#include "init.h" + +/* flag set when the replacement logging function is used */ +int replacement_logging_used; + +/* replacement abort function: */ +static void odp_init_abort(void) ODP_NORETURN; + +/* replacement log function: */ +ODP_PRINTF_FORMAT(2, 3) +static int odp_init_log(odp_log_level_e level, const char *fmt, ...); + +/* test ODP global init, with alternate abort function */ +static void init_test_odp_init_global_replace_abort(void) +{ + int status; + struct odp_init_t init_data; + + memset(&init_data, 0, sizeof(init_data)); + init_data.abort_fn = &odp_init_abort; + + status = odp_init_global(&init_data, NULL); + CU_ASSERT_FATAL(status == 0); + + status = odp_term_global(); + CU_ASSERT(status == 0); +} + +static CU_TestInfo init_suite_abort[] = { + {"replace abort", init_test_odp_init_global_replace_abort}, + CU_TEST_INFO_NULL, +}; + +static CU_SuiteInfo init_suites_abort[] = { + {"Init", NULL, NULL, NULL, NULL, init_suite_abort}, + CU_SUITE_INFO_NULL, +}; + +static void odp_init_abort(void) +{ + abort(); +} + +int init_main_abort(void) +{ + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* run the tests: */ + return odp_cunit_run(init_suites_abort); +} + +/* test ODP global init, with alternate log function */ +static void init_test_odp_init_global_replace_log(void) +{ + int status; + struct odp_init_t init_data; + + memset(&init_data, 0, sizeof(init_data)); + init_data.log_fn = &odp_init_log; + + replacement_logging_used = 0; + + status = odp_init_global(&init_data, NULL); + CU_ASSERT_FATAL(status == 0); + + CU_ASSERT_TRUE(replacement_logging_used); + + status = odp_term_global(); + CU_ASSERT(status == 0); +} + +static CU_TestInfo init_suite_log[] = { + {"replace log", init_test_odp_init_global_replace_log}, + CU_TEST_INFO_NULL, +}; + +static CU_SuiteInfo init_suites_log[] = { + {"Init", NULL, NULL, NULL, NULL, init_suite_log}, + CU_SUITE_INFO_NULL, +}; + +static int odp_init_log(odp_log_level_e level __attribute__((unused)), + const char *fmt, ...) +{ + va_list args; + int r; + + /* just set a flag to be sure the replacement fn was used */ + replacement_logging_used = 1; + + va_start(args, fmt); + r = vfprintf(stderr, fmt, args); + va_end(args); + + return r; +} + +int init_main_log(void) +{ + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* run the tests: */ + return odp_cunit_run(init_suites_log); +} + +/* test normal ODP global init */ +static void init_test_odp_init_global(void) +{ + int status; + + status = odp_init_global(NULL, NULL); + CU_ASSERT_FATAL(status == 0); + + status = odp_term_global(); + CU_ASSERT(status == 0); +} + +static CU_TestInfo init_suite_ok[] = { + {"test_odp_init_global", init_test_odp_init_global}, + CU_TEST_INFO_NULL, +}; + +static CU_SuiteInfo init_suites_ok[] = { + {"Init", NULL, NULL, NULL, NULL, init_suite_ok}, + CU_SUITE_INFO_NULL, +}; + +int init_main_ok(void) +{ + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* run the tests: */ + return odp_cunit_run(init_suites_ok); +} diff --git a/test/validation/init/init.h b/test/validation/init/init.h new file mode 100644 index 000000000..7e5a082f2 --- /dev/null +++ b/test/validation/init/init.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_INIT_H_ +#define _ODP_TEST_INIT_H_ + +int init_main_abort(void); +int init_main_log(void); +int init_main_ok(void); + +#endif diff --git a/test/validation/init/init_main_abort.c b/test/validation/init/init_main_abort.c new file mode 100644 index 000000000..c7bdd9deb --- /dev/null +++ b/test/validation/init/init_main_abort.c @@ -0,0 +1,11 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "init.h" + +int main(void) +{ + return init_main_abort(); +} diff --git a/test/validation/init/init_main_log.c b/test/validation/init/init_main_log.c new file mode 100644 index 000000000..f35ac38e5 --- /dev/null +++ b/test/validation/init/init_main_log.c @@ -0,0 +1,11 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "init.h" + +int main(void) +{ + return init_main_log(); +} diff --git a/test/validation/init/init_main_ok.c b/test/validation/init/init_main_ok.c new file mode 100644 index 000000000..285c7472f --- /dev/null +++ b/test/validation/init/init_main_ok.c @@ -0,0 +1,11 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "init.h" + +int main(void) +{ + return init_main_ok(); +} diff --git a/test/validation/init/odp_init.c b/test/validation/init/odp_init.c deleted file mode 100644 index 082e7c218..000000000 --- a/test/validation/init/odp_init.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2014, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <stdarg.h> -#include <odp.h> -#include <CUnit/Basic.h> -#include "odp_cunit_common.h" - -#define DEFAULT_MSG_POOL_SIZE (4 * 1024 * 1024) -#define DEFAULT_MSG_SIZE (8) - -/* overwrite common default so as not to perform odp init in main */ -int tests_global_init(void) -{ - return 0; -} - -/* overwrite common default so as not to perform odp term in main */ -int tests_global_term(void) -{ - return 0; -} - -static void test_odp_init_global(void) -{ - int status; - - status = odp_init_global(NULL, NULL); - CU_ASSERT_FATAL(status == 0); - - status = odp_term_global(); - CU_ASSERT(status == 0); -} - -CU_TestInfo test_odp_init[] = { - {"test_odp_init_global", test_odp_init_global}, - CU_TEST_INFO_NULL, -}; - -CU_SuiteInfo odp_testsuites[] = { - {"Init", NULL, NULL, NULL, NULL, test_odp_init}, - CU_SUITE_INFO_NULL, -}; diff --git a/test/validation/init/odp_init_abort.c b/test/validation/init/odp_init_abort.c deleted file mode 100644 index c83c8d391..000000000 --- a/test/validation/init/odp_init_abort.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <stdarg.h> -#include <stdlib.h> -#include <odp.h> -#include <CUnit/Basic.h> -#include "odp_cunit_common.h" - -/* overwrite common default so as not to perform odp init in main */ -int tests_global_init(void) -{ - return 0; -} - -/* overwrite common default so as not to perform odp term in main */ -int tests_global_term(void) -{ - return 0; -} - - -static void odp_init_abort(void) ODP_NORETURN; - -static void test_odp_init_global_replace_abort(void) -{ - int status; - struct odp_init_t init_data; - - memset(&init_data, 0, sizeof(init_data)); - init_data.abort_fn = &odp_init_abort; - - status = odp_init_global(&init_data, NULL); - CU_ASSERT_FATAL(status == 0); - - status = odp_term_global(); - CU_ASSERT(status == 0); -} - -CU_TestInfo test_odp_init[] = { - {"replace abort", test_odp_init_global_replace_abort}, - CU_TEST_INFO_NULL, -}; - -CU_SuiteInfo odp_testsuites[] = { - {"Init", NULL, NULL, NULL, NULL, test_odp_init}, - CU_SUITE_INFO_NULL, -}; - -void odp_init_abort(void) -{ - abort(); -} diff --git a/test/validation/init/odp_init_log.c b/test/validation/init/odp_init_log.c deleted file mode 100644 index fe1be71c4..000000000 --- a/test/validation/init/odp_init_log.c +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <stdarg.h> -#include <odp.h> -#include <CUnit/Basic.h> -#include "odp_cunit_common.h" - -int replacement_logging_used; - -/* overwrite common default so as not to perform odp init in main */ -int tests_global_init(void) -{ - return 0; -} - -/* overwrite common default so as not to perform odp term in main */ -int tests_global_term(void) -{ - return 0; -} - -ODP_PRINTF_FORMAT(2, 3) -static int odp_init_log(odp_log_level_e level, const char *fmt, ...); - -static void test_odp_init_global_replace_log(void) -{ - int status; - struct odp_init_t init_data; - - memset(&init_data, 0, sizeof(init_data)); - init_data.log_fn = &odp_init_log; - - replacement_logging_used = 0; - - status = odp_init_global(&init_data, NULL); - CU_ASSERT_FATAL(status == 0); - - CU_ASSERT_TRUE(replacement_logging_used); - - status = odp_term_global(); - CU_ASSERT(status == 0); -} - -CU_TestInfo test_odp_init[] = { - {"replace log", test_odp_init_global_replace_log}, - CU_TEST_INFO_NULL, -}; - -CU_SuiteInfo odp_testsuites[] = { - {"Init", NULL, NULL, NULL, NULL, test_odp_init}, - CU_SUITE_INFO_NULL, -}; - -int odp_init_log(odp_log_level_e level __attribute__((unused)), - const char *fmt, ...) -{ - va_list args; - int r; - - /* just set a flag to be sure the replacement fn was used */ - replacement_logging_used = 1; - - va_start(args, fmt); - r = vfprintf(stderr, fmt, args); - va_end(args); - - return r; -} diff --git a/test/validation/odp_classification.c b/test/validation/odp_classification.c deleted file mode 100644 index b501015cb..000000000 --- a/test/validation/odp_classification.c +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "odp_classification_testsuites.h" - -CU_SuiteInfo odp_testsuites[] = { - { .pName = "classification basic", - .pTests = classification_basic, - }, - { .pName = "classification tests", - .pTests = classification_tests, - .pInitFunc = classification_tests_init, - .pCleanupFunc = classification_tests_finalize, - }, - CU_SUITE_INFO_NULL, -}; diff --git a/test/validation/odp_cpumask.c b/test/validation/odp_cpumask.c deleted file mode 100644 index 1b1c104ad..000000000 --- a/test/validation/odp_cpumask.c +++ /dev/null @@ -1,479 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <odp.h> -#include "odp_cunit_common.h" - - -/* - * The following string are used to build cpu masks with - * odp_cpumask_from_str(). Both 0x prefixed and non prefixed - * hex values are supported by odp_cpumask_from_str() - */ -#define TEST_MASK_NO_CPU "0x0" -#define TEST_MASK_CPU_0 "0x1" -#define TEST_MASK_CPU_1 "0x2" -#define TEST_MASK_CPU_2 "0x4" -#define TEST_MASK_CPU_0_2 "0x5" -#define TEST_MASK_CPU_0_3 "0x9" -#define TEST_MASK_CPU_1_2 "0x6" -#define TEST_MASK_CPU_1_3 "0xA" -#define TEST_MASK_CPU_0_1_2 "0x7" -#define TEST_MASK_CPU_0_2_4_6 "0x55" -#define TEST_MASK_CPU_1_2_4_6 "0x56" - -#define TEST_MASK_CPU_0_NO_PREFIX "1" - -/* padding pattern used to check buffer overflow: */ -#define FILLING_PATTERN 0x55 - - - -/* - * returns the length of a string, excluding terminating NULL. - * As its C lib strlen equivalent. Just rewritten here to avoid C lib - * dependency in ODP tests (for platform independent / bare metal testing) - */ -static unsigned int stringlen(const char *str) -{ - unsigned int i = 0; - - while (str[i] != 0) - i++; - return i; -} - -/* - * builds a string containing a 0x prefixed hex number - * where a single bit (corresponding to cpu) is set. - * The string is null terminated. - * cpu_to_str(0) returns "0x1". - * cpu_to_str(10) returns "0x400". - * The buffer should be at least ceil(cpu/4)+3 bytes long, - * to accommodate with 4 cpus per nibble + "0x" prefix + null. - */ -#define CPUS_PER_NIBBLE 4 -static void cpu_to_str(char *buff, int cpu) -{ - const char *hex_nibble = "1248"; - int i = 0; - buff[i++] = '0'; - buff[i++] = 'x'; - buff[i++] = hex_nibble[cpu % CPUS_PER_NIBBLE]; - while (cpu > 3) { - buff[i++] = '0'; - cpu -= CPUS_PER_NIBBLE; - } - buff[i++] = 0; /* null */ -} - -/* - * returns the mask size to be tested... - * There is a bit of confusion right now about how to get this, - * so this is centralized here... in case of change... - */ -static unsigned int get_max_number_of_cpus_in_a_mask(void) -{ - return odp_cpu_count(); -} - - -static void test_odp_cpumask_to_from_str(void) -{ - odp_cpumask_t mask; - int32_t str_sz; - unsigned int buf_sz; /* buf size for the 2 following bufs */ - char *buf_in; - char *buf_out; - unsigned int cpu; - unsigned int i; - - /* makes sure the mask has room for at least 1 CPU...: */ - CU_ASSERT_FATAL(get_max_number_of_cpus_in_a_mask() > 0); - - /* allocate memory for the buffers containing the mask strings: - 1 char per nibble, i.e. 1 char per 4 cpus +extra for "0x" and null:*/ - buf_sz = (get_max_number_of_cpus_in_a_mask() >> 2) + 20; - buf_in = malloc(buf_sz); - buf_out = malloc(buf_sz); - CU_ASSERT_FATAL((buf_in != NULL) && (buf_out != NULL)); - - /* test 1 CPU at a time for all possible cpu positions in the mask */ - for (cpu = 0; cpu < get_max_number_of_cpus_in_a_mask(); cpu++) { - /* init buffer for overwrite check: */ - for (i = 0; i < buf_sz; i++) - buf_out[i] = FILLING_PATTERN; - - /* generate a hex string with that cpu set: */ - cpu_to_str(buf_in, cpu); - - /* generate mask: */ - odp_cpumask_from_str(&mask, buf_in); - - /* reverse cpu mask computation to get string back: */ - str_sz = odp_cpumask_to_str(&mask, buf_out, - stringlen(buf_in) + 1); - - /* check that returned size matches original (with NULL): */ - CU_ASSERT(str_sz == (int32_t)stringlen(buf_in) + 1); - - /* check that returned string matches original (with NULL): */ - CU_ASSERT_NSTRING_EQUAL(buf_out, buf_in, stringlen(buf_in) + 1); - - /* check that no extra buffer writes occurred: */ - CU_ASSERT(buf_out[stringlen(buf_in) + 2] == FILLING_PATTERN); - } - - /* re-init buffer for overwrite check: */ - for (i = 0; i < buf_sz; i++) - buf_out[i] = FILLING_PATTERN; - - /* check for buffer overflow when too small buffer given: */ - odp_cpumask_from_str(&mask, TEST_MASK_CPU_0); - str_sz = odp_cpumask_to_str(&mask, buf_out, stringlen(TEST_MASK_CPU_0)); - - CU_ASSERT(str_sz == -1); - - for (i = 0; i < buf_sz; i++) - CU_ASSERT(buf_out[i] == FILLING_PATTERN); - - /* check for handling of missing "0x" prefix: */ - odp_cpumask_from_str(&mask, TEST_MASK_CPU_0_NO_PREFIX); - - str_sz = odp_cpumask_to_str(&mask, buf_out, - stringlen(TEST_MASK_CPU_0) + 1); - - CU_ASSERT_NSTRING_EQUAL(buf_out, TEST_MASK_CPU_0, - stringlen(TEST_MASK_CPU_0) + 1); - - free(buf_out); - free(buf_in); -} - -static void test_odp_cpumask_equal(void) -{ - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_t mask3; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask3, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3)); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3)); - - if (get_max_number_of_cpus_in_a_mask() < 8) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2_4_6); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2_4_6); - odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2_4_6); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3)); -} - -static void test_odp_cpumask_zero(void) -{ - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_zero(&mask2); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); -} - -static void test_odp_cpumask_set(void) -{ - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_set(&mask1, 0); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_3); - odp_cpumask_set(&mask1, 3); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - - /* make sure that re-asserting a cpu has no impact: */ - odp_cpumask_set(&mask1, 3); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); -} - -static void test_odp_cpumask_clr(void) -{ - odp_cpumask_t mask1; - odp_cpumask_t mask2; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_clr(&mask1, 0); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_clr(&mask1, 2); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_clr(&mask1, 0); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - - /* make sure that re-clearing a cpu has no impact: */ - odp_cpumask_clr(&mask1, 0); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); -} - -static void test_odp_cpumask_isset(void) -{ - odp_cpumask_t mask1; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_isset(&mask1, 0)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 0)); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - CU_ASSERT(odp_cpumask_isset(&mask1, 0)); - CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 1)); - CU_ASSERT(odp_cpumask_isset(&mask1, 2)); - CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 3)); -} - -static void test_odp_cpumask_count(void) -{ - odp_cpumask_t mask1; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_count(&mask1) == 1); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_count(&mask1) == 0); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - CU_ASSERT(odp_cpumask_count(&mask1) == 2); -} - -static void test_odp_cpumask_and(void) -{ - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_t mask3; - odp_cpumask_t mask4; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0); - odp_cpumask_and(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_and(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_and(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_2); - odp_cpumask_and(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); -} - -static void test_odp_cpumask_or(void) -{ - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_t mask3; - odp_cpumask_t mask4; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0); - odp_cpumask_or(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0); - odp_cpumask_or(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_or(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0_1_2); - odp_cpumask_or(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); -} - -static void test_odp_cpumask_xor(void) -{ - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_t mask3; - odp_cpumask_t mask4; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_xor(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0); - odp_cpumask_xor(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_xor(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_1); - odp_cpumask_xor(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); -} - -static void test_odp_cpumask_copy(void) -{ - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_copy(&mask2, &mask1); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); -} - -static void test_odp_cpumask_first(void) -{ - odp_cpumask_t mask1; - - /* check when there is no first */ - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_first(&mask1) == -1); - - /* single CPU case: */ - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_first(&mask1) == 0); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3); - CU_ASSERT(odp_cpumask_first(&mask1) == 1); -} - -static void test_odp_cpumask_last(void) -{ - odp_cpumask_t mask1; - - /* check when there is no last: */ - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_last(&mask1) == -1); - - /* single CPU case: */ - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_last(&mask1) == 0); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3); - CU_ASSERT(odp_cpumask_last(&mask1) == 3); -} - -static void test_odp_cpumask_next(void) -{ - unsigned int i; - int expected[] = {1, 3, 3, -1}; - odp_cpumask_t mask1; - - /* case when the mask does not contain any CPU: */ - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_next(&mask1, -1) == -1); - - /* case when the mask just contain CPU 0: */ - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_next(&mask1, -1) == 0); - CU_ASSERT(odp_cpumask_next(&mask1, 0) == -1); - - if (get_max_number_of_cpus_in_a_mask() < 4) - return; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3); - - for (i = 0; i < sizeof(expected) / sizeof(int); i++) - CU_ASSERT(odp_cpumask_next(&mask1, i) == expected[i]); -} - -CU_TestInfo test_odp_cpumask[] = { - {"odp_cpumask_to/from_str()", test_odp_cpumask_to_from_str}, - {"odp_cpumask_equal()" , test_odp_cpumask_equal}, - {"odp_cpumask_zero()" , test_odp_cpumask_zero}, - {"odp_cpumask_set()" , test_odp_cpumask_set}, - {"odp_cpumask_clr()" , test_odp_cpumask_clr}, - {"odp_cpumask_isset()" , test_odp_cpumask_isset}, - {"odp_cpumask_count()" , test_odp_cpumask_count}, - {"odp_cpumask_and()" , test_odp_cpumask_and}, - {"odp_cpumask_or()" , test_odp_cpumask_or}, - {"odp_cpumask_xor()" , test_odp_cpumask_xor}, - {"odp_cpumask_copy()" , test_odp_cpumask_copy}, - {"odp_cpumask_first()" , test_odp_cpumask_first}, - {"odp_cpumask_last()" , test_odp_cpumask_last}, - {"odp_cpumask_next()" , test_odp_cpumask_next}, - CU_TEST_INFO_NULL, -}; - -CU_SuiteInfo odp_testsuites[] = { - {"Cpumask", NULL, NULL, NULL, NULL, test_odp_cpumask}, - CU_SUITE_INFO_NULL, -}; diff --git a/test/validation/odp_pktio_run b/test/validation/odp_pktio_run deleted file mode 100755 index b6a72c784..000000000 --- a/test/validation/odp_pktio_run +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2015, Linaro Limited -# All rights reserved. -# -# SPDX-License-Identifier: BSD-3-Clause -# - -# TEST_DIR is set by Makefile to point to the directory where binaries have been -# built (Makefile variable builddir) -# If TEST_DIR is not set it means we are not running with make, and in this case -# there are two situations: -# 1. user build ODP in the same dir as the source (most likely) -# here the user can simply call odp_pktio_run -# 2. user may have built ODP in a separate build dir (like bitbake usually does) -# here the user has to do something like $ODP/test/validation/odp_pktio_run -# -# In both situations the script assumes that the user is in the directory where -# odp_pktio exists. If that's not true, then the user has to specify the path -# to it and run: -# TEST_DIR=$builddir $ODP/test/validation/odp_pktio_run - -# directory where test binaries have been built -TEST_DIR="${TEST_DIR:-$PWD}" -# directory where test sources are, including scripts -TEST_SRC_DIR=$(dirname $0) - -PATH=$TEST_DIR:$PATH - -# exit codes expected by automake for skipped tests -TEST_SKIPPED=77 - -# Use installed pktio env or for make check take it from platform directory -if [ -f "./pktio_env" ]; then - . ./pktio_env -elif [ "$ODP_PLATFORM" = "" ]; then - echo "$0: error: ODP_PLATFORM must be defined" - # not skipped as this should never happen via "make check" - exit 1 -elif [ -f ${TEST_SRC_DIR}/../../platform/$ODP_PLATFORM/test/pktio_env ]; then - . ${TEST_SRC_DIR}/../../platform/$ODP_PLATFORM/test/pktio_env -else - echo "BUG: unable to find pktio_env!" - echo "pktio_env has to be in current directory or in platform/\$ODP_PLATFORM/test." - echo "ODP_PLATFORM=\"$ODP_PLATFORM\"" - exit 1 -fi - -run_test() -{ - local ret=0 - - # the linux-generic implementation uses environment variables to - # control which socket method is used, so try each combination to - # ensure decent coverage. - for distype in MMAP MMSG BASIC; do - unset ODP_PKTIO_DISABLE_SOCKET_${distype} - done - - for distype in SKIP MMAP MMSG; do - if [ "$disabletype" != "SKIP" ]; then - export ODP_PKTIO_DISABLE_SOCKET_${distype}=y - fi - odp_pktio - if [ $? -ne 0 ]; then - ret=1 - fi - done - - if [ $ret -ne 0 ]; then - echo "!!! FAILED !!!" - fi - - exit $ret -} - -run() -{ - if [ "$ODP_PLATFORM" != "linux-generic" -o "$(id -u)" != "0" ]; then - echo "pktio: using 'loop' device" - odp_pktio - exit $? - fi - - if [ "$ODP_PKTIO_IF0" = "" ]; then - # no interfaces specified on linux-generic, use defaults - setup_pktio_env clean - export ODP_PKTIO_IF0=$IF0 - export ODP_PKTIO_IF1=$IF1 - fi - - run_test -} - -case "$1" in - setup) setup_pktio_env ;; - cleanup) cleanup_pktio_env ;; - *) run ;; -esac diff --git a/test/validation/odp_thread.c b/test/validation/odp_thread.c deleted file mode 100644 index 84db1e708..000000000 --- a/test/validation/odp_thread.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <odp.h> -#include <odp_cunit_common.h> - -/* Helper macro for CU_TestInfo initialization */ -#define _CU_TEST_INFO(test_func) {#test_func, test_func} - -static void test_odp_cpu_id(void) -{ - (void) odp_cpu_id(); - CU_PASS(); -} - -static void test_odp_thread_id(void) -{ - (void) odp_thread_id(); - CU_PASS(); -} - -static void test_odp_thread_count(void) -{ - (void) odp_thread_count(); - CU_PASS(); -} - -CU_TestInfo test_odp_thread[] = { - _CU_TEST_INFO(test_odp_cpu_id), - _CU_TEST_INFO(test_odp_thread_id), - _CU_TEST_INFO(test_odp_thread_count), - CU_TEST_INFO_NULL, -}; - -CU_SuiteInfo odp_testsuites[] = { - {"thread", NULL, NULL, NULL, NULL, test_odp_thread}, - CU_SUITE_INFO_NULL, -}; diff --git a/test/validation/packet/.gitignore b/test/validation/packet/.gitignore new file mode 100644 index 000000000..c05530d2d --- /dev/null +++ b/test/validation/packet/.gitignore @@ -0,0 +1 @@ +packet_main diff --git a/test/validation/packet/Makefile.am b/test/validation/packet/Makefile.am new file mode 100644 index 000000000..7ba7a477b --- /dev/null +++ b/test/validation/packet/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libpacket.la +libpacket_la_SOURCES = packet.c + +bin_PROGRAMS = packet_main$(EXEEXT) +dist_packet_main_SOURCES = packet_main.c +packet_main_LDADD = libpacket.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_packet.c b/test/validation/packet/packet.c index a3634385d..329482a89 100644 --- a/test/validation/odp_packet.c +++ b/test/validation/packet/packet.c @@ -8,6 +8,7 @@ #include <odp.h> #include "odp_cunit_common.h" +#include "packet.h" /* Helper macro for CU_TestInfo initialization */ #define _CU_TEST_INFO(test_func) {#test_func, test_func} @@ -18,11 +19,12 @@ static odp_pool_t packet_pool; static const uint32_t packet_len = PACKET_BUF_LEN - - ODP_CONFIG_PACKET_HEADROOM - - ODP_CONFIG_PACKET_TAILROOM - PACKET_TAILROOM_RESERVE; -odp_packet_t test_packet; +static const uint32_t segmented_packet_len = PACKET_BUF_LEN * 5 - + PACKET_TAILROOM_RESERVE; + +odp_packet_t test_packet, segmented_test_packet; static struct udata_struct { uint64_t u64; @@ -34,7 +36,7 @@ static struct udata_struct { "abcdefg", }; -static int packet_testsuite_init(void) +static int packet_suite_init(void) { odp_pool_param_t params = { .pkt = { @@ -48,36 +50,44 @@ static int packet_testsuite_init(void) struct udata_struct *udat; uint32_t udat_size; - packet_pool = odp_pool_create("packet_pool", ODP_SHM_INVALID, ¶ms); + packet_pool = odp_pool_create("packet_pool", ¶ms); if (packet_pool == ODP_POOL_INVALID) return -1; test_packet = odp_packet_alloc(packet_pool, packet_len); + segmented_test_packet = odp_packet_alloc(packet_pool, + segmented_packet_len); - if (odp_packet_is_valid(test_packet) == 0) + if (odp_packet_is_valid(test_packet) == 0 || + odp_packet_is_valid(segmented_test_packet) == 0) return -1; udat = odp_packet_user_area(test_packet); udat_size = odp_packet_user_area_size(test_packet); - if (udat == NULL || udat_size != sizeof(struct udata_struct)) + if (!udat || udat_size != sizeof(struct udata_struct)) return -1; odp_pool_print(packet_pool); - printf("about to init udata at addr %p size %d\n", udat, udat_size); memcpy(udat, &test_packet_udata, sizeof(struct udata_struct)); - printf("udata set in test_packet\n"); + + udat = odp_packet_user_area(segmented_test_packet); + udat_size = odp_packet_user_area_size(segmented_test_packet); + if (udat == NULL || udat_size != sizeof(struct udata_struct)) + return -1; + memcpy(udat, &test_packet_udata, sizeof(struct udata_struct)); return 0; } -static int packet_testsuite_finalize(void) +static int packet_suite_term(void) { odp_packet_free(test_packet); + odp_packet_free(segmented_test_packet); if (odp_pool_destroy(packet_pool) != 0) return -1; return 0; } -static void packet_alloc_free(void) +static void packet_test_alloc_free(void) { odp_pool_t pool; odp_packet_t packet; @@ -90,7 +100,7 @@ static void packet_alloc_free(void) .type = ODP_POOL_PACKET, }; - pool = odp_pool_create("packet_pool_alloc", ODP_SHM_INVALID, ¶ms); + pool = odp_pool_create("packet_pool_alloc", ¶ms); /* Allocate the only buffer from the pool */ packet = odp_packet_alloc(pool, packet_len); @@ -116,7 +126,7 @@ static void packet_alloc_free(void) CU_ASSERT(odp_pool_destroy(pool) == 0); } -static void packet_alloc_segmented(void) +static void packet_test_alloc_segmented(void) { odp_packet_t pkt; const uint32_t len = ODP_CONFIG_PACKET_BUF_LEN_MAX - @@ -129,7 +139,7 @@ static void packet_alloc_segmented(void) odp_packet_free(pkt); } -static void packet_event_conversion(void) +static void packet_test_event_conversion(void) { odp_packet_t pkt = test_packet; odp_packet_t tmp_pkt; @@ -144,18 +154,19 @@ static void packet_event_conversion(void) /** @todo: Need an API to compare packets */ } -static void packet_basic_metadata(void) +static void packet_test_basic_metadata(void) { odp_packet_t pkt = test_packet; - CU_ASSERT(odp_packet_head(pkt) != NULL); - CU_ASSERT(odp_packet_data(pkt) != NULL); + + CU_ASSERT_PTR_NOT_NULL(odp_packet_head(pkt)); + CU_ASSERT_PTR_NOT_NULL(odp_packet_data(pkt)); CU_ASSERT(odp_packet_pool(pkt) != ODP_POOL_INVALID); /* Packet was allocated by application so shouldn't have valid pktio. */ CU_ASSERT(odp_packet_input(pkt) == ODP_PKTIO_INVALID); } -static void packet_length(void) +static void packet_test_length(void) { odp_packet_t pkt = test_packet; uint32_t buf_len, headroom, tailroom; @@ -174,13 +185,13 @@ static void packet_length(void) CU_ASSERT(buf_len >= packet_len + headroom + tailroom); } -static void packet_debug(void) +static void packet_test_debug(void) { CU_ASSERT(odp_packet_is_valid(test_packet) == 1); odp_packet_print(test_packet); } -static void packet_context(void) +static void packet_test_context(void) { odp_packet_t pkt = test_packet; char ptr_test_value = 2; @@ -193,7 +204,7 @@ static void packet_context(void) odp_packet_user_ptr_set(pkt, prev_ptr); udat = odp_packet_user_area(pkt); - CU_ASSERT(udat != NULL); + CU_ASSERT_PTR_NOT_NULL(udat); CU_ASSERT(odp_packet_user_area_size(pkt) == sizeof(struct udata_struct)); CU_ASSERT(memcmp(udat, &test_packet_udata, sizeof(struct udata_struct)) @@ -202,7 +213,7 @@ static void packet_context(void) odp_packet_reset(pkt, packet_len); } -static void packet_layer_offsets(void) +static void packet_test_layer_offsets(void) { odp_packet_t pkt = test_packet; uint8_t *l2_addr, *l3_addr, *l4_addr; @@ -227,7 +238,7 @@ static void packet_layer_offsets(void) CU_ASSERT(seg_len != 0); l4_addr = odp_packet_l4_ptr(pkt, &seg_len); CU_ASSERT(seg_len != 0); - CU_ASSERT(l2_addr != NULL); + CU_ASSERT_PTR_NOT_NULL(l2_addr); CU_ASSERT(l2_addr == l3_addr); CU_ASSERT(l2_addr == l4_addr); @@ -241,11 +252,11 @@ static void packet_layer_offsets(void) /* Addresses should not be the same */ l2_addr = odp_packet_l2_ptr(pkt, NULL); - CU_ASSERT(l2_addr != NULL); + CU_ASSERT_PTR_NOT_NULL(l2_addr); l3_addr = odp_packet_l3_ptr(pkt, NULL); - CU_ASSERT(l3_addr != NULL); + CU_ASSERT_PTR_NOT_NULL(l3_addr); l4_addr = odp_packet_l4_ptr(pkt, NULL); - CU_ASSERT(l4_addr != NULL); + CU_ASSERT_PTR_NOT_NULL(l4_addr); CU_ASSERT(l2_addr != l3_addr); CU_ASSERT(l2_addr != l4_addr); @@ -267,7 +278,7 @@ static void _verify_headroom_shift(odp_packet_t packet, else data = odp_packet_pull_head(packet, -shift); - CU_ASSERT(data != NULL); + CU_ASSERT_PTR_NOT_NULL(data); CU_ASSERT(odp_packet_headroom(packet) == room - shift); CU_ASSERT(odp_packet_seg_len(packet) == seg_data_len + shift); CU_ASSERT(odp_packet_len(packet) == pkt_data_len + shift); @@ -276,7 +287,7 @@ static void _verify_headroom_shift(odp_packet_t packet, CU_ASSERT(data == data_orig - shift); } -static void packet_headroom(void) +static void packet_test_headroom(void) { odp_packet_t pkt = test_packet; uint32_t room; @@ -319,6 +330,7 @@ static void _verify_tailroom_shift(odp_packet_t pkt, if (shift >= 0) { uint32_t l2_off, l3_off, l4_off; + l2_off = odp_packet_l2_offset(pkt); l3_off = odp_packet_l3_offset(pkt); l4_off = odp_packet_l4_offset(pkt); @@ -332,7 +344,7 @@ static void _verify_tailroom_shift(odp_packet_t pkt, tail = odp_packet_pull_tail(pkt, -shift); } - CU_ASSERT(tail != NULL); + CU_ASSERT_PTR_NOT_NULL(tail); CU_ASSERT(odp_packet_seg_data_len(pkt, seg) == seg_data_len + shift); CU_ASSERT(odp_packet_len(pkt) == pkt_data_len + shift); CU_ASSERT(odp_packet_tailroom(pkt) == room - shift); @@ -347,7 +359,7 @@ static void _verify_tailroom_shift(odp_packet_t pkt, } } -static void packet_tailroom(void) +static void packet_test_tailroom(void) { odp_packet_t pkt = test_packet; odp_packet_seg_t segment; @@ -374,12 +386,13 @@ static void packet_tailroom(void) _verify_tailroom_shift(pkt, 0); } -static void packet_segments(void) +static void packet_test_segments(void) { int num_segs, seg_index; uint32_t data_len, buf_len; odp_packet_seg_t seg; odp_packet_t pkt = test_packet; + odp_packet_t seg_pkt = segmented_test_packet; CU_ASSERT(odp_packet_is_valid(pkt) == 1); @@ -392,6 +405,8 @@ static void packet_segments(void) CU_ASSERT(num_segs == 1); } + CU_ASSERT(odp_packet_is_segmented(pkt) == 0); + CU_ASSERT(odp_packet_is_segmented(seg_pkt) == 1); seg = odp_packet_first_seg(pkt); buf_len = 0; @@ -409,8 +424,8 @@ static void packet_segments(void) CU_ASSERT(seg_buf_len > 0); CU_ASSERT(seg_data_len > 0); CU_ASSERT(seg_buf_len >= seg_data_len); - CU_ASSERT(seg_data != NULL); - CU_ASSERT(seg_buf_addr != NULL); + CU_ASSERT_PTR_NOT_NULL(seg_data); + CU_ASSERT_PTR_NOT_NULL(seg_buf_addr); CU_ASSERT(seg_data >= seg_buf_addr); CU_ASSERT(odp_packet_seg_to_u64(seg) != odp_packet_seg_to_u64(ODP_PACKET_SEG_INVALID)); @@ -429,9 +444,49 @@ static void packet_segments(void) if (seg_index == num_segs) CU_ASSERT(seg == ODP_PACKET_SEG_INVALID); + + seg = odp_packet_first_seg(seg_pkt); + num_segs = odp_packet_num_segs(seg_pkt); + + buf_len = 0; + data_len = 0; + seg_index = 0; + + while (seg_index < num_segs && seg != ODP_PACKET_SEG_INVALID) { + uint32_t seg_data_len, seg_buf_len; + void *seg_buf_addr, *seg_data; + + seg_buf_addr = odp_packet_seg_buf_addr(seg_pkt, seg); + seg_buf_len = odp_packet_seg_buf_len(seg_pkt, seg); + seg_data_len = odp_packet_seg_data_len(seg_pkt, seg); + seg_data = odp_packet_seg_data(seg_pkt, seg); + + CU_ASSERT(seg_buf_len > 0); + CU_ASSERT(seg_data_len > 0); + CU_ASSERT(seg_buf_len >= seg_data_len); + CU_ASSERT(seg_data != NULL); + CU_ASSERT(seg_buf_addr != NULL); + CU_ASSERT(seg_data >= seg_buf_addr); + CU_ASSERT(odp_packet_seg_to_u64(seg) != + odp_packet_seg_to_u64(ODP_PACKET_SEG_INVALID)); + + buf_len += seg_buf_len; + data_len += seg_data_len; + + /** @todo: touch memory in a segment */ + seg_index++; + seg = odp_packet_next_seg(seg_pkt, seg); + } + + CU_ASSERT(seg_index == num_segs); + CU_ASSERT(buf_len == odp_packet_buf_len(seg_pkt)); + CU_ASSERT(data_len == odp_packet_len(seg_pkt)); + + if (seg_index == num_segs) + CU_ASSERT(seg == ODP_PACKET_SEG_INVALID); } -static void packet_segment_last(void) +static void packet_test_segment_last(void) { odp_packet_t pkt = test_packet; odp_packet_seg_t seg; @@ -451,7 +506,7 @@ do { \ CU_ASSERT(odp_packet_has_##flag(packet) != 0); \ } while (0) -static void packet_in_flags(void) +static void packet_test_in_flags(void) { odp_packet_t pkt = test_packet; @@ -474,7 +529,7 @@ static void packet_in_flags(void) TEST_INFLAG(pkt, icmp); } -static void packet_error_flags(void) +static void packet_test_error_flags(void) { odp_packet_t pkt = test_packet; int err; @@ -496,7 +551,7 @@ struct packet_metadata { uint64_t usr_u64; }; -static void packet_add_rem_data(void) +static void packet_test_add_rem_data(void) { odp_packet_t pkt, new_pkt; uint32_t pkt_len, offset, add_len; @@ -527,7 +582,7 @@ static void packet_add_rem_data(void) /* Verify that user metadata has been preserved */ new_udat = odp_packet_user_area(new_pkt); - CU_ASSERT(new_udat != NULL); + CU_ASSERT_PTR_NOT_NULL(new_udat); CU_ASSERT(odp_packet_user_area_size(new_pkt) == sizeof(struct udata_struct)); CU_ASSERT(memcmp(new_udat, &test_packet_udata, @@ -546,7 +601,7 @@ static void packet_add_rem_data(void) /* Verify that user metadata has been preserved */ new_udat = odp_packet_user_area(new_pkt); - CU_ASSERT(new_udat != NULL); + CU_ASSERT_PTR_NOT_NULL(new_udat); CU_ASSERT(odp_packet_user_area_size(new_pkt) == sizeof(struct udata_struct)); CU_ASSERT(memcmp(new_udat, &test_packet_udata, @@ -558,7 +613,6 @@ free_packet: odp_packet_free(pkt); } - #define COMPARE_INFLAG(p1, p2, flag) \ CU_ASSERT(odp_packet_has_##flag(p1) == odp_packet_has_##flag(p2)) @@ -596,8 +650,8 @@ static void _packet_compare_data(odp_packet_t pkt1, odp_packet_t pkt2) void *pkt1map = odp_packet_offset(pkt1, offset, &seglen1, NULL); void *pkt2map = odp_packet_offset(pkt2, offset, &seglen2, NULL); - CU_ASSERT_FATAL(pkt1map != NULL); - CU_ASSERT_FATAL(pkt2map != NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(pkt1map); + CU_ASSERT_PTR_NOT_NULL_FATAL(pkt2map); cmplen = seglen1 < seglen2 ? seglen1 : seglen2; CU_ASSERT(!memcmp(pkt1map, pkt2map, cmplen)); @@ -606,7 +660,7 @@ static void _packet_compare_data(odp_packet_t pkt1, odp_packet_t pkt2) } } -static void packet_copy(void) +static void packet_test_copy(void) { odp_packet_t pkt = test_packet; odp_packet_t pkt_copy; @@ -625,7 +679,7 @@ static void packet_copy(void) odp_packet_free(pkt_copy); } -static void packet_copydata(void) +static void packet_test_copydata(void) { odp_packet_t pkt = test_packet; uint32_t pkt_len = odp_packet_len(pkt); @@ -636,7 +690,7 @@ static void packet_copydata(void) CU_ASSERT_FATAL(pkt_len > 0); data_buf = malloc(pkt_len); - CU_ASSERT_FATAL(data_buf != NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(data_buf); for (i = 0; i < pkt_len; i++) data_buf[i] = (uint8_t)i; @@ -656,7 +710,7 @@ static void packet_copydata(void) free(data_buf); } -static void packet_offset(void) +static void packet_test_offset(void) { odp_packet_t pkt = test_packet; uint32_t seg_len, full_seg_len; @@ -669,7 +723,7 @@ static void packet_offset(void) CU_ASSERT(seg_len > 1); CU_ASSERT(seg_len == odp_packet_seg_len(pkt)); CU_ASSERT(seg_len == odp_packet_seg_data_len(pkt, seg)); - CU_ASSERT(ptr != NULL); + CU_ASSERT_PTR_NOT_NULL(ptr); CU_ASSERT(ptr == odp_packet_data(pkt)); CU_ASSERT(ptr == odp_packet_seg_data(pkt, seg)); @@ -679,7 +733,7 @@ static void packet_offset(void) offset = 1; ptr = odp_packet_offset(pkt, offset, &seg_len, NULL); - CU_ASSERT(ptr != NULL); + CU_ASSERT_PTR_NOT_NULL(ptr); CU_ASSERT(ptr == start_ptr + offset); CU_ASSERT(seg_len == full_seg_len - offset); @@ -687,48 +741,53 @@ static void packet_offset(void) offset = full_seg_len - 1; ptr = odp_packet_offset(pkt, offset, &seg_len, NULL); - CU_ASSERT(ptr != NULL); + CU_ASSERT_PTR_NOT_NULL(ptr); CU_ASSERT(ptr == start_ptr + offset); CU_ASSERT(seg_len == full_seg_len - offset); /* Query the last byte in a packet */ offset = odp_packet_len(pkt) - 1; ptr = odp_packet_offset(pkt, offset, &seg_len, NULL); - CU_ASSERT(ptr != NULL); + CU_ASSERT_PTR_NOT_NULL(ptr); CU_ASSERT(seg_len == 1); /* Pass NULL to [out] arguments */ ptr = odp_packet_offset(pkt, 0, NULL, NULL); - CU_ASSERT(ptr != NULL); + CU_ASSERT_PTR_NOT_NULL(ptr); } -CU_TestInfo packet_tests[] = { - _CU_TEST_INFO(packet_alloc_free), - _CU_TEST_INFO(packet_alloc_segmented), - _CU_TEST_INFO(packet_basic_metadata), - _CU_TEST_INFO(packet_debug), - _CU_TEST_INFO(packet_length), - _CU_TEST_INFO(packet_headroom), - _CU_TEST_INFO(packet_tailroom), - _CU_TEST_INFO(packet_context), - _CU_TEST_INFO(packet_event_conversion), - _CU_TEST_INFO(packet_layer_offsets), - _CU_TEST_INFO(packet_segments), - _CU_TEST_INFO(packet_segment_last), - _CU_TEST_INFO(packet_in_flags), - _CU_TEST_INFO(packet_error_flags), - _CU_TEST_INFO(packet_add_rem_data), - _CU_TEST_INFO(packet_copy), - _CU_TEST_INFO(packet_copydata), - _CU_TEST_INFO(packet_offset), +static CU_TestInfo packet_suite[] = { + _CU_TEST_INFO(packet_test_alloc_free), + _CU_TEST_INFO(packet_test_alloc_segmented), + _CU_TEST_INFO(packet_test_basic_metadata), + _CU_TEST_INFO(packet_test_debug), + _CU_TEST_INFO(packet_test_length), + _CU_TEST_INFO(packet_test_headroom), + _CU_TEST_INFO(packet_test_tailroom), + _CU_TEST_INFO(packet_test_context), + _CU_TEST_INFO(packet_test_event_conversion), + _CU_TEST_INFO(packet_test_layer_offsets), + _CU_TEST_INFO(packet_test_segments), + _CU_TEST_INFO(packet_test_segment_last), + _CU_TEST_INFO(packet_test_in_flags), + _CU_TEST_INFO(packet_test_error_flags), + _CU_TEST_INFO(packet_test_add_rem_data), + _CU_TEST_INFO(packet_test_copy), + _CU_TEST_INFO(packet_test_copydata), + _CU_TEST_INFO(packet_test_offset), CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { +static CU_SuiteInfo packet_suites[] = { { .pName = "packet tests", - .pTests = packet_tests, - .pInitFunc = packet_testsuite_init, - .pCleanupFunc = packet_testsuite_finalize, + .pTests = packet_suite, + .pInitFunc = packet_suite_init, + .pCleanupFunc = packet_suite_term, }, CU_SUITE_INFO_NULL, }; + +int packet_main(void) +{ + return odp_cunit_run(packet_suites); +} diff --git a/test/validation/packet/packet.h b/test/validation/packet/packet.h new file mode 100644 index 000000000..7e210cb7c --- /dev/null +++ b/test/validation/packet/packet.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_PACKET_H_ +#define _ODP_TEST_PACKET_H_ + +int packet_main(void); + +#endif diff --git a/test/validation/ver_abt_log_dbg/odp_errno.h b/test/validation/packet/packet_main.c index 80507fa36..90972fddb 100644 --- a/test/validation/ver_abt_log_dbg/odp_errno.h +++ b/test/validation/packet/packet_main.c @@ -4,6 +4,9 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "odp_cunit_common.h" +#include "packet.h" -extern CU_TestInfo test_odp_errno[]; +int main(void) +{ + return packet_main(); +} diff --git a/test/validation/pktio/.gitignore b/test/validation/pktio/.gitignore new file mode 100644 index 000000000..1a5dd46e4 --- /dev/null +++ b/test/validation/pktio/.gitignore @@ -0,0 +1 @@ +pktio_main diff --git a/test/validation/pktio/Makefile.am b/test/validation/pktio/Makefile.am new file mode 100644 index 000000000..86127a18e --- /dev/null +++ b/test/validation/pktio/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libpktio.la +libpktio_la_SOURCES = pktio.c + +bin_PROGRAMS = pktio_main$(EXEEXT) +dist_pktio_main_SOURCES = pktio_main.c +pktio_main_LDADD = libpktio.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_pktio.c b/test/validation/pktio/pktio.c index e1025d6d3..bfdf52570 100644 --- a/test/validation/odp_pktio.c +++ b/test/validation/pktio/pktio.c @@ -9,12 +9,12 @@ #include <odp/helper/eth.h> #include <odp/helper/ip.h> #include <odp/helper/udp.h> -#include <odp_internal.h> #include <stdlib.h> +#include "pktio.h" #define PKT_BUF_NUM 32 -#define PKT_BUF_SIZE (9*1024) +#define PKT_BUF_SIZE (9 * 1024) #define PKT_LEN_NORMAL 64 #define PKT_LEN_JUMBO (PKT_BUF_SIZE - ODPH_ETHHDR_LEN - \ ODPH_IPV4HDR_LEN - ODPH_UDPHDR_LEN) @@ -154,8 +154,8 @@ static uint32_t pktio_init_packet(odp_packet_t pkt) /* IP */ odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN); ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); - ip->dst_addr = odp_cpu_to_be_32(0); - ip->src_addr = odp_cpu_to_be_32(0); + ip->dst_addr = odp_cpu_to_be_32(0x0a000064); + ip->src_addr = odp_cpu_to_be_32(0x0a000001); ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN; ip->tot_len = odp_cpu_to_be_16(pkt_len - ODPH_ETHHDR_LEN); ip->ttl = 128; @@ -168,8 +168,8 @@ static uint32_t pktio_init_packet(odp_packet_t pkt) /* UDP */ odp_packet_l4_offset_set(pkt, ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); udp = (odph_udphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); - udp->src_port = odp_cpu_to_be_16(0); - udp->dst_port = odp_cpu_to_be_16(0); + udp->src_port = odp_cpu_to_be_16(12049); + udp->dst_port = odp_cpu_to_be_16(12050); udp->length = odp_cpu_to_be_16(pkt_len - ODPH_ETHHDR_LEN - ODPH_IPV4HDR_LEN); udp->chksum = 0; @@ -213,8 +213,7 @@ static int default_pool_create(void) params.pkt.num = PKT_BUF_NUM; params.type = ODP_POOL_PACKET; - default_pkt_pool = odp_pool_create("pkt_pool_default", - ODP_SHM_NULL, ¶ms); + default_pkt_pool = odp_pool_create("pkt_pool_default", ¶ms); if (default_pkt_pool == ODP_POOL_INVALID) return -1; @@ -249,7 +248,8 @@ static int create_inq(odp_pktio_t pktio, odp_queue_type_t qtype) odp_pktio_to_u64(pktio)); inq_def = odp_queue_lookup(inq_name); if (inq_def == ODP_QUEUE_INVALID) - inq_def = odp_queue_create(inq_name, + inq_def = odp_queue_create( + inq_name, ODP_QUEUE_TYPE_PKTIN, qtype == ODP_QUEUE_TYPE_POLL ? NULL : &qparam); @@ -381,12 +381,16 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b, ret = odp_queue_enq(pktio_a->outq, tx_ev[0]); if (ret != 0) { CU_FAIL("failed to enqueue test packet"); + odp_packet_free(tx_pkt[0]); return; } } else { ret = odp_queue_enq_multi(pktio_a->outq, tx_ev, num_pkts); if (ret != num_pkts) { CU_FAIL("failed to enqueue test packets"); + i = ret < 0 ? 0 : ret; + for ( ; i < num_pkts; i++) + odp_packet_free(tx_pkt[i]); return; } } @@ -405,7 +409,7 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b, CU_ASSERT(i == num_pkts); } -static void pktio_test_txrx(odp_queue_type_t q_type, int num_pkts) +static void test_txrx(odp_queue_type_t q_type, int num_pkts) { int ret, i, if_b; pktio_info_t pktios[MAX_NUM_IFACES]; @@ -441,34 +445,34 @@ static void pktio_test_txrx(odp_queue_type_t q_type, int num_pkts) } } -static void test_odp_pktio_poll_queue(void) +static void pktio_test_poll_queue(void) { - pktio_test_txrx(ODP_QUEUE_TYPE_POLL, 1); + test_txrx(ODP_QUEUE_TYPE_POLL, 1); } -static void test_odp_pktio_poll_multi(void) +static void pktio_test_poll_multi(void) { - pktio_test_txrx(ODP_QUEUE_TYPE_POLL, 4); + test_txrx(ODP_QUEUE_TYPE_POLL, 4); } -static void test_odp_pktio_sched_queue(void) +static void pktio_test_sched_queue(void) { - pktio_test_txrx(ODP_QUEUE_TYPE_SCHED, 1); + test_txrx(ODP_QUEUE_TYPE_SCHED, 1); } -static void test_odp_pktio_sched_multi(void) +static void pktio_test_sched_multi(void) { - pktio_test_txrx(ODP_QUEUE_TYPE_SCHED, 4); + test_txrx(ODP_QUEUE_TYPE_SCHED, 4); } -static void test_odp_pktio_jumbo(void) +static void pktio_test_jumbo(void) { packet_len = PKT_LEN_JUMBO; - test_odp_pktio_sched_multi(); + pktio_test_sched_multi(); packet_len = PKT_LEN_NORMAL; } -static void test_odp_pktio_mtu(void) +static void pktio_test_mtu(void) { int ret; int mtu; @@ -481,11 +485,9 @@ static void test_odp_pktio_mtu(void) ret = odp_pktio_close(pktio); CU_ASSERT(ret == 0); - - return; } -static void test_odp_pktio_promisc(void) +static void pktio_test_promisc(void) { int ret; odp_pktio_t pktio = create_pktio(iface_name[0], 0); @@ -506,11 +508,9 @@ static void test_odp_pktio_promisc(void) ret = odp_pktio_close(pktio); CU_ASSERT(ret == 0); - - return; } -static void test_odp_pktio_mac(void) +static void pktio_test_mac(void) { unsigned char mac_addr[ODPH_ETHADDR_LEN]; int mac_len; @@ -532,11 +532,9 @@ static void test_odp_pktio_mac(void) ret = odp_pktio_close(pktio); CU_ASSERT(0 == ret); - - return; } -static void test_odp_pktio_inq_remdef(void) +static void pktio_test_inq_remdef(void) { odp_pktio_t pktio = create_pktio(iface_name[0], 0); odp_queue_t inq; @@ -545,7 +543,8 @@ static void test_odp_pktio_inq_remdef(void) CU_ASSERT(pktio != ODP_PKTIO_INVALID); CU_ASSERT(create_inq(pktio, ODP_QUEUE_TYPE_POLL) == 0); - CU_ASSERT((inq = odp_pktio_inq_getdef(pktio)) != ODP_QUEUE_INVALID); + inq = odp_pktio_inq_getdef(pktio); + CU_ASSERT(inq != ODP_QUEUE_INVALID); CU_ASSERT(odp_pktio_inq_remdef(pktio) == 0); for (i = 0; i < 100; i++) { @@ -560,7 +559,7 @@ static void test_odp_pktio_inq_remdef(void) CU_ASSERT(odp_pktio_close(pktio) == 0); } -static void test_odp_pktio_open(void) +static void pktio_test_open(void) { odp_pktio_t pktio; int i; @@ -576,7 +575,7 @@ static void test_odp_pktio_open(void) CU_ASSERT(pktio == ODP_PKTIO_INVALID); } -static void test_odp_pktio_lookup(void) +static void pktio_test_lookup(void) { odp_pktio_t pktio, pktio_inval; @@ -594,7 +593,7 @@ static void test_odp_pktio_lookup(void) CU_ASSERT(odp_pktio_lookup(iface_name[0]) == ODP_PKTIO_INVALID); } -static void test_odp_pktio_inq(void) +static void pktio_test_inq(void) { odp_pktio_t pktio; @@ -619,7 +618,7 @@ static int create_pool(const char *iface, int num) snprintf(pool_name, sizeof(pool_name), "pkt_pool_%s", iface); - pool[num] = odp_pool_create(pool_name, ODP_SHM_NULL, ¶ms); + pool[num] = odp_pool_create(pool_name, ¶ms); if (ODP_POOL_INVALID == pool[num]) { CU_FAIL("unable to create pool"); return -1; @@ -628,7 +627,7 @@ static int create_pool(const char *iface, int num) return 0; } -static int init_pktio_suite(void) +static int pktio_suite_init(void) { odp_atomic_init_u32(&ip_seq, 0); iface_name[0] = getenv("ODP_PKTIO_IF0"); @@ -660,7 +659,7 @@ static int init_pktio_suite(void) return 0; } -static int term_pktio_suite(void) +static int pktio_suite_term(void) { char pool_name[ODP_POOL_NAME_LEN]; odp_pool_t pool; @@ -689,24 +688,29 @@ static int term_pktio_suite(void) return ret; } -CU_TestInfo pktio_tests[] = { - {"pktio open", test_odp_pktio_open}, - {"pktio lookup", test_odp_pktio_lookup}, - {"pktio inq", test_odp_pktio_inq}, - {"pktio poll queues", test_odp_pktio_poll_queue}, - {"pktio poll multi", test_odp_pktio_poll_multi}, - {"pktio sched queues", test_odp_pktio_sched_queue}, - {"pktio sched multi", test_odp_pktio_sched_multi}, - {"pktio jumbo frames", test_odp_pktio_jumbo}, - {"pktio mtu", test_odp_pktio_mtu}, - {"pktio promisc mode", test_odp_pktio_promisc}, - {"pktio mac", test_odp_pktio_mac}, - {"pktio inq_remdef", test_odp_pktio_inq_remdef}, +static CU_TestInfo pktio_suite[] = { + {"pktio open", pktio_test_open}, + {"pktio lookup", pktio_test_lookup}, + {"pktio inq", pktio_test_inq}, + {"pktio poll queues", pktio_test_poll_queue}, + {"pktio poll multi", pktio_test_poll_multi}, + {"pktio sched queues", pktio_test_sched_queue}, + {"pktio sched multi", pktio_test_sched_multi}, + {"pktio jumbo frames", pktio_test_jumbo}, + {"pktio mtu", pktio_test_mtu}, + {"pktio promisc mode", pktio_test_promisc}, + {"pktio mac", pktio_test_mac}, + {"pktio inq_remdef", pktio_test_inq_remdef}, CU_TEST_INFO_NULL }; -CU_SuiteInfo odp_testsuites[] = { +static CU_SuiteInfo pktio_suites[] = { {"Packet I/O", - init_pktio_suite, term_pktio_suite, NULL, NULL, pktio_tests}, + pktio_suite_init, pktio_suite_term, NULL, NULL, pktio_suite}, CU_SUITE_INFO_NULL }; + +int pktio_main(void) +{ + return odp_cunit_run(pktio_suites); +} diff --git a/test/validation/pktio/pktio.h b/test/validation/pktio/pktio.h new file mode 100644 index 000000000..ccf52680c --- /dev/null +++ b/test/validation/pktio/pktio.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_PKTIO_H_ +#define _ODP_TEST_PKTIO_H_ + +int pktio_main(void); + +#endif diff --git a/test/validation/pktio/pktio_main.c b/test/validation/pktio/pktio_main.c new file mode 100644 index 000000000..dca041c77 --- /dev/null +++ b/test/validation/pktio/pktio_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pktio.h" + +int main(void) +{ + return pktio_main(); +} diff --git a/test/validation/pool/.gitignore b/test/validation/pool/.gitignore new file mode 100644 index 000000000..fc91b28d6 --- /dev/null +++ b/test/validation/pool/.gitignore @@ -0,0 +1 @@ +pool_main diff --git a/test/validation/pool/Makefile.am b/test/validation/pool/Makefile.am new file mode 100644 index 000000000..97f3eb450 --- /dev/null +++ b/test/validation/pool/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libpool.la +libpool_la_SOURCES = pool.c + +bin_PROGRAMS = pool_main$(EXEEXT) +dist_pool_main_SOURCES = pool_main.c +pool_main_LDADD = libpool.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_pool.c b/test/validation/pool/pool.c index 1a518a038..a888b6846 100644 --- a/test/validation/odp_pool.c +++ b/test/validation/pool/pool.c @@ -6,6 +6,7 @@ #include <odp.h> #include "odp_cunit_common.h" +#include "pool.h" static int pool_name_number = 1; static const int default_buffer_size = 1500; @@ -19,14 +20,14 @@ static void pool_create_destroy(odp_pool_param_t *params) snprintf(pool_name, sizeof(pool_name), "test_pool-%d", pool_name_number++); - pool = odp_pool_create(pool_name, ODP_SHM_INVALID, params); + pool = odp_pool_create(pool_name, params); CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); CU_ASSERT(odp_pool_to_u64(pool) != odp_pool_to_u64(ODP_POOL_INVALID)); CU_ASSERT(odp_pool_destroy(pool) == 0); } -static void pool_create_destroy_buffer(void) +static void pool_test_create_destroy_buffer(void) { odp_pool_param_t params = { .buf = { @@ -40,7 +41,7 @@ static void pool_create_destroy_buffer(void) pool_create_destroy(¶ms); } -static void pool_create_destroy_packet(void) +static void pool_test_create_destroy_packet(void) { odp_pool_param_t params = { .pkt = { @@ -54,7 +55,7 @@ static void pool_create_destroy_packet(void) pool_create_destroy(¶ms); } -static void pool_create_destroy_timeout(void) +static void pool_test_create_destroy_timeout(void) { odp_pool_param_t params = { .tmo = { @@ -66,33 +67,7 @@ static void pool_create_destroy_timeout(void) pool_create_destroy(¶ms); } -static void pool_create_destroy_buffer_shm(void) -{ - odp_pool_t pool; - odp_shm_t test_shm; - odp_pool_param_t params = { - .buf = { - .size = 1500, - .align = ODP_CACHE_LINE_SIZE, - .num = 10, - }, - .type = ODP_POOL_BUFFER, - }; - - test_shm = odp_shm_reserve("test_shm", - params.buf.size * params.buf.num * 2, - ODP_CACHE_LINE_SIZE, - 0); - CU_ASSERT_FATAL(test_shm != ODP_SHM_INVALID); - - pool = odp_pool_create("test_shm_pool", test_shm, ¶ms); - CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); - - CU_ASSERT(odp_pool_destroy(pool) == 0); - CU_ASSERT(odp_shm_free(test_shm) == 0); -} - -static void pool_lookup_info_print(void) +static void pool_test_lookup_info_print(void) { odp_pool_t pool; const char pool_name[] = "pool_for_lookup_test"; @@ -106,7 +81,7 @@ static void pool_lookup_info_print(void) .type = ODP_POOL_BUFFER, }; - pool = odp_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); + pool = odp_pool_create(pool_name, ¶ms); CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); pool = odp_pool_lookup(pool_name); @@ -114,7 +89,6 @@ static void pool_lookup_info_print(void) CU_ASSERT_FATAL(odp_pool_info(pool, &info) == 0); CU_ASSERT(strncmp(pool_name, info.name, sizeof(pool_name)) == 0); - CU_ASSERT(info.shm == ODP_SHM_INVALID); CU_ASSERT(params.buf.size <= info.params.buf.size); CU_ASSERT(params.buf.align <= info.params.buf.align); CU_ASSERT(params.buf.num <= info.params.buf.num); @@ -127,18 +101,22 @@ static void pool_lookup_info_print(void) #define _CU_TEST_INFO(test_func) {#test_func, test_func} -CU_TestInfo pool_tests[] = { - _CU_TEST_INFO(pool_create_destroy_buffer), - _CU_TEST_INFO(pool_create_destroy_packet), - _CU_TEST_INFO(pool_create_destroy_timeout), - _CU_TEST_INFO(pool_create_destroy_buffer_shm), - _CU_TEST_INFO(pool_lookup_info_print), +static CU_TestInfo pool_suite[] = { + _CU_TEST_INFO(pool_test_create_destroy_buffer), + _CU_TEST_INFO(pool_test_create_destroy_packet), + _CU_TEST_INFO(pool_test_create_destroy_timeout), + _CU_TEST_INFO(pool_test_lookup_info_print), CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { +static CU_SuiteInfo pool_suites[] = { { .pName = "Pool tests", - .pTests = pool_tests, + .pTests = pool_suite, }, CU_SUITE_INFO_NULL, }; + +int pool_main(void) +{ + return odp_cunit_run(pool_suites); +} diff --git a/test/validation/pool/pool.h b/test/validation/pool/pool.h new file mode 100644 index 000000000..8c73d9b5e --- /dev/null +++ b/test/validation/pool/pool.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_POOL_H_ +#define _ODP_TEST_POOL_H_ + +int pool_main(void); + +#endif diff --git a/test/validation/ver_abt_log_dbg/odp_system.h b/test/validation/pool/pool_main.c index ce99bedbd..5ef739ea6 100644 --- a/test/validation/ver_abt_log_dbg/odp_system.h +++ b/test/validation/pool/pool_main.c @@ -4,6 +4,9 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "odp_cunit_common.h" +#include "pool.h" -extern CU_TestInfo test_odp_system[]; +int main(void) +{ + return pool_main(); +} diff --git a/test/validation/queue/.gitignore b/test/validation/queue/.gitignore new file mode 100644 index 000000000..469506a13 --- /dev/null +++ b/test/validation/queue/.gitignore @@ -0,0 +1 @@ +queue_main diff --git a/test/validation/queue/Makefile.am b/test/validation/queue/Makefile.am new file mode 100644 index 000000000..adeefc7ee --- /dev/null +++ b/test/validation/queue/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libqueue.la +libqueue_la_SOURCES = queue.c + +bin_PROGRAMS = queue_main$(EXEEXT) +dist_queue_main_SOURCES = queue_main.c +queue_main_LDADD = libqueue.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_queue.c b/test/validation/queue/queue.c index 01a704c60..ef7c8f24f 100644 --- a/test/validation/odp_queue.c +++ b/test/validation/queue/queue.c @@ -6,15 +6,16 @@ #include <odp.h> #include <odp_cunit_common.h> +#include "queue.h" #define MAX_BUFFER_QUEUE (8) -#define MSG_POOL_SIZE (4*1024*1024) +#define MSG_POOL_SIZE (4 * 1024 * 1024) #define CONFIG_MAX_ITERATION (100) static int queue_contest = 0xff; static odp_pool_t pool; -static int init_queue_suite(void) +static int queue_suite_init(void) { odp_pool_param_t params; @@ -23,7 +24,7 @@ static int init_queue_suite(void) params.buf.num = 1024 * 10; params.type = ODP_POOL_BUFFER; - pool = odp_pool_create("msg_pool", ODP_SHM_NULL, ¶ms); + pool = odp_pool_create("msg_pool", ¶ms); if (ODP_POOL_INVALID == pool) { printf("Pool create failed.\n"); @@ -32,12 +33,12 @@ static int init_queue_suite(void) return 0; } -static int init_queue_finalize(void) +static int queue_suite_term(void) { return odp_pool_destroy(pool); } -static void test_odp_queue_sunnyday(void) +static void queue_test_sunnydays(void) { odp_queue_t queue_creat_id, queue_id; odp_event_t enev[MAX_BUFFER_QUEUE]; @@ -71,9 +72,12 @@ static void test_odp_queue_sunnyday(void) CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID); ev = odp_buffer_to_event(buf); - odp_queue_enq(queue_id, ev); - CU_ASSERT_EQUAL(ev, odp_queue_deq(queue_id)); - odp_buffer_free(buf); + if (!(CU_ASSERT(odp_queue_enq(queue_id, ev) == 0))) { + odp_buffer_free(buf); + } else { + CU_ASSERT_EQUAL(ev, odp_queue_deq(queue_id)); + odp_buffer_free(buf); + } for (i = 0; i < MAX_BUFFER_QUEUE; i++) { odp_buffer_t buf = odp_buffer_alloc(msg_pool); @@ -87,6 +91,10 @@ static void test_odp_queue_sunnyday(void) */ ret = odp_queue_enq_multi(queue_id, enev, MAX_BUFFER_QUEUE); CU_ASSERT(MAX_BUFFER_QUEUE == ret); + i = ret < 0 ? 0 : ret; + for ( ; i < MAX_BUFFER_QUEUE; i++) + odp_event_free(enev[i]); + pev_tmp = deev; do { deq_ret = odp_queue_deq_multi(queue_id, pev_tmp, @@ -104,16 +112,20 @@ static void test_odp_queue_sunnyday(void) } CU_ASSERT(odp_queue_destroy(queue_id) == 0); - return; } -CU_TestInfo test_odp_queue[] = { - {"queue sunnyday", test_odp_queue_sunnyday}, +static CU_TestInfo queue_suite[] = { + {"queue sunnyday", queue_test_sunnydays}, CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { - {"Queue", init_queue_suite, init_queue_finalize, - NULL, NULL, test_odp_queue}, +static CU_SuiteInfo queue_suites[] = { + {"Queue", queue_suite_init, queue_suite_term, + NULL, NULL, queue_suite}, CU_SUITE_INFO_NULL, }; + +int queue_main(void) +{ + return odp_cunit_run(queue_suites); +} diff --git a/test/validation/queue/queue.h b/test/validation/queue/queue.h new file mode 100644 index 000000000..8302912de --- /dev/null +++ b/test/validation/queue/queue.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_QUEUE_H_ +#define _ODP_TEST_QUEUE_H_ + +int queue_main(void); + +#endif diff --git a/test/validation/queue/queue_main.c b/test/validation/queue/queue_main.c new file mode 100644 index 000000000..326f13183 --- /dev/null +++ b/test/validation/queue/queue_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "queue.h" + +int main(void) +{ + return queue_main(); +} diff --git a/test/validation/random/.gitignore b/test/validation/random/.gitignore new file mode 100644 index 000000000..2c88ec0b8 --- /dev/null +++ b/test/validation/random/.gitignore @@ -0,0 +1 @@ +random_main diff --git a/test/validation/random/Makefile.am b/test/validation/random/Makefile.am new file mode 100644 index 000000000..85056d59f --- /dev/null +++ b/test/validation/random/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = librandom.la +librandom_la_SOURCES = random.c + +bin_PROGRAMS = random_main$(EXEEXT) +dist_random_main_SOURCES = random_main.c +random_main_LDADD = librandom.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_random.c b/test/validation/random/random.c index ebc9705e7..a42523faf 100644 --- a/test/validation/odp_random.c +++ b/test/validation/random/random.c @@ -6,11 +6,12 @@ #include <odp.h> #include <odp_cunit_common.h> +#include "random.h" /* Helper macro for CU_TestInfo initialization */ #define _CU_TEST_INFO(test_func) {#test_func, test_func} -static void random_get_size(void) +static void random_test_get_size(void) { int32_t ret; uint8_t buf[32]; @@ -19,12 +20,17 @@ static void random_get_size(void) CU_ASSERT(ret == sizeof(buf)); } -CU_TestInfo test_odp_random[] = { - _CU_TEST_INFO(random_get_size), +static CU_TestInfo random_suite[] = { + _CU_TEST_INFO(random_test_get_size), CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { - {"Random", NULL, NULL, NULL, NULL, test_odp_random}, +static CU_SuiteInfo random_suites[] = { + {"Random", NULL, NULL, NULL, NULL, random_suite}, CU_SUITE_INFO_NULL, }; + +int random_main(void) +{ + return odp_cunit_run(random_suites); +} diff --git a/test/validation/random/random.h b/test/validation/random/random.h new file mode 100644 index 000000000..34e375c70 --- /dev/null +++ b/test/validation/random/random.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_RANDOM_H_ +#define _ODP_TEST_RANDOM_H_ + +int random_main(void); + +#endif diff --git a/test/validation/random/random_main.c b/test/validation/random/random_main.c new file mode 100644 index 000000000..36b32f73d --- /dev/null +++ b/test/validation/random/random_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "random.h" + +int main(void) +{ + return random_main(); +} diff --git a/test/validation/scheduler/.gitignore b/test/validation/scheduler/.gitignore new file mode 100644 index 000000000..b4eb30091 --- /dev/null +++ b/test/validation/scheduler/.gitignore @@ -0,0 +1 @@ +scheduler_main diff --git a/test/validation/scheduler/Makefile.am b/test/validation/scheduler/Makefile.am new file mode 100644 index 000000000..d5696914f --- /dev/null +++ b/test/validation/scheduler/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libscheduler.la +libscheduler_la_SOURCES = scheduler.c + +bin_PROGRAMS = scheduler_main$(EXEEXT) +dist_scheduler_main_SOURCES = scheduler_main.c +scheduler_main_LDADD = libscheduler.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_scheduler.c b/test/validation/scheduler/scheduler.c index c2eb9969a..d6a4a3e99 100644 --- a/test/validation/odp_scheduler.c +++ b/test/validation/scheduler/scheduler.c @@ -6,9 +6,10 @@ #include <odp.h> #include "odp_cunit_common.h" +#include "scheduler.h" #define MAX_WORKERS_THREADS 32 -#define MSG_POOL_SIZE (4*1024*1024) +#define MSG_POOL_SIZE (4 * 1024 * 1024) #define QUEUES_PER_PRIO 16 #define BUF_SIZE 64 #define TEST_NUM_BUFS 100 @@ -37,7 +38,7 @@ /* Test global variables */ typedef struct { - int cpu_count; + int num_workers; odp_barrier_t barrier; int buf_count; odp_ticketlock_t lock; @@ -51,7 +52,7 @@ typedef struct { int num_queues; int num_prio; int num_bufs; - int num_cpus; + int num_workers; int enable_schd_multi; int enable_excl_atomic; } thread_args_t; @@ -77,7 +78,7 @@ static int exit_schedule_loop(void) return ret; } -static void test_schedule_wait_time(void) +static void scheduler_test_wait_time(void) { uint64_t wait_time; @@ -90,7 +91,7 @@ static void test_schedule_wait_time(void) CU_ASSERT(wait_time > 0); } -static void test_schedule_num_prio(void) +static void scheduler_test_num_prio(void) { int prio; @@ -100,7 +101,7 @@ static void test_schedule_num_prio(void) CU_ASSERT(prio == odp_schedule_num_prio()); } -static void test_schedule_queue_destroy(void) +static void scheduler_test_queue_destroy(void) { odp_pool_t p; odp_pool_param_t params; @@ -119,7 +120,7 @@ static void test_schedule_queue_destroy(void) params.buf.num = 1; params.type = ODP_POOL_BUFFER; - p = odp_pool_create("sched_destroy_pool", ODP_SHM_NULL, ¶ms); + p = odp_pool_create("sched_destroy_pool", ¶ms); CU_ASSERT_FATAL(p != ODP_POOL_INVALID); @@ -141,7 +142,8 @@ static void test_schedule_queue_destroy(void) u32[0] = MAGIC; ev = odp_buffer_to_event(buf); - CU_ASSERT(odp_queue_enq(queue, ev) == 0); + if (!(CU_ASSERT(odp_queue_enq(queue, ev) == 0))) + odp_buffer_free(buf); ev = odp_schedule(&from, ODP_SCHED_WAIT); @@ -166,14 +168,12 @@ static void *schedule_common_(void *arg) { thread_args_t *args = (thread_args_t *)arg; odp_schedule_sync_t sync; - int num_cpus; test_globals_t *globals; globals = args->globals; sync = args->sync; - num_cpus = args->num_cpus; - if (num_cpus == globals->cpu_count) + if (args->num_workers > 1) odp_barrier_wait(&globals->barrier); while (1) { @@ -293,8 +293,10 @@ static void fill_queues(thread_args_t *args) buf = odp_buffer_alloc(pool); CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID); ev = odp_buffer_to_event(buf); - CU_ASSERT(odp_queue_enq(queue, ev) == 0); - buf_count++; + if (!(CU_ASSERT(odp_queue_enq(queue, ev) == 0))) + odp_buffer_free(buf); + else + buf_count++; } } } @@ -312,14 +314,14 @@ static void schedule_common(odp_schedule_sync_t sync, int num_queues, shm = odp_shm_lookup(GLOBALS_SHM_NAME); CU_ASSERT_FATAL(shm != ODP_SHM_INVALID); globals = odp_shm_addr(shm); - CU_ASSERT_FATAL(globals != NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(globals); args.globals = globals; args.sync = sync; args.num_queues = num_queues; args.num_prio = num_prio; args.num_bufs = TEST_NUM_BUFS; - args.num_cpus = 1; + args.num_workers = 1; args.enable_schd_multi = enable_schd_multi; args.enable_excl_atomic = 0; /* Not needed with a single CPU */ @@ -339,12 +341,12 @@ static void parallel_execute(odp_schedule_sync_t sync, int num_queues, shm = odp_shm_lookup(GLOBALS_SHM_NAME); CU_ASSERT_FATAL(shm != ODP_SHM_INVALID); globals = odp_shm_addr(shm); - CU_ASSERT_FATAL(globals != NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(globals); shm = odp_shm_lookup(SHM_THR_ARGS_NAME); CU_ASSERT_FATAL(shm != ODP_SHM_INVALID); args = odp_shm_addr(shm); - CU_ASSERT_FATAL(args != NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(args); args->globals = globals; args->sync = sync; @@ -354,14 +356,14 @@ static void parallel_execute(odp_schedule_sync_t sync, int num_queues, args->num_bufs = NUM_BUFS_EXCL; else args->num_bufs = TEST_NUM_BUFS; - args->num_cpus = globals->cpu_count; + args->num_workers = globals->num_workers; args->enable_schd_multi = enable_schd_multi; args->enable_excl_atomic = enable_excl_atomic; fill_queues(args); /* Create and launch worker threads */ - args->cu_thr.numthrds = globals->cpu_count; + args->cu_thr.numthrds = globals->num_workers; odp_cunit_thread_create(schedule_common_, &args->cu_thr); /* Wait for worker threads to terminate */ @@ -369,25 +371,25 @@ static void parallel_execute(odp_schedule_sync_t sync, int num_queues, } /* 1 queue 1 thread ODP_SCHED_SYNC_NONE */ -static void test_schedule_1q_1t_n(void) +static void scheduler_test_1q_1t_n(void) { schedule_common(ODP_SCHED_SYNC_NONE, ONE_Q, ONE_PRIO, SCHD_ONE); } /* 1 queue 1 thread ODP_SCHED_SYNC_ATOMIC */ -static void test_schedule_1q_1t_a(void) +static void scheduler_test_1q_1t_a(void) { schedule_common(ODP_SCHED_SYNC_ATOMIC, ONE_Q, ONE_PRIO, SCHD_ONE); } /* 1 queue 1 thread ODP_SCHED_SYNC_ORDERED */ -static void test_schedule_1q_1t_o(void) +static void scheduler_test_1q_1t_o(void) { schedule_common(ODP_SCHED_SYNC_ORDERED, ONE_Q, ONE_PRIO, SCHD_ONE); } /* Many queues 1 thread ODP_SCHED_SYNC_NONE */ -static void test_schedule_mq_1t_n(void) +static void scheduler_test_mq_1t_n(void) { /* Only one priority involved in these tests, but use the same number of queues the more general case uses */ @@ -395,89 +397,95 @@ static void test_schedule_mq_1t_n(void) } /* Many queues 1 thread ODP_SCHED_SYNC_ATOMIC */ -static void test_schedule_mq_1t_a(void) +static void scheduler_test_mq_1t_a(void) { schedule_common(ODP_SCHED_SYNC_ATOMIC, MANY_QS, ONE_PRIO, SCHD_ONE); } /* Many queues 1 thread ODP_SCHED_SYNC_ORDERED */ -static void test_schedule_mq_1t_o(void) +static void scheduler_test_mq_1t_o(void) { schedule_common(ODP_SCHED_SYNC_ORDERED, MANY_QS, ONE_PRIO, SCHD_ONE); } /* Many queues 1 thread check priority ODP_SCHED_SYNC_NONE */ -static void test_schedule_mq_1t_prio_n(void) +static void scheduler_test_mq_1t_prio_n(void) { int prio = odp_schedule_num_prio(); + schedule_common(ODP_SCHED_SYNC_NONE, MANY_QS, prio, SCHD_ONE); } /* Many queues 1 thread check priority ODP_SCHED_SYNC_ATOMIC */ -static void test_schedule_mq_1t_prio_a(void) +static void scheduler_test_mq_1t_prio_a(void) { int prio = odp_schedule_num_prio(); + schedule_common(ODP_SCHED_SYNC_ATOMIC, MANY_QS, prio, SCHD_ONE); } /* Many queues 1 thread check priority ODP_SCHED_SYNC_ORDERED */ -static void test_schedule_mq_1t_prio_o(void) +static void scheduler_test_mq_1t_prio_o(void) { int prio = odp_schedule_num_prio(); + schedule_common(ODP_SCHED_SYNC_ORDERED, MANY_QS, prio, SCHD_ONE); } /* Many queues many threads check priority ODP_SCHED_SYNC_NONE */ -static void test_schedule_mq_mt_prio_n(void) +static void scheduler_test_mq_mt_prio_n(void) { int prio = odp_schedule_num_prio(); + parallel_execute(ODP_SCHED_SYNC_NONE, MANY_QS, prio, SCHD_ONE, DISABLE_EXCL_ATOMIC); } /* Many queues many threads check priority ODP_SCHED_SYNC_ATOMIC */ -static void test_schedule_mq_mt_prio_a(void) +static void scheduler_test_mq_mt_prio_a(void) { int prio = odp_schedule_num_prio(); + parallel_execute(ODP_SCHED_SYNC_ATOMIC, MANY_QS, prio, SCHD_ONE, DISABLE_EXCL_ATOMIC); } /* Many queues many threads check priority ODP_SCHED_SYNC_ORDERED */ -static void test_schedule_mq_mt_prio_o(void) +static void scheduler_test_mq_mt_prio_o(void) { int prio = odp_schedule_num_prio(); + parallel_execute(ODP_SCHED_SYNC_ORDERED, MANY_QS, prio, SCHD_ONE, DISABLE_EXCL_ATOMIC); } /* 1 queue many threads check exclusive access on ATOMIC queues */ -static void test_schedule_1q_mt_a_excl(void) +static void scheduler_test_1q_mt_a_excl(void) { parallel_execute(ODP_SCHED_SYNC_ATOMIC, ONE_Q, ONE_PRIO, SCHD_ONE, ENABLE_EXCL_ATOMIC); } /* 1 queue 1 thread ODP_SCHED_SYNC_NONE multi */ -static void test_schedule_multi_1q_1t_n(void) +static void scheduler_test_multi_1q_1t_n(void) { schedule_common(ODP_SCHED_SYNC_NONE, ONE_Q, ONE_PRIO, SCHD_MULTI); } /* 1 queue 1 thread ODP_SCHED_SYNC_ATOMIC multi */ -static void test_schedule_multi_1q_1t_a(void) +static void scheduler_test_multi_1q_1t_a(void) { schedule_common(ODP_SCHED_SYNC_ATOMIC, ONE_Q, ONE_PRIO, SCHD_MULTI); } /* 1 queue 1 thread ODP_SCHED_SYNC_ORDERED multi */ -static void test_schedule_multi_1q_1t_o(void) +static void scheduler_test_multi_1q_1t_o(void) { schedule_common(ODP_SCHED_SYNC_ORDERED, ONE_Q, ONE_PRIO, SCHD_MULTI); } /* Many queues 1 thread ODP_SCHED_SYNC_NONE multi */ -static void test_schedule_multi_mq_1t_n(void) +static void scheduler_test_multi_mq_1t_n(void) { /* Only one priority involved in these tests, but use the same number of queues the more general case uses */ @@ -485,67 +493,73 @@ static void test_schedule_multi_mq_1t_n(void) } /* Many queues 1 thread ODP_SCHED_SYNC_ATOMIC multi */ -static void test_schedule_multi_mq_1t_a(void) +static void scheduler_test_multi_mq_1t_a(void) { schedule_common(ODP_SCHED_SYNC_ATOMIC, MANY_QS, ONE_PRIO, SCHD_MULTI); } /* Many queues 1 thread ODP_SCHED_SYNC_ORDERED multi */ -static void test_schedule_multi_mq_1t_o(void) +static void scheduler_test_multi_mq_1t_o(void) { schedule_common(ODP_SCHED_SYNC_ORDERED, MANY_QS, ONE_PRIO, SCHD_MULTI); } /* Many queues 1 thread check priority ODP_SCHED_SYNC_NONE multi */ -static void test_schedule_multi_mq_1t_prio_n(void) +static void scheduler_test_multi_mq_1t_prio_n(void) { int prio = odp_schedule_num_prio(); + schedule_common(ODP_SCHED_SYNC_NONE, MANY_QS, prio, SCHD_MULTI); } /* Many queues 1 thread check priority ODP_SCHED_SYNC_ATOMIC multi */ -static void test_schedule_multi_mq_1t_prio_a(void) +static void scheduler_test_multi_mq_1t_prio_a(void) { int prio = odp_schedule_num_prio(); + schedule_common(ODP_SCHED_SYNC_ATOMIC, MANY_QS, prio, SCHD_MULTI); } /* Many queues 1 thread check priority ODP_SCHED_SYNC_ORDERED multi */ -static void test_schedule_multi_mq_1t_prio_o(void) +static void scheduler_test_multi_mq_1t_prio_o(void) { int prio = odp_schedule_num_prio(); + schedule_common(ODP_SCHED_SYNC_ORDERED, MANY_QS, prio, SCHD_MULTI); } /* Many queues many threads check priority ODP_SCHED_SYNC_NONE multi */ -static void test_schedule_multi_mq_mt_prio_n(void) +static void scheduler_test_multi_mq_mt_prio_n(void) { int prio = odp_schedule_num_prio(); + parallel_execute(ODP_SCHED_SYNC_NONE, MANY_QS, prio, SCHD_MULTI, 0); } /* Many queues many threads check priority ODP_SCHED_SYNC_ATOMIC multi */ -static void test_schedule_multi_mq_mt_prio_a(void) +static void scheduler_test_multi_mq_mt_prio_a(void) { int prio = odp_schedule_num_prio(); + parallel_execute(ODP_SCHED_SYNC_ATOMIC, MANY_QS, prio, SCHD_MULTI, 0); } /* Many queues many threads check priority ODP_SCHED_SYNC_ORDERED multi */ -static void test_schedule_multi_mq_mt_prio_o(void) +static void scheduler_test_multi_mq_mt_prio_o(void) { int prio = odp_schedule_num_prio(); + parallel_execute(ODP_SCHED_SYNC_ORDERED, MANY_QS, prio, SCHD_MULTI, 0); } /* 1 queue many threads check exclusive access on ATOMIC queues multi */ -static void test_schedule_multi_1q_mt_a_excl(void) +static void scheduler_test_multi_1q_mt_a_excl(void) { parallel_execute(ODP_SCHED_SYNC_ATOMIC, ONE_Q, ONE_PRIO, SCHD_MULTI, ENABLE_EXCL_ATOMIC); } -static void test_schedule_pause_resume(void) +static void scheduler_test_pause_resume(void) { odp_queue_t queue; odp_buffer_t buf; @@ -560,17 +574,17 @@ static void test_schedule_pause_resume(void) pool = odp_pool_lookup(MSG_POOL_NAME); CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); - for (i = 0; i < NUM_BUFS_PAUSE; i++) { buf = odp_buffer_alloc(pool); CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID); ev = odp_buffer_to_event(buf); - odp_queue_enq(queue, ev); + if (odp_queue_enq(queue, ev)) + odp_buffer_free(buf); } for (i = 0; i < NUM_BUFS_BEFORE_PAUSE; i++) { from = ODP_QUEUE_INVALID; - ev = odp_schedule(&from, ODP_SCHED_NO_WAIT); + ev = odp_schedule(&from, ODP_SCHED_WAIT); CU_ASSERT(from == queue); buf = odp_buffer_from_event(ev); odp_buffer_free(buf); @@ -651,8 +665,9 @@ static int create_queues(void) return 0; } -static int schd_suite_init(void) +static int scheduler_suite_init(void) { + odp_cpumask_t mask; odp_shm_t shm; odp_pool_t pool; test_globals_t *globals; @@ -661,10 +676,10 @@ static int schd_suite_init(void) params.buf.size = BUF_SIZE; params.buf.align = 0; - params.buf.num = MSG_POOL_SIZE/BUF_SIZE; + params.buf.num = MSG_POOL_SIZE / BUF_SIZE; params.type = ODP_POOL_BUFFER; - pool = odp_pool_create(MSG_POOL_NAME, ODP_SHM_NULL, ¶ms); + pool = odp_pool_create(MSG_POOL_NAME, ¶ms); if (pool == ODP_POOL_INVALID) { printf("Pool creation failed (msg).\n"); @@ -676,22 +691,22 @@ static int schd_suite_init(void) globals = odp_shm_addr(shm); - if (globals == NULL) { + if (!globals) { printf("Shared memory reserve failed (globals).\n"); return -1; } memset(globals, 0, sizeof(test_globals_t)); - globals->cpu_count = odp_cpu_count(); - if (globals->cpu_count > MAX_WORKERS) - globals->cpu_count = MAX_WORKERS; + globals->num_workers = odp_cpumask_def_worker(&mask, 0); + if (globals->num_workers > MAX_WORKERS) + globals->num_workers = MAX_WORKERS; shm = odp_shm_reserve(SHM_THR_ARGS_NAME, sizeof(thread_args_t), ODP_CACHE_LINE_SIZE, 0); args = odp_shm_addr(shm); - if (args == NULL) { + if (!args) { printf("Shared memory reserve failed (args).\n"); return -1; } @@ -699,7 +714,7 @@ static int schd_suite_init(void) memset(args, 0, sizeof(thread_args_t)); /* Barrier to sync test case execution */ - odp_barrier_init(&globals->barrier, globals->cpu_count); + odp_barrier_init(&globals->barrier, globals->num_workers); odp_ticketlock_init(&globals->lock); odp_spinlock_init(&globals->atomic_lock); @@ -748,7 +763,7 @@ static int destroy_queues(void) return 0; } -static int schd_suite_term(void) +static int scheduler_suite_term(void) { odp_pool_t pool; @@ -764,42 +779,48 @@ static int schd_suite_term(void) return 0; } -struct CU_TestInfo schd_tests[] = { - {"schedule_wait_time", test_schedule_wait_time}, - {"schedule_num_prio", test_schedule_num_prio}, - {"schedule_queue_destroy", test_schedule_queue_destroy}, - {"schedule_1q_1t_n", test_schedule_1q_1t_n}, - {"schedule_1q_1t_a", test_schedule_1q_1t_a}, - {"schedule_1q_1t_o", test_schedule_1q_1t_o}, - {"schedule_mq_1t_n", test_schedule_mq_1t_n}, - {"schedule_mq_1t_a", test_schedule_mq_1t_a}, - {"schedule_mq_1t_o", test_schedule_mq_1t_o}, - {"schedule_mq_1t_prio_n", test_schedule_mq_1t_prio_n}, - {"schedule_mq_1t_prio_a", test_schedule_mq_1t_prio_a}, - {"schedule_mq_1t_prio_o", test_schedule_mq_1t_prio_o}, - {"schedule_mq_mt_prio_n", test_schedule_mq_mt_prio_n}, - {"schedule_mq_mt_prio_a", test_schedule_mq_mt_prio_a}, - {"schedule_mq_mt_prio_o", test_schedule_mq_mt_prio_o}, - {"schedule_1q_mt_a_excl", test_schedule_1q_mt_a_excl}, - {"schedule_multi_1q_1t_n", test_schedule_multi_1q_1t_n}, - {"schedule_multi_1q_1t_a", test_schedule_multi_1q_1t_a}, - {"schedule_multi_1q_1t_o", test_schedule_multi_1q_1t_o}, - {"schedule_multi_mq_1t_n", test_schedule_multi_mq_1t_n}, - {"schedule_multi_mq_1t_a", test_schedule_multi_mq_1t_a}, - {"schedule_multi_mq_1t_o", test_schedule_multi_mq_1t_o}, - {"schedule_multi_mq_1t_prio_n", test_schedule_multi_mq_1t_prio_n}, - {"schedule_multi_mq_1t_prio_a", test_schedule_multi_mq_1t_prio_a}, - {"schedule_multi_mq_1t_prio_o", test_schedule_multi_mq_1t_prio_o}, - {"schedule_multi_mq_mt_prio_n", test_schedule_multi_mq_mt_prio_n}, - {"schedule_multi_mq_mt_prio_a", test_schedule_multi_mq_mt_prio_a}, - {"schedule_multi_mq_mt_prio_o", test_schedule_multi_mq_mt_prio_o}, - {"schedule_multi_1q_mt_a_excl", test_schedule_multi_1q_mt_a_excl}, - {"schedule_pause_resume", test_schedule_pause_resume}, +static struct CU_TestInfo scheduler_suite[] = { + {"schedule_wait_time", scheduler_test_wait_time}, + {"schedule_num_prio", scheduler_test_num_prio}, + {"schedule_queue_destroy", scheduler_test_queue_destroy}, + {"schedule_1q_1t_n", scheduler_test_1q_1t_n}, + {"schedule_1q_1t_a", scheduler_test_1q_1t_a}, + {"schedule_1q_1t_o", scheduler_test_1q_1t_o}, + {"schedule_mq_1t_n", scheduler_test_mq_1t_n}, + {"schedule_mq_1t_a", scheduler_test_mq_1t_a}, + {"schedule_mq_1t_o", scheduler_test_mq_1t_o}, + {"schedule_mq_1t_prio_n", scheduler_test_mq_1t_prio_n}, + {"schedule_mq_1t_prio_a", scheduler_test_mq_1t_prio_a}, + {"schedule_mq_1t_prio_o", scheduler_test_mq_1t_prio_o}, + {"schedule_mq_mt_prio_n", scheduler_test_mq_mt_prio_n}, + {"schedule_mq_mt_prio_a", scheduler_test_mq_mt_prio_a}, + {"schedule_mq_mt_prio_o", scheduler_test_mq_mt_prio_o}, + {"schedule_1q_mt_a_excl", scheduler_test_1q_mt_a_excl}, + {"schedule_multi_1q_1t_n", scheduler_test_multi_1q_1t_n}, + {"schedule_multi_1q_1t_a", scheduler_test_multi_1q_1t_a}, + {"schedule_multi_1q_1t_o", scheduler_test_multi_1q_1t_o}, + {"schedule_multi_mq_1t_n", scheduler_test_multi_mq_1t_n}, + {"schedule_multi_mq_1t_a", scheduler_test_multi_mq_1t_a}, + {"schedule_multi_mq_1t_o", scheduler_test_multi_mq_1t_o}, + {"schedule_multi_mq_1t_prio_n", scheduler_test_multi_mq_1t_prio_n}, + {"schedule_multi_mq_1t_prio_a", scheduler_test_multi_mq_1t_prio_a}, + {"schedule_multi_mq_1t_prio_o", scheduler_test_multi_mq_1t_prio_o}, + {"schedule_multi_mq_mt_prio_n", scheduler_test_multi_mq_mt_prio_n}, + {"schedule_multi_mq_mt_prio_a", scheduler_test_multi_mq_mt_prio_a}, + {"schedule_multi_mq_mt_prio_o", scheduler_test_multi_mq_mt_prio_o}, + {"schedule_multi_1q_mt_a_excl", scheduler_test_multi_1q_mt_a_excl}, + {"schedule_pause_resume", scheduler_test_pause_resume}, CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { +static CU_SuiteInfo scheduler_suites[] = { {"Scheduler", - schd_suite_init, schd_suite_term, NULL, NULL, schd_tests}, + scheduler_suite_init, scheduler_suite_term, NULL, NULL, scheduler_suite + }, CU_SUITE_INFO_NULL, }; + +int scheduler_main(void) +{ + return odp_cunit_run(scheduler_suites); +} diff --git a/test/validation/scheduler/scheduler.h b/test/validation/scheduler/scheduler.h new file mode 100644 index 000000000..db0f2895b --- /dev/null +++ b/test/validation/scheduler/scheduler.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_SCHEDULER_H_ +#define _ODP_TEST_SCHEDULER_H_ + +int scheduler_main(void); + +#endif diff --git a/test/validation/scheduler/scheduler_main.c b/test/validation/scheduler/scheduler_main.c new file mode 100644 index 000000000..1f6f32f51 --- /dev/null +++ b/test/validation/scheduler/scheduler_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "scheduler.h" + +int main(void) +{ + return scheduler_main(); +} diff --git a/test/validation/shmem/.gitignore b/test/validation/shmem/.gitignore new file mode 100644 index 000000000..4d82fd53a --- /dev/null +++ b/test/validation/shmem/.gitignore @@ -0,0 +1 @@ +shmem_main diff --git a/test/validation/shmem/Makefile.am b/test/validation/shmem/Makefile.am new file mode 100644 index 000000000..d81303db2 --- /dev/null +++ b/test/validation/shmem/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libshmem.la +libshmem_la_SOURCES = shmem.c + +bin_PROGRAMS = shmem_main$(EXEEXT) +dist_shmem_main_SOURCES = shmem_main.c +shmem_main_LDADD = libshmem.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_shared_memory.c b/test/validation/shmem/shmem.c index 938ae6583..0c713c657 100644 --- a/test/validation/odp_shared_memory.c +++ b/test/validation/shmem/shmem.c @@ -6,6 +6,7 @@ #include <odp.h> #include <odp_cunit_common.h> +#include "shmem.h" #define ALIGE_SIZE (128) #define TESTNAME "cunit_test_shared_data" @@ -43,7 +44,7 @@ static void *run_shm_thread(void *arg) return arg; } -static void test_odp_shm_sunnyday(void) +static void shmem_test_odp_shm_sunnyday(void) { pthrd_arg thrdarg; odp_shm_t shm; @@ -75,13 +76,17 @@ static void test_odp_shm_sunnyday(void) odp_cunit_thread_exit(&thrdarg); } -CU_TestInfo test_odp_shm[] = { - {"test_odp_shm_creat", test_odp_shm_sunnyday}, +static CU_TestInfo shmem_suite[] = { + {"test_odp_shm_creat", shmem_test_odp_shm_sunnyday}, CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { - {"Shared Memory", NULL, NULL, NULL, NULL, test_odp_shm}, +static CU_SuiteInfo shmem_suites[] = { + {"Shared Memory", NULL, NULL, NULL, NULL, shmem_suite}, CU_SUITE_INFO_NULL, }; +int shmem_main(void) +{ + return odp_cunit_run(shmem_suites); +} diff --git a/test/validation/shmem/shmem.h b/test/validation/shmem/shmem.h new file mode 100644 index 000000000..f9cf52307 --- /dev/null +++ b/test/validation/shmem/shmem.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_SHMEM_H_ +#define _ODP_TEST_SHMEM_H_ + +int shmem_main(void); + +#endif diff --git a/test/validation/shmem/shmem_main.c b/test/validation/shmem/shmem_main.c new file mode 100644 index 000000000..445fbf111 --- /dev/null +++ b/test/validation/shmem/shmem_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "shmem.h" + +int main(void) +{ + return shmem_main(); +} diff --git a/test/validation/synchronizers/.gitignore b/test/validation/synchronizers/.gitignore new file mode 100644 index 000000000..6aad9dfbd --- /dev/null +++ b/test/validation/synchronizers/.gitignore @@ -0,0 +1 @@ +synchronizers_main diff --git a/test/validation/synchronizers/Makefile.am b/test/validation/synchronizers/Makefile.am new file mode 100644 index 000000000..ecb9886a3 --- /dev/null +++ b/test/validation/synchronizers/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libsynchronizers.la +libsynchronizers_la_SOURCES = synchronizers.c + +bin_PROGRAMS = synchronizers_main$(EXEEXT) +dist_synchronizers_main_SOURCES = synchronizers_main.c +synchronizers_main_LDADD = libsynchronizers.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_synchronizers.c b/test/validation/synchronizers/synchronizers.c index 71342d182..ed56c8fca 100644 --- a/test/validation/odp_synchronizers.c +++ b/test/validation/synchronizers/synchronizers.c @@ -9,6 +9,8 @@ #include <CUnit/Basic.h> #include <odp_cunit_common.h> #include <unistd.h> +#include "synchronizers.h" + #define VERBOSE 0 #define MAX_ITERATIONS 1000 #define BARRIER_ITERATIONS 64 @@ -123,7 +125,7 @@ static per_thread_mem_t *thread_init(void) global_shm = odp_shm_lookup(GLOBAL_SHM_NAME); global_mem = odp_shm_addr(global_shm); - CU_ASSERT(global_mem != NULL); + CU_ASSERT_PTR_NOT_NULL(global_mem); per_thread_mem->global_mem = global_mem; @@ -181,8 +183,8 @@ static uint32_t barrier_test(per_thread_mem_t *per_thread_mem, barrier_cnt2 = global_mem->barrier_cnt2; if ((barrier_cnt1 != cnt) || (barrier_cnt2 != cnt)) { - printf("thread_num=%"PRIu32" barrier_cnts of %"PRIu32 - " %"PRIu32" cnt=%"PRIu32"\n", + printf("thread_num=%" PRIu32 " barrier_cnts of %" PRIu32 + " %" PRIu32 " cnt=%" PRIu32 "\n", thread_num, barrier_cnt1, barrier_cnt2, cnt); barrier_errs++; } @@ -231,10 +233,10 @@ static uint32_t barrier_test(per_thread_mem_t *per_thread_mem, } if ((global_mem->g_verbose) && (barrier_errs != 0)) - printf("\nThread %"PRIu32" (id=%d core=%d) had %"PRIu32 - " barrier_errs in %"PRIu32" iterations\n", thread_num, - per_thread_mem->thread_id, - per_thread_mem->thread_core, barrier_errs, iterations); + printf("\nThread %" PRIu32 " (id=%d core=%d) had %" PRIu32 + " barrier_errs in %" PRIu32 " iterations\n", thread_num, + per_thread_mem->thread_id, + per_thread_mem->thread_core, barrier_errs, iterations); return barrier_errs; } @@ -435,8 +437,9 @@ static void *no_lock_functional_test(void *arg UNUSED) } if (global_mem->g_verbose) - printf("\nThread %"PRIu32" (id=%d core=%d) had %"PRIu32" sync_failures" - " in %"PRIu32" iterations\n", thread_num, + printf("\nThread %" PRIu32 " (id=%d core=%d) had %" PRIu32 + " sync_failures in %" PRIu32 " iterations\n", + thread_num, per_thread_mem->thread_id, per_thread_mem->thread_core, sync_failures, iterations); @@ -523,8 +526,10 @@ static void *spinlock_functional_test(void *arg UNUSED) if ((global_mem->g_verbose) && ((sync_failures != 0) || (is_locked_errs != 0))) - printf("\nThread %"PRIu32" (id=%d core=%d) had %"PRIu32" sync_failures" - " and %"PRIu32" is_locked_errs in %"PRIu32" iterations\n", thread_num, + printf("\nThread %" PRIu32 " (id=%d core=%d) had %" PRIu32 + " sync_failures and %" PRIu32 + " is_locked_errs in %" PRIu32 + " iterations\n", thread_num, per_thread_mem->thread_id, per_thread_mem->thread_core, sync_failures, is_locked_errs, iterations); @@ -608,8 +613,10 @@ static void *ticketlock_functional_test(void *arg UNUSED) if ((global_mem->g_verbose) && ((sync_failures != 0) || (is_locked_errs != 0))) - printf("\nThread %"PRIu32" (id=%d core=%d) had %"PRIu32" sync_failures" - " and %"PRIu32" is_locked_errs in %"PRIu32" iterations\n", thread_num, + printf("\nThread %" PRIu32 " (id=%d core=%d) had %" PRIu32 + " sync_failures and %" PRIu32 + " is_locked_errs in %" PRIu32 " iterations\n", + thread_num, per_thread_mem->thread_id, per_thread_mem->thread_core, sync_failures, is_locked_errs, iterations); @@ -686,8 +693,8 @@ static void *rwlock_functional_test(void *arg UNUSED) } if ((global_mem->g_verbose) && (sync_failures != 0)) - printf("\nThread %"PRIu32" (id=%d core=%d) had %"PRIu32" sync_failures" - " in %"PRIu32" iterations\n", thread_num, + printf("\nThread %" PRIu32 " (id=%d core=%d) had %" PRIu32 + " sync_failures in %" PRIu32 " iterations\n", thread_num, per_thread_mem->thread_id, per_thread_mem->thread_core, sync_failures, iterations); @@ -876,7 +883,6 @@ static void test_atomic_add_sub_32(void) test_atomic_sub_32(); } - static void test_atomic_add_sub_64(void) { test_atomic_add_64(); @@ -914,86 +920,87 @@ static void test_atomic_validate(void) } /* Barrier tests */ -static void test_no_barrier_functional(void) +static void synchronizers_test_no_barrier_functional(void) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; barrier_test_init(); odp_cunit_thread_create(no_barrier_functional_test, &arg); odp_cunit_thread_exit(&arg); } -static void test_barrier_functional(void) +static void synchronizers_test_barrier_functional(void) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; barrier_test_init(); odp_cunit_thread_create(barrier_functional_test, &arg); odp_cunit_thread_exit(&arg); } -static CU_TestInfo test_odp_barrier[] = { - {"no_barrier_functional", test_no_barrier_functional}, - {"barrier_functional", test_barrier_functional}, +static CU_TestInfo synchronizers_suite_barrier[] = { + {"no_barrier_functional", synchronizers_test_no_barrier_functional}, + {"barrier_functional", synchronizers_test_barrier_functional}, CU_TEST_INFO_NULL }; /* Thread-unsafe tests */ -static void test_no_lock_functional(void) +static void synchronizers_test_no_lock_functional(void) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; odp_cunit_thread_create(no_lock_functional_test, &arg); odp_cunit_thread_exit(&arg); } -static CU_TestInfo test_no_locking[] = { - {"no_lock_functional", test_no_lock_functional}, +static CU_TestInfo synchronizers_suite_no_locking[] = { + {"no_lock_functional", synchronizers_test_no_lock_functional}, CU_TEST_INFO_NULL }; /* Spin lock tests */ -static void test_spinlock_api(void) +static void synchronizers_test_spinlock_api(void) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; odp_cunit_thread_create(spinlock_api_tests, &arg); odp_cunit_thread_exit(&arg); } -static void test_spinlock_functional(void) +static void synchronizers_test_spinlock_functional(void) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; odp_spinlock_init(&global_mem->global_spinlock); odp_cunit_thread_create(spinlock_functional_test, &arg); odp_cunit_thread_exit(&arg); } -static CU_TestInfo test_odp_spinlock[] = { - {"spinlock_api", test_spinlock_api}, - {"spinlock_functional", test_spinlock_functional}, +static CU_TestInfo synchronizers_suite_spinlock[] = { + {"spinlock_api", synchronizers_test_spinlock_api}, + {"spinlock_functional", synchronizers_test_spinlock_functional}, CU_TEST_INFO_NULL }; /* Ticket lock tests */ -static void test_ticketlock_api(void) +static void synchronizers_test_ticketlock_api(void) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; odp_cunit_thread_create(ticketlock_api_tests, &arg); odp_cunit_thread_exit(&arg); } -static void test_ticketlock_functional(void) +static void synchronizers_test_ticketlock_functional(void) { pthrd_arg arg; + arg.numthrds = global_mem->g_num_threads; odp_ticketlock_init(&global_mem->global_ticketlock); @@ -1001,40 +1008,39 @@ static void test_ticketlock_functional(void) odp_cunit_thread_exit(&arg); } -static CU_TestInfo test_odp_ticketlock[] = { - {"ticketlock_api", test_ticketlock_api}, - {"ticketlock_functional", test_ticketlock_functional}, +static CU_TestInfo synchronizers_suite_ticketlock[] = { + {"ticketlock_api", synchronizers_test_ticketlock_api}, + {"ticketlock_functional", synchronizers_test_ticketlock_functional}, CU_TEST_INFO_NULL }; /* RW lock tests */ -static void test_rwlock_api(void) +static void synchronizers_test_rwlock_api(void) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; odp_cunit_thread_create(rwlock_api_tests, &arg); odp_cunit_thread_exit(&arg); } -static void test_rwlock_functional(void) +static void synchronizers_test_rwlock_functional(void) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; odp_rwlock_init(&global_mem->global_rwlock); odp_cunit_thread_create(rwlock_functional_test, &arg); odp_cunit_thread_exit(&arg); } -static CU_TestInfo test_odp_rwlock[] = { - {"rwlock_api", test_rwlock_api}, - {"rwlock_functional", test_rwlock_functional}, +static CU_TestInfo synchronizers_suite_rwlock[] = { + {"rwlock_api", synchronizers_test_rwlock_api}, + {"rwlock_functional", synchronizers_test_rwlock_functional}, CU_TEST_INFO_NULL }; - -static int init_locks(void) +static int synchronizers_suite_init(void) { uint32_t num_threads, idx; @@ -1046,7 +1052,7 @@ static int init_locks(void) return 0; } -int tests_global_init(void) +static int synchronizers_init(void) { uint32_t core_count, max_threads; int ret = 0; @@ -1055,7 +1061,7 @@ int tests_global_init(void) fprintf(stderr, "error: odp_init_global() failed.\n"); return -1; } - if (0 != odp_init_local()) { + if (0 != odp_init_local(ODP_THREAD_CONTROL)) { fprintf(stderr, "error: odp_init_local() failed.\n"); return -1; } @@ -1081,12 +1087,14 @@ int tests_global_init(void) if (max_threads < global_mem->g_num_threads) { printf("Requested num of threads is too large\n"); - printf("reducing from %"PRIu32" to %"PRIu32"\n", global_mem->g_num_threads, + printf("reducing from %" PRIu32 " to %" PRIu32 "\n", + global_mem->g_num_threads, max_threads); global_mem->g_num_threads = max_threads; } - printf("Num of threads used = %"PRIu32"\n", global_mem->g_num_threads); + printf("Num of threads used = %" PRIu32 "\n", + global_mem->g_num_threads); return ret; } @@ -1147,8 +1155,8 @@ static void *test_atomic_fetch_add_sub_thread(void *arg UNUSED) static void test_atomic_functional(void *func_ptr(void *)) { pthrd_arg arg; - arg.numthrds = global_mem->g_num_threads; + arg.numthrds = global_mem->g_num_threads; test_atomic_init(); test_atomic_store(); odp_cunit_thread_create(func_ptr, &arg); @@ -1156,40 +1164,52 @@ static void test_atomic_functional(void *func_ptr(void *)) test_atomic_validate(); } -static void test_atomic_inc_dec(void) +static void synchronizers_test_atomic_inc_dec(void) { test_atomic_functional(test_atomic_inc_dec_thread); } -static void test_atomic_add_sub(void) +static void synchronizers_test_atomic_add_sub(void) { test_atomic_functional(test_atomic_add_sub_thread); } -static void test_atomic_fetch_inc_dec(void) +static void synchronizers_test_atomic_fetch_inc_dec(void) { test_atomic_functional(test_atomic_fetch_inc_dec_thread); } -static void test_atomic_fetch_add_sub(void) +static void synchronizers_test_atomic_fetch_add_sub(void) { test_atomic_functional(test_atomic_fetch_add_sub_thread); } -CU_TestInfo test_odp_atomic[] = { - {"atomic_inc_dec", test_atomic_inc_dec}, - {"atomic_add_sub", test_atomic_add_sub}, - {"atomic_fetch_inc_dec", test_atomic_fetch_inc_dec}, - {"atomic_fetch_add_sub", test_atomic_fetch_add_sub}, +static CU_TestInfo synchronizers_suite_atomic[] = { + {"atomic_inc_dec", synchronizers_test_atomic_inc_dec}, + {"atomic_add_sub", synchronizers_test_atomic_add_sub}, + {"atomic_fetch_inc_dec", synchronizers_test_atomic_fetch_inc_dec}, + {"atomic_fetch_add_sub", synchronizers_test_atomic_fetch_add_sub}, CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { - {"barrier", NULL, NULL, NULL, NULL, test_odp_barrier}, - {"nolocking", init_locks, NULL, NULL, NULL, test_no_locking}, - {"spinlock", init_locks, NULL, NULL, NULL, test_odp_spinlock}, - {"ticketlock", init_locks, NULL, NULL, NULL, test_odp_ticketlock}, - {"rwlock", init_locks, NULL, NULL, NULL, test_odp_rwlock}, - {"atomic", NULL, NULL, NULL, NULL, test_odp_atomic}, +static CU_SuiteInfo synchronizers_suites[] = { + {"barrier", NULL, + NULL, NULL, NULL, synchronizers_suite_barrier}, + {"nolocking", synchronizers_suite_init, + NULL, NULL, NULL, synchronizers_suite_no_locking}, + {"spinlock", synchronizers_suite_init, + NULL, NULL, NULL, synchronizers_suite_spinlock}, + {"ticketlock", synchronizers_suite_init, + NULL, NULL, NULL, synchronizers_suite_ticketlock}, + {"rwlock", synchronizers_suite_init, + NULL, NULL, NULL, synchronizers_suite_rwlock}, + {"atomic", NULL, NULL, NULL, NULL, + synchronizers_suite_atomic}, CU_SUITE_INFO_NULL }; + +int synchronizers_main(void) +{ + odp_cunit_register_global_init(synchronizers_init); + return odp_cunit_run(synchronizers_suites); +} diff --git a/test/validation/synchronizers/synchronizers.h b/test/validation/synchronizers/synchronizers.h new file mode 100644 index 000000000..8a931876f --- /dev/null +++ b/test/validation/synchronizers/synchronizers.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_SYNCHRONIZERS_H_ +#define _ODP_TEST_SYNCHRONIZERS_H_ + +int synchronizers_main(void); + +#endif diff --git a/test/validation/synchronizers/synchronizers_main.c b/test/validation/synchronizers/synchronizers_main.c new file mode 100644 index 000000000..659d3152f --- /dev/null +++ b/test/validation/synchronizers/synchronizers_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "synchronizers.h" + +int main(void) +{ + return synchronizers_main(); +} diff --git a/test/validation/system/.gitignore b/test/validation/system/.gitignore new file mode 100644 index 000000000..347b1ee21 --- /dev/null +++ b/test/validation/system/.gitignore @@ -0,0 +1 @@ +system_main diff --git a/test/validation/system/Makefile.am b/test/validation/system/Makefile.am new file mode 100644 index 000000000..dd7759c2e --- /dev/null +++ b/test/validation/system/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libsystem.la +libsystem_la_SOURCES = system.c + +bin_PROGRAMS = system_main$(EXEEXT) +dist_system_main_SOURCES = system_main.c +system_main_LDADD = libsystem.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/system/system.c b/test/validation/system/system.c new file mode 100644 index 000000000..b80fd39f9 --- /dev/null +++ b/test/validation/system/system.c @@ -0,0 +1,105 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <ctype.h> +#include <odp.h> +#include "odp_cunit_common.h" +#include "test_debug.h" +#include "system.h" + +static void system_test_odp_version_numbers(void) +{ + int char_ok; + char version_string[128]; + char *s = version_string; + + strncpy(version_string, odp_version_api_str(), + sizeof(version_string) - 1); + + while (*s) { + if (isdigit((int)*s) || (strncmp(s, ".", 1) == 0)) { + char_ok = 1; + s++; + } else { + char_ok = 0; + LOG_DBG("\nBAD VERSION=%s\n", version_string); + break; + } + } + CU_ASSERT(char_ok); +} + +static void system_test_odp_cpu_count(void) +{ + int cpus; + + cpus = odp_cpu_count(); + CU_ASSERT(0 < cpus); +} + +static void system_test_odp_sys_cache_line_size(void) +{ + uint64_t cache_size; + + cache_size = odp_sys_cache_line_size(); + CU_ASSERT(0 < cache_size); + CU_ASSERT(ODP_CACHE_LINE_SIZE == cache_size); +} + +static void system_test_odp_sys_cpu_model_str(void) +{ + char model[128]; + + snprintf(model, 128, "%s", odp_sys_cpu_model_str()); + CU_ASSERT(strlen(model) > 0); + CU_ASSERT(strlen(model) < 127); +} + +static void system_test_odp_sys_page_size(void) +{ + uint64_t page; + + page = odp_sys_page_size(); + CU_ASSERT(0 < page); + CU_ASSERT(ODP_PAGE_SIZE == page); +} + +static void system_test_odp_sys_huge_page_size(void) +{ + uint64_t page; + + page = odp_sys_huge_page_size(); + CU_ASSERT(0 < page); +} + +static void system_test_odp_sys_cpu_hz(void) +{ + uint64_t hz; + + hz = odp_sys_cpu_hz(); + CU_ASSERT(0 < hz); +} + +static CU_TestInfo system_suite[] = { + {"odp version", system_test_odp_version_numbers}, + {"odp_cpu_count", system_test_odp_cpu_count}, + {"odp_sys_cache_line_size", system_test_odp_sys_cache_line_size}, + {"odp_sys_cpu_model_str", system_test_odp_sys_cpu_model_str}, + {"odp_sys_page_size", system_test_odp_sys_page_size}, + {"odp_sys_huge_page_size", system_test_odp_sys_huge_page_size}, + {"odp_sys_cpu_hz", system_test_odp_sys_cpu_hz}, + CU_TEST_INFO_NULL, +}; + +static CU_SuiteInfo system_suites[] = { + {"System Info", NULL, NULL, NULL, NULL, system_suite}, + CU_SUITE_INFO_NULL, +}; + +int system_main(void) +{ + return odp_cunit_run(system_suites); +} diff --git a/test/validation/system/system.h b/test/validation/system/system.h new file mode 100644 index 000000000..f00ae5754 --- /dev/null +++ b/test/validation/system/system.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_SYSTEM_H_ +#define _ODP_TEST_SYSTEM_H_ + +int system_main(void); + +#endif diff --git a/test/validation/system/system_main.c b/test/validation/system/system_main.c new file mode 100644 index 000000000..5293dc08c --- /dev/null +++ b/test/validation/system/system_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "system.h" + +int main(void) +{ + return system_main(); +} diff --git a/test/validation/thread/.gitignore b/test/validation/thread/.gitignore new file mode 100644 index 000000000..ab1787d97 --- /dev/null +++ b/test/validation/thread/.gitignore @@ -0,0 +1 @@ +thread_main diff --git a/test/validation/thread/Makefile.am b/test/validation/thread/Makefile.am new file mode 100644 index 000000000..c18bc5018 --- /dev/null +++ b/test/validation/thread/Makefile.am @@ -0,0 +1,10 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libthread.la +libthread_la_SOURCES = thread.c +libthread_la_CFLAGS = $(AM_CFLAGS) -DTEST_THRMASK +libthread_la_LIBADD = $(LIBTHRMASK_COMMON) + +bin_PROGRAMS = thread_main$(EXEEXT) +dist_thread_main_SOURCES = thread_main.c +thread_main_LDADD = libthread.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/thread/thread.c b/test/validation/thread/thread.c new file mode 100644 index 000000000..6fbdaef45 --- /dev/null +++ b/test/validation/thread/thread.c @@ -0,0 +1,132 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp.h> +#include <odp_cunit_common.h> +#include <mask_common.h> +#include <test_debug.h> +#include "thread.h" + +/* Helper macro for CU_TestInfo initialization */ +#define _CU_TEST_INFO(test_func) {#test_func, test_func} + +/* Test thread entry and exit synchronization barriers */ +odp_barrier_t bar_entry; +odp_barrier_t bar_exit; + +static void thread_test_odp_cpu_id(void) +{ + (void)odp_cpu_id(); + CU_PASS(); +} + +static void thread_test_odp_thread_id(void) +{ + (void)odp_thread_id(); + CU_PASS(); +} + +static void thread_test_odp_thread_count(void) +{ + (void)odp_thread_count(); + CU_PASS(); +} + +static void *thread_func(void *arg TEST_UNUSED) +{ + /* indicate that thread has started */ + odp_barrier_wait(&bar_entry); + + CU_ASSERT(odp_thread_type() == ODP_THREAD_WORKER); + + /* wait for indication that we can exit */ + odp_barrier_wait(&bar_exit); + + return NULL; +} + +static void thread_test_odp_thrmask_worker(void) +{ + odp_thrmask_t mask; + int ret; + pthrd_arg args = { .testcase = 0, .numthrds = 1 }; + + CU_ASSERT_FATAL(odp_thread_type() == ODP_THREAD_CONTROL); + + odp_barrier_init(&bar_entry, args.numthrds + 1); + odp_barrier_init(&bar_exit, args.numthrds + 1); + + /* should start out with 0 worker threads */ + ret = odp_thrmask_worker(&mask); + CU_ASSERT(ret == odp_thrmask_count(&mask)); + CU_ASSERT(ret == 0); + + /* start the test thread(s) */ + ret = odp_cunit_thread_create(thread_func, &args); + CU_ASSERT(ret == args.numthrds); + + if (ret != args.numthrds) + return; + + /* wait for thread(s) to start */ + odp_barrier_wait(&bar_entry); + + ret = odp_thrmask_worker(&mask); + CU_ASSERT(ret == odp_thrmask_count(&mask)); + CU_ASSERT(ret == args.numthrds); + CU_ASSERT(ret <= ODP_CONFIG_MAX_THREADS); + + /* allow thread(s) to exit */ + odp_barrier_wait(&bar_exit); + + odp_cunit_thread_exit(&args); +} + +static void thread_test_odp_thrmask_control(void) +{ + odp_thrmask_t mask; + int ret; + + CU_ASSERT(odp_thread_type() == ODP_THREAD_CONTROL); + + /* should start out with 1 worker thread */ + ret = odp_thrmask_control(&mask); + CU_ASSERT(ret == odp_thrmask_count(&mask)); + CU_ASSERT(ret == 1); +} + +static CU_TestInfo thread_suite[] = { + _CU_TEST_INFO(thread_test_odp_cpu_id), + _CU_TEST_INFO(thread_test_odp_thread_id), + _CU_TEST_INFO(thread_test_odp_thread_count), + _CU_TEST_INFO(thread_test_odp_thrmask_to_from_str), + _CU_TEST_INFO(thread_test_odp_thrmask_equal), + _CU_TEST_INFO(thread_test_odp_thrmask_zero), + _CU_TEST_INFO(thread_test_odp_thrmask_set), + _CU_TEST_INFO(thread_test_odp_thrmask_clr), + _CU_TEST_INFO(thread_test_odp_thrmask_isset), + _CU_TEST_INFO(thread_test_odp_thrmask_count), + _CU_TEST_INFO(thread_test_odp_thrmask_and), + _CU_TEST_INFO(thread_test_odp_thrmask_or), + _CU_TEST_INFO(thread_test_odp_thrmask_xor), + _CU_TEST_INFO(thread_test_odp_thrmask_copy), + _CU_TEST_INFO(thread_test_odp_thrmask_first), + _CU_TEST_INFO(thread_test_odp_thrmask_last), + _CU_TEST_INFO(thread_test_odp_thrmask_next), + _CU_TEST_INFO(thread_test_odp_thrmask_worker), + _CU_TEST_INFO(thread_test_odp_thrmask_control), + CU_TEST_INFO_NULL, +}; + +static CU_SuiteInfo thread_suites[] = { + {"thread", NULL, NULL, NULL, NULL, thread_suite}, + CU_SUITE_INFO_NULL, +}; + +int thread_main(void) +{ + return odp_cunit_run(thread_suites); +} diff --git a/test/validation/thread/thread.h b/test/validation/thread/thread.h new file mode 100644 index 000000000..c0cbb34ab --- /dev/null +++ b/test/validation/thread/thread.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_THREAD_H_ +#define _ODP_TEST_THREAD_H_ + +int thread_main(void); + +#endif diff --git a/test/validation/thread/thread_main.c b/test/validation/thread/thread_main.c new file mode 100644 index 000000000..1751b01f7 --- /dev/null +++ b/test/validation/thread/thread_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "thread.h" + +int main(void) +{ + return thread_main(); +} diff --git a/test/validation/time/.gitignore b/test/validation/time/.gitignore new file mode 100644 index 000000000..0ef3e6162 --- /dev/null +++ b/test/validation/time/.gitignore @@ -0,0 +1 @@ +time_main diff --git a/test/validation/time/Makefile.am b/test/validation/time/Makefile.am new file mode 100644 index 000000000..418107d11 --- /dev/null +++ b/test/validation/time/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libtime.la +libtime_la_SOURCES = time.c + +bin_PROGRAMS = time_main$(EXEEXT) +dist_time_main_SOURCES = time_main.c +time_main_LDADD = libtime.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_time.c b/test/validation/time/time.c index 8db989445..0aac599b6 100644 --- a/test/validation/odp_time.c +++ b/test/validation/time/time.c @@ -6,12 +6,13 @@ #include <odp.h> #include "odp_cunit_common.h" +#include "time.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) +static void time_test_odp_cycles_diff(void) { /* volatile to stop optimization of busy loop */ volatile int count = 0; @@ -31,9 +32,10 @@ static void test_odp_cycles_diff(void) } /* check that a negative cycles difference gives a reasonable result */ -static void test_odp_cycles_negative_diff(void) +static void time_test_odp_cycles_negative_diff(void) { uint64_t diff, cycles1, cycles2; + cycles1 = 10; cycles2 = 5; diff = odp_time_diff_cycles(cycles1, cycles2); @@ -41,10 +43,11 @@ static void test_odp_cycles_negative_diff(void) } /* check that related conversions come back to the same value */ -static void test_odp_time_conversion(void) +static void time_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); @@ -58,14 +61,19 @@ static void test_odp_time_conversion(void) 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_TestInfo time_suite_time[] = { + {"cycles diff", time_test_odp_cycles_diff}, + {"negative diff", time_test_odp_cycles_negative_diff}, + {"conversion", time_test_odp_time_conversion}, CU_TEST_INFO_NULL }; -CU_SuiteInfo odp_testsuites[] = { - {"Time", NULL, NULL, NULL, NULL, test_odp_time}, +static CU_SuiteInfo time_suites[] = { + {"Time", NULL, NULL, NULL, NULL, time_suite_time}, CU_SUITE_INFO_NULL }; + +int time_main(void) +{ + return odp_cunit_run(time_suites); +} diff --git a/test/validation/time/time.h b/test/validation/time/time.h new file mode 100644 index 000000000..1cd54d97f --- /dev/null +++ b/test/validation/time/time.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_TIME_H_ +#define _ODP_TEST_TIME_H_ + +int time_main(void); + +#endif diff --git a/test/validation/time/time_main.c b/test/validation/time/time_main.c new file mode 100644 index 000000000..36cc1dc6f --- /dev/null +++ b/test/validation/time/time_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "time.h" + +int main(void) +{ + return time_main(); +} diff --git a/test/validation/timer/.gitignore b/test/validation/timer/.gitignore new file mode 100644 index 000000000..74e8fa992 --- /dev/null +++ b/test/validation/timer/.gitignore @@ -0,0 +1 @@ +timer_main diff --git a/test/validation/timer/Makefile.am b/test/validation/timer/Makefile.am new file mode 100644 index 000000000..591dfb637 --- /dev/null +++ b/test/validation/timer/Makefile.am @@ -0,0 +1,8 @@ +include ../Makefile.inc + +noinst_LTLIBRARIES = libtimer.la +libtimer_la_SOURCES = timer.c + +bin_PROGRAMS = timer_main$(EXEEXT) +dist_timer_main_SOURCES = timer_main.c +timer_main_LDADD = libtimer.la $(LIBCUNIT_COMMON) $(LIBODP) diff --git a/test/validation/odp_timer.c b/test/validation/timer/timer.c index 554b35368..ecca78564 100644 --- a/test/validation/odp_timer.c +++ b/test/validation/timer/timer.c @@ -14,6 +14,7 @@ #include <odp.h> #include "odp_cunit_common.h" #include "test_debug.h" +#include "timer.h" /** @private Timeout range in milliseconds (ms) */ #define RANGE_MS 2000 @@ -49,7 +50,7 @@ struct test_timer { #define TICK_INVALID (~(uint64_t)0) -static void test_timeout_pool_alloc(void) +static void timer_test_timeout_pool_alloc(void) { odp_pool_t pool; const int num = 3; @@ -64,7 +65,7 @@ static void test_timeout_pool_alloc(void) .type = ODP_POOL_TIMEOUT, }; - pool = odp_pool_create("timeout_pool_alloc", ODP_SHM_NULL, ¶ms); + pool = odp_pool_create("timeout_pool_alloc", ¶ms); odp_pool_print(pool); /* Try to allocate num items from the pool */ @@ -93,7 +94,7 @@ static void test_timeout_pool_alloc(void) CU_ASSERT(odp_pool_destroy(pool) == 0); } -static void test_timeout_pool_free(void) +static void timer_test_timeout_pool_free(void) { odp_pool_t pool; odp_timeout_t tmo; @@ -104,7 +105,7 @@ static void test_timeout_pool_free(void) .type = ODP_POOL_TIMEOUT, }; - pool = odp_pool_create("timeout_pool_free", ODP_SHM_NULL, ¶ms); + pool = odp_pool_create("timeout_pool_free", ¶ms); odp_pool_print(pool); /* Allocate the only timeout from the pool */ @@ -124,7 +125,7 @@ static void test_timeout_pool_free(void) CU_ASSERT(odp_pool_destroy(pool) == 0); } -static void test_odp_timer_cancel(void) +static void timer_test_odp_timer_cancel(void) { odp_pool_t pool; odp_pool_param_t params; @@ -139,7 +140,7 @@ static void test_odp_timer_cancel(void) params.tmo.num = 1; params.type = ODP_POOL_TIMEOUT; - pool = odp_pool_create("tmo_pool_for_cancel", ODP_SHM_NULL, ¶ms); + pool = odp_pool_create("tmo_pool_for_cancel", ¶ms); if (pool == ODP_POOL_INVALID) CU_FAIL_FATAL("Timeout pool create failed"); @@ -225,25 +226,25 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick) if (tim == ODP_TIMER_INVALID) CU_FAIL("odp_timeout_timer() invalid timer"); - if (ttp == NULL) + if (!ttp) CU_FAIL("odp_timeout_user_ptr() null user ptr"); - if (ttp != NULL && ttp->ev2 != ev) + if (ttp && ttp->ev2 != ev) CU_FAIL("odp_timeout_user_ptr() wrong user ptr"); - if (ttp != NULL && ttp->tim != tim) + if (ttp && ttp->tim != tim) CU_FAIL("odp_timeout_timer() wrong timer"); if (stale) { if (odp_timeout_fresh(tmo)) CU_FAIL("Wrong status (fresh) for stale timeout"); /* Stale timeout => local timer must have invalid tick */ - if (ttp != NULL && ttp->tick != TICK_INVALID) + if (ttp && ttp->tick != TICK_INVALID) CU_FAIL("Stale timeout for active timer"); } else { if (!odp_timeout_fresh(tmo)) CU_FAIL("Wrong status (stale) for fresh timeout"); /* Fresh timeout => local timer must have matching tick */ - if (ttp != NULL && ttp->tick != tick) { - LOG_DBG("Wrong tick: expected %"PRIu64" actual %"PRIu64"\n", + if (ttp && ttp->tick != tick) { + LOG_DBG("Wrong tick: expected %" PRIu64 " actual %" PRIu64 "\n", ttp->tick, tick); CU_FAIL("odp_timeout_tick() wrong tick"); } @@ -251,14 +252,14 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick) if (tick > odp_timer_current_tick(tp)) CU_FAIL("Timeout delivered early"); if (tick < prev_tick) { - LOG_DBG("Too late tick: %"PRIu64" prev_tick %"PRIu64"\n", + LOG_DBG("Too late tick: %" PRIu64 " prev_tick %" PRIu64"\n", tick, prev_tick); /* We don't report late timeouts using CU_FAIL */ odp_atomic_inc_u32(&ndelivtoolate); } } - if (ttp != NULL) { + if (ttp) { /* Internal error */ CU_ASSERT_FATAL(ttp->ev == ODP_EVENT_INVALID); ttp->ev = ev; @@ -281,7 +282,7 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) CU_FAIL_FATAL("Queue create failed"); struct test_timer *tt = malloc(sizeof(struct test_timer) * NTIMERS); - if (tt == NULL) + if (!tt) CU_FAIL_FATAL("malloc failed"); /* Prepare all timers */ @@ -322,6 +323,7 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) uint32_t ntoolate = 0; uint32_t ms; uint64_t prev_tick = odp_timer_current_tick(tp); + for (ms = 0; ms < 7 * RANGE_MS / 10; ms++) { odp_event_t ev; while ((ev = odp_queue_deq(queue)) != ODP_EVENT_INVALID) { @@ -365,9 +367,10 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) } else if (rc != ODP_TIMER_SUCCESS) { /* Set/reset failed, timer already expired */ ntoolate++; + } else if (rc == ODP_TIMER_SUCCESS) { + /* Save expected expiration tick on success */ + tt[i].tick = cur_tick + tck; } - /* Save expected expiration tick */ - tt[i].tick = cur_tick + tck; } struct timespec ts; ts.tv_sec = 0; @@ -389,13 +392,13 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) CU_FAIL("odp_timer_free"); } - LOG_DBG("Thread %u: %"PRIu32" timers set\n", thr, nset); - LOG_DBG("Thread %u: %"PRIu32" timers reset\n", thr, nreset); - LOG_DBG("Thread %u: %"PRIu32" timers cancelled\n", thr, ncancel); - LOG_DBG("Thread %u: %"PRIu32" timers reset/cancelled too late\n", + LOG_DBG("Thread %u: %" PRIu32 " timers set\n", thr, nset); + LOG_DBG("Thread %u: %" PRIu32 " timers reset\n", thr, nreset); + LOG_DBG("Thread %u: %" PRIu32 " timers cancelled\n", thr, ncancel); + LOG_DBG("Thread %u: %" PRIu32 " timers reset/cancelled too late\n", thr, ntoolate); - LOG_DBG("Thread %u: %"PRIu32" timeouts received\n", thr, nrcv); - LOG_DBG("Thread %u: %"PRIu32" stale timeout(s) after odp_timer_free()\n", + LOG_DBG("Thread %u: %" PRIu32 " timeouts received\n", thr, nrcv); + LOG_DBG("Thread %u: %" PRIu32 " stale timeout(s) after odp_timer_free()\n", thr, nstale); /* Delay some more to ensure timeouts for expired timers can be @@ -433,7 +436,7 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) } /* @private Timer test case entrypoint */ -static void test_odp_timer_all(void) +static void timer_test_odp_timer_all(void) { int rc; odp_pool_param_t params; @@ -449,7 +452,7 @@ static void test_odp_timer_all(void) /* Create timeout pools */ params.tmo.num = (NTIMERS + 1) * num_workers; params.type = ODP_POOL_TIMEOUT; - tbp = odp_pool_create("tmo_pool", ODP_SHM_NULL, ¶ms); + tbp = odp_pool_create("tmo_pool", ¶ms); if (tbp == ODP_POOL_INVALID) CU_FAIL_FATAL("Timeout pool create failed"); @@ -481,7 +484,7 @@ static void test_odp_timer_all(void) CU_ASSERT(strcmp(tpinfo.name, NAME) == 0); LOG_DBG("#timers..: %u\n", NTIMERS); - LOG_DBG("Tmo range: %u ms (%"PRIu64" ticks)\n", RANGE_MS, + LOG_DBG("Tmo range: %u ms (%" PRIu64 " ticks)\n", RANGE_MS, odp_timer_ns_to_tick(tp, 1000000ULL * RANGE_MS)); uint64_t tick; @@ -506,7 +509,7 @@ static void test_odp_timer_all(void) /* Wait for worker threads to exit */ odp_cunit_thread_exit(&thrdarg); - LOG_DBG("Number of timeouts delivered/received too late: %"PRIu32"\n", + LOG_DBG("Number of timeouts delivered/received too late: %" PRIu32 "\n", odp_atomic_load_u32(&ndelivtoolate)); /* Check some statistics after the test */ @@ -526,15 +529,20 @@ static void test_odp_timer_all(void) CU_PASS("ODP timer test"); } -CU_TestInfo test_odp_timer[] = { - {"test_timeout_pool_alloc", test_timeout_pool_alloc}, - {"test_timeout_pool_free", test_timeout_pool_free}, - {"test_odp_timer_cancel", test_odp_timer_cancel}, - {"test_odp_timer_all", test_odp_timer_all}, +static CU_TestInfo timer_suite[] = { + {"test_timeout_pool_alloc", timer_test_timeout_pool_alloc}, + {"test_timeout_pool_free", timer_test_timeout_pool_free}, + {"test_odp_timer_cancel", timer_test_odp_timer_cancel}, + {"test_odp_timer_all", timer_test_odp_timer_all}, CU_TEST_INFO_NULL, }; -CU_SuiteInfo odp_testsuites[] = { - {"Timer", NULL, NULL, NULL, NULL, test_odp_timer}, +static CU_SuiteInfo timer_suites[] = { + {"Timer", NULL, NULL, NULL, NULL, timer_suite}, CU_SUITE_INFO_NULL, }; + +int timer_main(void) +{ + return odp_cunit_run(timer_suites); +} diff --git a/test/validation/timer/timer.h b/test/validation/timer/timer.h new file mode 100644 index 000000000..5bdf9082a --- /dev/null +++ b/test/validation/timer/timer.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_TIMER_H_ +#define _ODP_TEST_TIMER_H_ + +int timer_main(void); + +#endif diff --git a/test/validation/timer/timer_main.c b/test/validation/timer/timer_main.c new file mode 100644 index 000000000..24eb77b95 --- /dev/null +++ b/test/validation/timer/timer_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "timer.h" + +int main(void) +{ + return timer_main(); +} diff --git a/test/validation/ver_abt_log_dbg/odp_system.c b/test/validation/ver_abt_log_dbg/odp_system.c deleted file mode 100644 index 1a40957e0..000000000 --- a/test/validation/ver_abt_log_dbg/odp_system.c +++ /dev/null @@ -1,94 +0,0 @@ -/* Copyright (c) 2014, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <ctype.h> -#include "odp.h" -#include "odp_cunit_common.h" -#include "test_debug.h" - -static void test_odp_version_numbers(void) -{ - int char_ok; - char version_string[128]; - char *s = version_string; - - strncpy(version_string, odp_version_api_str(), - sizeof(version_string)-1); - - while (*s) { - if (isdigit(*s) || (strncmp(s, ".", 1) == 0)) { - char_ok = 1; - s++; - } else { - char_ok = 0; - LOG_DBG("\nBAD VERSION=%s\n", version_string); - break; - } - } - CU_ASSERT(char_ok); -} - -static void test_odp_cpu_count(void) -{ - int cpus; - - cpus = odp_cpu_count(); - CU_ASSERT(0 < cpus); -} - -static void test_odp_sys_cache_line_size(void) -{ - uint64_t cache_size; - - cache_size = odp_sys_cache_line_size(); - CU_ASSERT(0 < cache_size); - CU_ASSERT(ODP_CACHE_LINE_SIZE == cache_size); -} - -static void test_odp_sys_cpu_model_str(void) -{ - char model[128]; - - snprintf(model, 128, "%s", odp_sys_cpu_model_str()); - CU_ASSERT(strlen(model) > 0); - CU_ASSERT(strlen(model) < 127); -} - -static void test_odp_sys_page_size(void) -{ - uint64_t page; - - page = odp_sys_page_size(); - CU_ASSERT(0 < page); - CU_ASSERT(ODP_PAGE_SIZE == page); -} - -static void test_odp_sys_huge_page_size(void) -{ - uint64_t page; - - page = odp_sys_huge_page_size(); - CU_ASSERT(0 < page); -} - -static void test_odp_sys_cpu_hz(void) -{ - uint64_t hz; - - hz = odp_sys_cpu_hz(); - CU_ASSERT(0 < hz); -} - -CU_TestInfo test_odp_system[] = { - {"odp version", test_odp_version_numbers}, - {"odp_cpu_count", test_odp_cpu_count}, - {"odp_sys_cache_line_size", test_odp_sys_cache_line_size}, - {"odp_sys_cpu_model_str", test_odp_sys_cpu_model_str}, - {"odp_sys_page_size", test_odp_sys_page_size}, - {"odp_sys_huge_page_size", test_odp_sys_huge_page_size}, - {"odp_sys_cpu_hz", test_odp_sys_cpu_hz}, - CU_TEST_INFO_NULL, -}; diff --git a/test/validation/ver_abt_log_dbg/odp_ver_abt_log_dbg.c b/test/validation/ver_abt_log_dbg/odp_ver_abt_log_dbg.c deleted file mode 100644 index 39a632e7a..000000000 --- a/test/validation/ver_abt_log_dbg/odp_ver_abt_log_dbg.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <odp.h> -#include "odp_cunit_common.h" -#include "odp_errno.h" -#include "odp_system.h" - -CU_SuiteInfo odp_testsuites[] = { - {"Errno", NULL, NULL, NULL, NULL, test_odp_errno}, - {"System Info", NULL, NULL, NULL, NULL, test_odp_system}, - CU_SUITE_INFO_NULL, -}; |