diff --git a/include/linker/common-ram.ld b/include/linker/common-ram.ld index 81949ea0daa1..62876dc2e9b1 100644 --- a/include/linker/common-ram.ld +++ b/include/linker/common-ram.ld @@ -143,4 +143,6 @@ #if defined(CONFIG_ZTEST) ITERABLE_SECTION_RAM(ztest_suite_node, 4) + ITERABLE_SECTION_RAM(ztest_unit_test, 4) + ITERABLE_SECTION_RAM(ztest_test_rule, 4) #endif /* CONFIG_ZTEST */ diff --git a/samples/subsys/testsuite/integration/src/main.c b/samples/subsys/testsuite/integration/src/main.c index c18541f70758..60a15b4a10d8 100644 --- a/samples/subsys/testsuite/integration/src/main.c +++ b/samples/subsys/testsuite/integration/src/main.c @@ -6,13 +6,16 @@ #include + +ZTEST_SUITE(framework_tests, NULL, NULL, NULL, NULL, NULL); + /** * @brief Test Asserts * * This test verifies various assert macros provided by ztest. * */ -static void test_assert(void) +ZTEST(framework_tests, test_assert) { zassert_true(1, "1 was false"); zassert_false(0, "0 was true"); @@ -21,12 +24,3 @@ static void test_assert(void) zassert_equal(1, 1, "1 was not equal to 1"); zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL"); } - -void test_main(void) -{ - ztest_test_suite(framework_tests, - ztest_unit_test(test_assert) - ); - - ztest_run_test_suite(framework_tests); -} diff --git a/samples/subsys/testsuite/pytest/src/main.c b/samples/subsys/testsuite/pytest/src/main.c index dfb6085e9c6d..4d4f396ff024 100644 --- a/samples/subsys/testsuite/pytest/src/main.c +++ b/samples/subsys/testsuite/pytest/src/main.c @@ -4,16 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ #include -void test_pytest(void) -{ - TC_PRINT("Hello world\n"); -} -void test_main(void) -{ - ztest_test_suite(test_pytest, - ztest_unit_test(test_pytest) - ); +ZTEST_SUITE(test_pytest, NULL, NULL, NULL, NULL, NULL); - ztest_run_test_suite(test_pytest); +ZTEST(test_pytest, test_pytest) +{ + TC_PRINT("Hello world\n"); } diff --git a/subsys/testsuite/include/ztest.ld b/subsys/testsuite/include/ztest.ld index 7012c8ee0646..14de5a897fcc 100644 --- a/subsys/testsuite/include/ztest.ld +++ b/subsys/testsuite/include/ztest.ld @@ -12,5 +12,17 @@ SECTIONS KEEP(*(SORT_BY_NAME(._ztest_suite_node.static.*))) _ztest_suite_node_list_end = .; } + .data.ztest_unit_test_area : ALIGN(4) + { + _ztest_unit_test_list_start = .; + KEEP(*(SORT_BY_NAME(._ztest_unit_test.static.*))) + _ztest_unit_test_list_end = .; + } + .data.ztest_test_rule_area : ALIGN(4) + { + _ztest_test_rule_list_start = .; + KEEP(*(SORT_BY_NAME(._ztest_test_rule.static.*))) + _ztest_test_rule_list_end = .; + } } INSERT AFTER .data; diff --git a/subsys/testsuite/ztest/CMakeLists.txt b/subsys/testsuite/ztest/CMakeLists.txt index 566c7b2f6731..db3830f7bbe7 100644 --- a/subsys/testsuite/ztest/CMakeLists.txt +++ b/subsys/testsuite/ztest/CMakeLists.txt @@ -8,4 +8,5 @@ zephyr_include_directories( zephyr_library() zephyr_library_sources( src/ztest.c) zephyr_library_sources( src/ztest_error_hook.c) +zephyr_library_sources( src/ztest_rules.c) zephyr_library_sources_ifdef(CONFIG_ZTEST_MOCKING src/ztest_mock.c) diff --git a/subsys/testsuite/ztest/Kconfig b/subsys/testsuite/ztest/Kconfig index 53fe8c33b455..29089cffb7df 100644 --- a/subsys/testsuite/ztest/Kconfig +++ b/subsys/testsuite/ztest/Kconfig @@ -73,6 +73,16 @@ config ZTEST_ASSERT_HOOK error test case. Remember to add ignore_fault tag in yaml file when using twister to run testing. +menu "ztest provided rules" + +config ZTEST_RULE_1CPU + bool "Run all the tests on a single CPU" + help + This rule will call z_test_1cpu_start before each unit test and + ztest_1cpu_stop after each test. + +endmenu + endif # ZTEST config ZTEST_MOCKING diff --git a/subsys/testsuite/ztest/include/ztest_test.h b/subsys/testsuite/ztest/include/ztest_test.h index 8e3e8b10d046..eb99133c02a8 100644 --- a/subsys/testsuite/ztest/include/ztest_test.h +++ b/subsys/testsuite/ztest/include/ztest_test.h @@ -21,14 +21,16 @@ extern "C" { #endif -struct unit_test { +struct ztest_unit_test { + const char *test_suite_name; const char *name; - void (*test)(void); - void (*setup)(void); - void (*teardown)(void); + void (*test)(void *data); uint32_t thread_options; }; +extern struct ztest_unit_test _ztest_unit_test_list_start[]; +extern struct ztest_unit_test _ztest_unit_test_list_end[]; + /** * Stats about a ztest suite */ @@ -43,13 +45,35 @@ struct ztest_suite_stats { /** * A single node of test suite. Each node should be added to a single linker section which will - * allow ztest_run_registered_test_suites() to iterate over the various nodes. + * allow ztest_run_test_suites() to iterate over the various nodes. */ struct ztest_suite_node { /** The name of the test suite. */ const char *name; - /** Pointer to the test suite. */ - struct unit_test *suite; + /** + * Setup function to run before running this suite + * + * @return Pointer to the data structure that will be used throughout this test suite + */ + void *(*setup)(void); + /** + * Function to run before each test in this suite + * + * @param data The test suite's data returned from setup() + */ + void (*before)(void *data); + /** + * Function to run after each test in this suite + * + * @param data The test suite's data returned from setup() + */ + void (*after)(void *data); + /** + * Teardown function to run after running this suite + * + * @param data The test suite's data returned from setup() + */ + void (*teardown)(void *data); /** * An optional predicate function to determine if the test should run. If NULL, then the * test will only run once on the first attempt. @@ -69,20 +93,25 @@ extern struct ztest_suite_node _ztest_suite_node_list_end[]; * Create and register a ztest suite. Using this macro creates a new test suite (using * ztest_test_suite). It then creates a struct ztest_suite_node in a specific linker section. * - * Tests can then be run by calling ztest_run_registered_test_suites(const void *state) by passing - * in the current state. See the documentation for ztest_run_registered_test_suites for more info. + * Tests can then be run by calling ztest_run_test_suites(const void *state) by passing + * in the current state. See the documentation for ztest_run_test_suites for more info. * * @param SUITE_NAME The name of the suite (see ztest_test_suite for more info) * @param PREDICATE A function to test against the state and determine if the test should run. - * @param args Varargs placeholder for the remaining arguments passed for the unit tests. + * @param setup_fn The setup function to call before running this test suite + * @param before_fn The function to call before each unit test in this suite + * @param after_fn The function to call after each unit test in this suite + * @param teardown_fn The function to call after running all the tests in this suite */ -#define ztest_register_test_suite(SUITE_NAME, PREDICATE, args...) \ - ztest_test_suite(SUITE_NAME, ##args); \ +#define ZTEST_SUITE(SUITE_NAME, PREDICATE, setup_fn, before_fn, after_fn, teardown_fn) \ static STRUCT_SECTION_ITERABLE(ztest_suite_node, z_ztest_test_node_##SUITE_NAME) = { \ .name = #SUITE_NAME, \ - .suite = _##SUITE_NAME, \ + .setup = (setup_fn), \ + .before = (before_fn), \ + .after = (after_fn), \ + .teardown = (teardown_fn), \ .predicate = PREDICATE, \ - }; + } /** * Run the registered unit tests which return true from their pragma function. @@ -90,7 +119,7 @@ extern struct ztest_suite_node _ztest_suite_node_list_end[]; * @param state The current state of the machine as it relates to the test executable. * @return The number of tests that ran. */ -int ztest_run_registered_test_suites(const void *state); +int ztest_run_test_suites(const void *state); /** * @brief Fails the test if any of the registered tests did not run. @@ -101,7 +130,7 @@ int ztest_run_registered_test_suites(const void *state); * may be called at the end of test_main(). It will cause the test to fail if any suite was * registered but never ran. */ -void ztest_verify_all_registered_test_suites_ran(void); +void ztest_verify_all_test_suites_ran(void); /** * @brief Run a test suite. @@ -110,10 +139,9 @@ void ztest_verify_all_registered_test_suites_ran(void); * checks for fast failures and initialization. * * @param name The name of the suite to run. - * @param suite Pointer to the first unit test. * @return Negative value if the test suite never ran; otherwise, return the number of failures. */ -int z_ztest_run_test_suite(const char *name, struct unit_test *suite); +int z_ztest_run_test_suite(const char *name); /** * @defgroup ztest_test Ztest testing macros @@ -160,79 +188,111 @@ static inline void unit_test_noop(void) { } -/** - * @brief Define a test with setup and teardown functions - * - * This should be called as an argument to ztest_test_suite. The test will - * be run in the following order: @a setup, @a fn, @a teardown. - * - * @param fn Main test function - * @param setup Setup function - * @param teardown Teardown function - */ +#define Z_ZTEST(suite, fn, t_options) \ + static void _##suite##_##fn##_wrapper(void *data); \ + static void suite##_##fn(void); \ + static STRUCT_SECTION_ITERABLE(ztest_unit_test, z_ztest_unit_test_##suite##_##fn) = { \ + .test_suite_name = STRINGIFY(suite), \ + .name = STRINGIFY(fn), \ + .test = (_##suite##_##fn##_wrapper), \ + .thread_options = t_options, \ + }; \ + static void _##suite##_##fn##_wrapper(void *data) \ + { \ + ARG_UNUSED(data); \ + suite##_##fn(); \ + } \ + static inline void suite##_##fn(void) + +#define Z_ZTEST_F(suite, fn, t_options) \ + static void _##suite##_##fn##_wrapper(void *data); \ + static void suite##_##fn(struct suite##_fixture *this); \ + static STRUCT_SECTION_ITERABLE(ztest_unit_test, z_ztest_unit_test_##suite##_##fn) = { \ + .test_suite_name = STRINGIFY(suite), \ + .name = STRINGIFY(fn), \ + .test = (_##suite##_##fn##_wrapper), \ + .thread_options = t_options, \ + }; \ + static void _##suite##_##fn##_wrapper(void *data) \ + { \ + suite##_##fn((struct suite##_fixture *)data); \ + } \ + static inline void suite##_##fn(struct suite##_fixture *this) + +#define ZTEST(suite, fn) Z_ZTEST(suite, fn, 0) -#define ztest_unit_test_setup_teardown(fn, setup, teardown) { \ - STRINGIFY(fn), fn, setup, teardown, 0 \ -} - -/** - * @brief Define a user mode test with setup and teardown functions - * - * This should be called as an argument to ztest_test_suite. The test will - * be run in the following order: @a setup, @a fn, @a teardown. ALL - * test functions will be run in user mode, and only if CONFIG_USERSPACE - * is enabled, otherwise this is the same as ztest_unit_test_setup_teardown(). - * - * @param fn Main test function - * @param setup Setup function - * @param teardown Teardown function - */ +#ifdef CONFIG_USERSPACE +#define ZTEST_USER(suite, fn) Z_ZTEST(suite, fn, K_USER) +#else +#define ZTEST_USER(suite, fn) \ + BUILD_ASSERT(false, "Can't create userspace test without CONFIG_USERSPACE being enabled") +#endif -#define ztest_user_unit_test_setup_teardown(fn, setup, teardown) { \ - STRINGIFY(fn), fn, setup, teardown, K_USER \ -} +#define ZTEST_AUTOSPACE(suite, fn) Z_ZTEST(suite, fn, COND_VAR_1(CONFIG_USERSPACE, (K_USER), (0))) /** * @brief Define a test function * - * This should be called as an argument to ztest_test_suite. - * + * @param suite The test suite to attach this function to * @param fn Test function */ - -#define ztest_unit_test(fn) \ - ztest_unit_test_setup_teardown(fn, unit_test_noop, unit_test_noop) +#define ZTEST_F(suite, fn) Z_ZTEST_F(suite, fn, 0) /** * @brief Define a test function that should run as a user thread * - * This should be called as an argument to ztest_test_suite. * If CONFIG_USERSPACE is not enabled, this is functionally identical to * ztest_unit_test(). * + * @param suite The test suite to attach this function to * @param fn Test function */ +#ifdef CONFIG_USERSPACE +#define ZTEST_USER_F(suite, fn) Z_ZTEST_F(suite, fn, K_USER) +#else +#define ZTEST_USER_F(suite, fn) \ + BUILD_ASSERT(false, "Can't create userspace test without CONFIG_USERSPACE being enabled") +#endif + +#define ZTEST_AUTOSPACE_F(suite, fn) \ + Z_ZTEST_F(suite, fn, COND_VAR_1(CONFIG_USERSPACE, (K_USER), (0))) + +typedef void (*ztest_rule_cb)(const struct ztest_unit_test *test, void *data); -#define ztest_user_unit_test(fn) \ - ztest_user_unit_test_setup_teardown(fn, unit_test_noop, unit_test_noop) +struct ztest_test_rule { + ztest_rule_cb before_each; + ztest_rule_cb after_each; +}; + +#define ZTEST_RULE(name, before_each_fn, after_each_fn) \ + static STRUCT_SECTION_ITERABLE(ztest_test_rule, z_ztest_test_rule_##name) = { \ + .before_each = (before_each_fn), \ + .after_each = (after_each_fn), \ + } + +extern struct ztest_test_rule _ztest_test_rule_list_start[]; +extern struct ztest_test_rule _ztest_test_rule_list_end[]; __syscall void z_test_1cpu_start(void); __syscall void z_test_1cpu_stop(void); /** - * @brief Define a SMP-unsafe test function + * @brief A 'before' function to use in test suites that just need to start 1cpu * - * As ztest_unit_test(), but ensures all test code runs on only - * one CPU when in SMP. + * Ignores data, and calls z_test_1cpu_start() * - * @param fn Test function + * @param data The test suite's data */ -#ifdef CONFIG_SMP -#define ztest_1cpu_unit_test(fn) \ - ztest_unit_test_setup_teardown(fn, z_test_1cpu_start, z_test_1cpu_stop) -#else -#define ztest_1cpu_unit_test(fn) ztest_unit_test(fn) -#endif +void ztest_simple_1cpu_before(void *data); + +/** + * @brief A 'after' function to use in test suites that just need to stop 1cpu + * + * Ignores data, and calls z_test_1cpu_stop() + * + * @param data The test suite's data + */ +void ztest_simple_1cpu_after(void *data); /** * @brief Define a SMP-unsafe test function that should run as a user thread @@ -242,12 +302,15 @@ __syscall void z_test_1cpu_stop(void); * * @param fn Test function */ +// TODO(yperess) These should be test suites with before/after functions +/* #ifdef CONFIG_SMP #define ztest_1cpu_user_unit_test(fn) \ ztest_user_unit_test_setup_teardown(fn, z_test_1cpu_start, z_test_1cpu_stop) #else #define ztest_1cpu_user_unit_test(fn) ztest_user_unit_test(fn) #endif +*/ /* definitions for use with testing application shared memory */ #ifdef CONFIG_USERSPACE @@ -261,32 +324,13 @@ extern struct k_mem_partition ztest_mem_partition; #define ZTEST_SECTION .data #endif -/** - * @brief Define a test suite - * - * This function should be called in the following fashion: - * ```{.c} - * ztest_test_suite(test_suite_name, - * ztest_unit_test(test_function), - * ztest_unit_test(test_other_function) - * ); - * - * ztest_run_test_suite(test_suite_name); - * ``` - * - * @param suite Name of the testing suite - */ -#define ztest_test_suite(suite, ...) \ - static ZTEST_DMEM struct unit_test _##suite[] = { \ - __VA_ARGS__, { 0 } \ - } /** * @brief Run the specified test suite. * * @param suite Test suite to run. */ #define ztest_run_test_suite(suite) \ - z_ztest_run_test_suite(#suite, _##suite) + z_ztest_run_test_suite(STRINGIFY(suite)) /** * @} diff --git a/subsys/testsuite/ztest/src/ztest.c b/subsys/testsuite/ztest/src/ztest.c index 2bd75e197946..1cdfa49e4e2b 100644 --- a/subsys/testsuite/ztest/src/ztest.c +++ b/subsys/testsuite/ztest/src/ztest.c @@ -24,7 +24,9 @@ static struct k_thread ztest_thread; ZTEST_DMEM enum { TEST_PHASE_SETUP, + TEST_PHASE_BEFORE, TEST_PHASE_TEST, + TEST_PHASE_AFTER, TEST_PHASE_TEARDOWN, TEST_PHASE_FRAMEWORK } phase = TEST_PHASE_FRAMEWORK; @@ -56,7 +58,7 @@ const char *ztest_relative_filename(const char *file) return file; } -static int cleanup_test(struct unit_test *test) +static int cleanup_test(struct ztest_unit_test *test) { int ret = TC_PASS; int mock_status; @@ -198,12 +200,28 @@ void z_vrfy_z_test_1cpu_stop(void) #endif /* CONFIG_USERSPACE */ #endif -static void run_test_functions(struct unit_test *test) +static void run_test_rules(bool is_before, struct ztest_unit_test *test, void *data) { - phase = TEST_PHASE_SETUP; - test->setup(); + for (struct ztest_test_rule *rule = _ztest_test_rule_list_start; + rule < _ztest_test_rule_list_end; ++rule) { + if (is_before && rule->before_each) { + rule->before_each(test, data); + } else if (!is_before && rule->after_each) { + rule->after_each(test, data); + } + } +} + +static void run_test_functions(struct ztest_suite_node *suite, struct ztest_unit_test *test, + void *data) +{ + phase = TEST_PHASE_BEFORE; + if (suite->before) { + suite->before(data); + } + run_test_rules(/*is_before=*/true, test, data); phase = TEST_PHASE_TEST; - test->test(); + test->test(data); } #ifndef KERNEL @@ -246,7 +264,9 @@ static void handle_signal(int sig) PRINT(" %s", strsignal(sig)); switch (phase) { case TEST_PHASE_SETUP: + case TEST_PHASE_BEFORE: case TEST_PHASE_TEST: + case TEST_PHASE_AFTER: case TEST_PHASE_TEARDOWN: PRINT(" at %s function\n", phase_str[phase]); longjmp(test_fail, 1); @@ -267,7 +287,7 @@ static void init_testing(void) } } -static int run_test(struct unit_test *test) +static int run_test(struct ztest_suite_node *suite, struct ztest_unit_test *test, void *data) { int ret = TC_PASS; @@ -283,7 +303,7 @@ static int run_test(struct unit_test *test) goto out; } - run_test_functions(test); + run_test_functions(suite, test, data); out: ret |= cleanup_test(test); Z_TC_END_RESULT(ret, test->name); @@ -302,8 +322,7 @@ static int run_test(struct unit_test *test) #define FAIL_FAST 0 #endif -K_THREAD_STACK_DEFINE(ztest_thread_stack, CONFIG_ZTEST_STACKSIZE + - CONFIG_TEST_EXTRA_STACKSIZE); +K_THREAD_STACK_DEFINE(ztest_thread_stack, CONFIG_ZTEST_STACKSIZE + CONFIG_TEST_EXTRA_STACKSIZE); static ZTEST_BMEM int test_result; static void test_finalize(void) @@ -332,24 +351,34 @@ void ztest_test_skip(void) test_finalize(); } +void ztest_simple_1cpu_before(void *data) +{ + ARG_UNUSED(data); + z_test_1cpu_start(); +} + +void ztest_simple_1cpu_after(void *data) +{ + ARG_UNUSED(data); + z_test_1cpu_stop(); +} + static void init_testing(void) { k_object_access_all_grant(&ztest_thread); } -static void test_cb(void *a, void *dummy2, void *dummy) +static void test_cb(void *a, void *b, void *c) { - struct unit_test *test = (struct unit_test *)a; - - ARG_UNUSED(dummy2); - ARG_UNUSED(dummy); + struct ztest_suite_node *suite = a; + struct ztest_unit_test *test = b; test_result = 1; - run_test_functions(test); + run_test_functions(suite, test, c); test_result = 0; } -static int run_test(struct unit_test *test) +static int run_test(struct ztest_suite_node *suite, struct ztest_unit_test *test, void *data) { int ret = TC_PASS; @@ -358,10 +387,9 @@ static int run_test(struct unit_test *test) if (IS_ENABLED(CONFIG_MULTITHREADING)) { k_thread_create(&ztest_thread, ztest_thread_stack, K_THREAD_STACK_SIZEOF(ztest_thread_stack), - (k_thread_entry_t) test_cb, (struct unit_test *)test, - NULL, NULL, CONFIG_ZTEST_THREAD_PRIORITY, - test->thread_options | K_INHERIT_PERMS, - K_FOREVER); + (k_thread_entry_t)test_cb, suite, test, data, + CONFIG_ZTEST_THREAD_PRIORITY, + test->thread_options | K_INHERIT_PERMS, K_FOREVER); if (test->name != NULL) { k_thread_name_set(&ztest_thread, test->name); @@ -370,11 +398,14 @@ static int run_test(struct unit_test *test) k_thread_join(&ztest_thread, K_FOREVER); } else { test_result = 1; - run_test_functions(test); + run_test_functions(suite, test, data); } - phase = TEST_PHASE_TEARDOWN; - test->teardown(); + phase = TEST_PHASE_AFTER; + if (suite->after != NULL) { + suite->after(data); + } + run_test_rules(/*is_before=*/false, test, data); phase = TEST_PHASE_FRAMEWORK; if (test_result == -1) { @@ -396,32 +427,76 @@ static int run_test(struct unit_test *test) #endif /* !KERNEL */ -int z_ztest_run_test_suite(const char *name, struct unit_test *suite) +static struct ztest_suite_node *ztest_find_test_suite(const char *name) { + struct ztest_suite_node *node; + + for (node = _ztest_suite_node_list_start; node < _ztest_suite_node_list_end; ++node) { + if (strcmp(name, node->name) == 0) { + return node; + } + } + + return NULL; +} + +struct ztest_unit_test *ztest_get_next_test(const char *suite, struct ztest_unit_test *prev) +{ + struct ztest_unit_test *test = (prev == NULL) ? _ztest_unit_test_list_start : prev + 1; + + for (; test < _ztest_unit_test_list_end; ++test) { + if (strcmp(suite, test->test_suite_name) == 0) { + return test; + } + } + return NULL; +} + +static int z_ztest_run_test_suite_ptr(struct ztest_suite_node *suite) +{ + struct ztest_unit_test *test = NULL; + void *data = NULL; int fail = 0; if (test_status < 0) { return test_status; } + if (suite == NULL) { + test_status = 1; + return -1; + } + init_testing(); - TC_SUITE_START(name); - while (suite->test) { - fail += run_test(suite); - suite++; + TC_SUITE_START(suite->name); + phase = TEST_PHASE_SETUP; + if (suite->setup != NULL) { + data = suite->setup(); + } + while ((test = ztest_get_next_test(suite->name, test)) != NULL) { + fail += run_test(suite, test, data); if (fail && FAIL_FAST) { break; } } - TC_SUITE_END(name, (fail > 0 ? TC_FAIL : TC_PASS)); + TC_SUITE_END(suite->name, (fail > 0 ? TC_FAIL : TC_PASS)); + phase = TEST_PHASE_TEARDOWN; + if (suite->teardown != NULL) { + suite->teardown(data); + } test_status = (test_status || fail) ? 1 : 0; return fail; } +int z_ztest_run_test_suite(const char *name) +{ + return z_ztest_run_test_suite_ptr(ztest_find_test_suite(name)); +} + void end_report(void) { if (test_status) { @@ -435,7 +510,7 @@ void end_report(void) K_APPMEM_PARTITION_DEFINE(ztest_mem_partition); #endif -int ztest_run_registered_test_suites(const void *state) +int ztest_run_test_suites(const void *state) { struct ztest_suite_node *ptr; int count = 0; @@ -447,12 +522,12 @@ int ztest_run_registered_test_suites(const void *state) if (ptr->predicate != NULL) { should_run = ptr->predicate(state); } else { - /* If pragma is NULL, only run this test once. */ + /* If predicate is NULL, only run this test once. */ should_run = stats->run_count == 0; } if (should_run) { - int fail = z_ztest_run_test_suite(ptr->name, ptr->suite); + int fail = z_ztest_run_test_suite_ptr(ptr); count++; stats->run_count++; @@ -465,7 +540,7 @@ int ztest_run_registered_test_suites(const void *state) return count; } -void ztest_verify_all_registered_test_suites_ran(void) +void ztest_verify_all_test_suites_ran(void) { bool all_tests_run = true; struct ztest_suite_node *ptr; @@ -484,8 +559,8 @@ void ztest_verify_all_registered_test_suites_ran(void) void __weak test_main(void) { - ztest_run_registered_test_suites(NULL); - ztest_verify_all_registered_test_suites_ran(); + ztest_run_test_suites(NULL); + ztest_verify_all_test_suites_ran(); } #ifndef KERNEL diff --git a/subsys/testsuite/ztest/src/ztest_rules.c b/subsys/testsuite/ztest/src/ztest_rules.c new file mode 100644 index 000000000000..90c5531e1e79 --- /dev/null +++ b/subsys/testsuite/ztest/src/ztest_rules.c @@ -0,0 +1,23 @@ +/* + * Copyright 2021 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#ifdef CONFIG_ZTEST_RULE_1CPU +static void one_cpu_rule_before_each(const struct ztest_unit_test *test, void *data) +{ + ARG_UNUSED(test); + ARG_UNUSED(data); + z_test_1cpu_start(); +} +static void one_cpu_rule_after_each(const struct ztest_unit_test *test, void *data) +{ + ARG_UNUSED(test); + ARG_UNUSED(data); + z_test_1cpu_stop(); +} +ZTEST_RULE(one_cpu, one_cpu_rule_before_each, one_cpu_rule_after_each); +#endif /* CONFIG_ZTEST_RULE_1CPU */ diff --git a/tests/application_development/gen_inc_file/src/main.c b/tests/application_development/gen_inc_file/src/main.c index 875f5e24a9d6..5109e48f17e7 100644 --- a/tests/application_development/gen_inc_file/src/main.c +++ b/tests/application_development/gen_inc_file/src/main.c @@ -74,7 +74,9 @@ static const unsigned char compressed_inc_file[] = { 0x8c, 0x05, 0x29, 0x00, 0x01, 0x00, 0x00, }; -static void test_gen_inc_file(void) +ZTEST_SUITE(gen_inc_file_test, NULL, NULL, NULL, NULL, NULL); + +ZTEST(gen_inc_file_test, test_gen_inc_file) { int i; @@ -109,7 +111,7 @@ static void do_test_gen_gz_inc_file(const unsigned char gz_inc_file[], } } -static void test_gen_gz_inc_file_no_mtime(void) +ZTEST(gen_inc_file_test, test_gen_gz_inc_file_no_mtime) { zassert_equal(sizeof(no_mtime_gz_inc_file), sizeof(compressed_inc_file), "Invalid compressed file size"); @@ -117,21 +119,10 @@ static void test_gen_gz_inc_file_no_mtime(void) do_test_gen_gz_inc_file(no_mtime_gz_inc_file, mtime_zero); } -static void test_gen_gz_inc_file_mtime_arg(void) +ZTEST(gen_inc_file_test, test_gen_gz_inc_file_mtime_arg) { zassert_equal(sizeof(mtime_gz_inc_file), sizeof(compressed_inc_file), "Invalid compressed file size"); do_test_gen_gz_inc_file(mtime_gz_inc_file, mtime_test_val); } - -void test_main(void) -{ - ztest_test_suite(gen_inc_file_test, - ztest_unit_test(test_gen_inc_file), - ztest_unit_test(test_gen_gz_inc_file_no_mtime), - ztest_unit_test(test_gen_gz_inc_file_mtime_arg) - ); - - ztest_run_test_suite(gen_inc_file_test); -} diff --git a/tests/arch/arm/arm_hardfault_validation/src/arm_hardfault.c b/tests/arch/arm/arm_hardfault_validation/src/arm_hardfault.c index 1cfdccffbbab..494c095f1c07 100644 --- a/tests/arch/arm/arm_hardfault_validation/src/arm_hardfault.c +++ b/tests/arch/arm/arm_hardfault_validation/src/arm_hardfault.c @@ -45,7 +45,8 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) expected_reason = -1; } -void test_arm_hardfault(void) + +ZTEST(arm_hardfault_validation, test_arm_hardfault) { expected_reason = K_ERR_KERNEL_PANIC; diff --git a/tests/arch/arm/arm_hardfault_validation/src/main.c b/tests/arch/arm/arm_hardfault_validation/src/main.c index a4e51ae91fca..bd1e59cb487a 100644 --- a/tests/arch/arm/arm_hardfault_validation/src/main.c +++ b/tests/arch/arm/arm_hardfault_validation/src/main.c @@ -5,12 +5,5 @@ */ #include -extern void test_arm_hardfault(void); -/**test case main entry*/ -void test_main(void) -{ - ztest_test_suite(arm_hardfault_validation, - ztest_unit_test(test_arm_hardfault)); - ztest_run_test_suite(arm_hardfault_validation); -} +ZTEST_SUITE(arm_hardfault_validation, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_interrupt/src/arm_interrupt.c b/tests/arch/arm/arm_interrupt/src/arm_interrupt.c index 5e44535b1517..f9e3a56262ef 100644 --- a/tests/arch/arm/arm_interrupt/src/arm_interrupt.c +++ b/tests/arch/arm/arm_interrupt/src/arm_interrupt.c @@ -151,7 +151,7 @@ void set_regs_with_known_pattern(void) ); } -void test_arm_esf_collection(void) +ZTEST(arm_interrupt, test_arm_esf_collection) { int test_validation_rv; @@ -227,8 +227,7 @@ void arm_isr_handler(const void *args) #endif } } - -void test_arm_interrupt(void) +ZTEST(arm_interrupt, test_arm_interrupt) { /* Determine an NVIC IRQ line that is not currently in use. */ int i; @@ -403,8 +402,7 @@ static inline void z_vrfy_test_arm_user_interrupt_syscall(void) z_impl_test_arm_user_interrupt_syscall(); } #include - -void test_arm_user_interrupt(void) +ZTEST_USER(arm_interrupt, test_arm_user_interrupt) { /* Test thread executing in user mode */ zassert_true(arch_is_user_context(), @@ -440,7 +438,7 @@ void test_arm_user_interrupt(void) #endif } #else -void test_arm_user_interrupt(void) +ZTEST_USER(arm_interrupt, test_arm_user_interrupt) { TC_PRINT("Skipped\n"); } @@ -450,7 +448,7 @@ void test_arm_user_interrupt(void) #pragma GCC push_options #pragma GCC optimize("O0") /* Avoid compiler optimizing null pointer de-referencing. */ -void test_arm_null_pointer_exception(void) +ZTEST(arm_interrupt, test_arm_null_pointer_exception) { int reason; @@ -471,7 +469,7 @@ void test_arm_null_pointer_exception(void) } #pragma GCC pop_options #else -void test_arm_null_pointer_exception(void) +ZTEST(arm_interrupt, test_arm_null_pointer_exception) { TC_PRINT("Skipped\n"); } diff --git a/tests/arch/arm/arm_interrupt/src/main.c b/tests/arch/arm/arm_interrupt/src/main.c index 75054f59a874..22fb1fb56915 100644 --- a/tests/arch/arm/arm_interrupt/src/main.c +++ b/tests/arch/arm/arm_interrupt/src/main.c @@ -6,17 +6,5 @@ #include -extern void test_arm_null_pointer_exception(void); -extern void test_arm_interrupt(void); -extern void test_arm_user_interrupt(void); -extern void test_arm_esf_collection(void); +ZTEST_SUITE(arm_interrupt, NULL, NULL, NULL, NULL, NULL); -void test_main(void) -{ - ztest_test_suite(arm_interrupt, - ztest_unit_test(test_arm_null_pointer_exception), - ztest_unit_test(test_arm_interrupt), - ztest_unit_test(test_arm_esf_collection), - ztest_user_unit_test(test_arm_user_interrupt)); - ztest_run_test_suite(arm_interrupt); -} diff --git a/tests/arch/arm/arm_irq_advanced_features/src/arm_dynamic_direct_interrupts.c b/tests/arch/arm/arm_irq_advanced_features/src/arm_dynamic_direct_interrupts.c index 0fa3c437b4f4..15918abbb04c 100644 --- a/tests/arch/arm/arm_irq_advanced_features/src/arm_dynamic_direct_interrupts.c +++ b/tests/arch/arm/arm_irq_advanced_features/src/arm_dynamic_direct_interrupts.c @@ -27,7 +27,7 @@ void arm_direct_isr_handler_1(const void *args) test_flag = 2; } -void test_arm_dynamic_direct_interrupts(void) +ZTEST(arm_irq_advanced_features, test_arm_dynamic_direct_interrupts) { int post_flag = 0; diff --git a/tests/arch/arm/arm_irq_advanced_features/src/arm_irq_target_state.c b/tests/arch/arm/arm_irq_advanced_features/src/arm_irq_target_state.c index 6521eef0cb7b..a5201bf45860 100644 --- a/tests/arch/arm/arm_irq_advanced_features/src/arm_irq_target_state.c +++ b/tests/arch/arm/arm_irq_advanced_features/src/arm_irq_target_state.c @@ -15,7 +15,7 @@ extern irq_target_state_t irq_target_state_set(unsigned int irq, irq_target_state_t target_state); extern int irq_target_state_is_secure(unsigned int irq); -void test_arm_irq_target_state(void) +ZTEST(arm_irq_advanced_features, test_arm_irq_target_state) { /* Determine an NVIC IRQ line that is implemented * but not currently in use. @@ -79,7 +79,7 @@ void test_arm_irq_target_state(void) "Target state not set to Non-Secure\n"); } #else -void test_arm_irq_target_state(void) +ZTEST(arm_irq_advanced_features, test_arm_irq_target_state) { TC_PRINT("Skipped (TrustZone-M-enabled Cortex-M Mainline only)\n"); } diff --git a/tests/arch/arm/arm_irq_advanced_features/src/arm_zero_latency_irqs.c b/tests/arch/arm/arm_irq_advanced_features/src/arm_zero_latency_irqs.c index 0bcc6694b32e..0ed1ce5c73fd 100644 --- a/tests/arch/arm/arm_irq_advanced_features/src/arm_zero_latency_irqs.c +++ b/tests/arch/arm/arm_irq_advanced_features/src/arm_zero_latency_irqs.c @@ -17,7 +17,7 @@ void arm_zero_latency_isr_handler(const void *args) test_flag = 1; } -void test_arm_zero_latency_irqs(void) +ZTEST(arm_irq_advanced_features, test_arm_zero_latency_irqs) { if (!IS_ENABLED(CONFIG_ZERO_LATENCY_IRQS)) { diff --git a/tests/arch/arm/arm_irq_advanced_features/src/main.c b/tests/arch/arm/arm_irq_advanced_features/src/main.c index a3e71128f118..5b76f072fa5e 100644 --- a/tests/arch/arm/arm_irq_advanced_features/src/main.c +++ b/tests/arch/arm/arm_irq_advanced_features/src/main.c @@ -6,15 +6,4 @@ #include -extern void test_arm_zero_latency_irqs(void); -extern void test_arm_dynamic_direct_interrupts(void); -extern void test_arm_irq_target_state(void); - -void test_main(void) -{ - ztest_test_suite(arm_irq_advanced_features, - ztest_unit_test(test_arm_dynamic_direct_interrupts), - ztest_unit_test(test_arm_zero_latency_irqs), - ztest_unit_test(test_arm_irq_target_state)); - ztest_run_test_suite(arm_irq_advanced_features); -} +ZTEST_SUITE(arm_irq_advanced_features, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c b/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c index 78c8697e6fd4..d6e41563588b 100644 --- a/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c +++ b/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c @@ -140,7 +140,7 @@ void isr2(void) * @see irq_enable(), z_irq_priority_set(), NVIC_SetPendingIRQ() * */ -void test_arm_irq_vector_table(void) +ZTEST(vector_table, test_arm_irq_vector_table) { printk("Test Cortex-M IRQs installed directly in the vector table\n"); diff --git a/tests/arch/arm/arm_irq_vector_table/src/main.c b/tests/arch/arm/arm_irq_vector_table/src/main.c index 3f023ed3c64e..249b9353046d 100644 --- a/tests/arch/arm/arm_irq_vector_table/src/main.c +++ b/tests/arch/arm/arm_irq_vector_table/src/main.c @@ -10,11 +10,4 @@ #include -extern void test_arm_irq_vector_table(void); - -void test_main(void) -{ - ztest_test_suite(vector_table, - ztest_unit_test(test_arm_irq_vector_table)); - ztest_run_test_suite(vector_table); -} +ZTEST_SUITE(vector_table, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_mem_protect/src/main.c b/tests/arch/arm/arm_mem_protect/src/main.c index 38395f8e52cd..6a399d7c1e4b 100644 --- a/tests/arch/arm/arm_mem_protect/src/main.c +++ b/tests/arch/arm/arm_mem_protect/src/main.c @@ -14,7 +14,7 @@ ZTEST_BMEM char user_stack[256]; * * @ingroup kernel_memprotect_tests */ -void test_user_corrupt_stack_pointer(void) +ZTEST_USER(arm_mem_protect, test_user_corrupt_stack_pointer) { int ret = 0; uint32_t saved_sp; @@ -37,10 +37,4 @@ void test_user_corrupt_stack_pointer(void) zassert_equal(ret, 0, "svc exception wrote to user stack"); } -void test_main(void) -{ - ztest_test_suite(arm_mem_protect, - ztest_user_unit_test(test_user_corrupt_stack_pointer) - ); - ztest_run_test_suite(arm_mem_protect); -} +ZTEST_SUITE(arm_mem_protect, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c b/tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c index 74948fbf2e10..f89fe51f7ce4 100644 --- a/tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c +++ b/tests/arch/arm/arm_ramfunc/src/arm_ramfunc.c @@ -15,7 +15,7 @@ __ramfunc static void arm_ram_function(void) test_flag = 1; } -void test_arm_ramfunc(void) +ZTEST(arm_ramfunc, test_arm_ramfunc) { int init_flag, post_flag; diff --git a/tests/arch/arm/arm_ramfunc/src/main.c b/tests/arch/arm/arm_ramfunc/src/main.c index 5b70c180f42c..823560316230 100644 --- a/tests/arch/arm/arm_ramfunc/src/main.c +++ b/tests/arch/arm/arm_ramfunc/src/main.c @@ -10,11 +10,4 @@ #include -extern void test_arm_ramfunc(void); - -void test_main(void) -{ - ztest_test_suite(arm_ramfunc, - ztest_unit_test(test_arm_ramfunc)); - ztest_run_test_suite(arm_ramfunc); -} +ZTEST_SUITE(arm_ramfunc, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_runtime_nmi/src/arm_runtime_nmi.c b/tests/arch/arm/arm_runtime_nmi/src/arm_runtime_nmi.c index feffb0f10d3d..a087e88b6a03 100644 --- a/tests/arch/arm/arm_runtime_nmi/src/arm_runtime_nmi.c +++ b/tests/arch/arm/arm_runtime_nmi/src/arm_runtime_nmi.c @@ -45,7 +45,7 @@ static void nmi_test_isr(void) * * @see z_NmiHandlerSet() */ -void test_arm_runtime_nmi(void) +ZTEST(arm_runtime_nmi_fn, test_arm_runtime_nmi) { uint32_t i = 0U; diff --git a/tests/arch/arm/arm_runtime_nmi/src/main.c b/tests/arch/arm/arm_runtime_nmi/src/main.c index 6e63431f43e5..45c289d58888 100644 --- a/tests/arch/arm/arm_runtime_nmi/src/main.c +++ b/tests/arch/arm/arm_runtime_nmi/src/main.c @@ -5,12 +5,5 @@ */ #include -extern void test_arm_runtime_nmi(void); -/**test case main entry*/ -void test_main(void) -{ - ztest_test_suite(arm_runtime_nmi_fn, - ztest_unit_test(test_arm_runtime_nmi)); - ztest_run_test_suite(arm_runtime_nmi_fn); -} +ZTEST_SUITE(arm_runtime_nmi_fn, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_sw_vector_relay/src/arm_sw_vector_relay.c b/tests/arch/arm/arm_sw_vector_relay/src/arm_sw_vector_relay.c index 3fee52d2640e..433de58b33b5 100644 --- a/tests/arch/arm/arm_sw_vector_relay/src/arm_sw_vector_relay.c +++ b/tests/arch/arm/arm_sw_vector_relay/src/arm_sw_vector_relay.c @@ -15,7 +15,7 @@ extern uint32_t _vector_table; extern uint32_t __vector_relay_handler; extern uint32_t _vector_table_pointer; -void test_arm_sw_vector_relay(void) +ZTEST(arm_sw_vector_relay, test_arm_sw_vector_relay) { uint32_t vector_relay_table_addr = (uint32_t)&__vector_relay_table; uint32_t vector_relay_handler_func = (uint32_t)&__vector_relay_handler; diff --git a/tests/arch/arm/arm_sw_vector_relay/src/main.c b/tests/arch/arm/arm_sw_vector_relay/src/main.c index 1edfcd9f3a4a..45f9cf9bd79d 100644 --- a/tests/arch/arm/arm_sw_vector_relay/src/main.c +++ b/tests/arch/arm/arm_sw_vector_relay/src/main.c @@ -10,11 +10,4 @@ #include -extern void test_arm_sw_vector_relay(void); - -void test_main(void) -{ - ztest_test_suite(arm_sw_vector_relay, - ztest_unit_test(test_arm_sw_vector_relay)); - ztest_run_test_suite(arm_sw_vector_relay); -} +ZTEST_SUITE(arm_sw_vector_relay, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_thread_swap/src/arm_syscalls.c b/tests/arch/arm/arm_thread_swap/src/arm_syscalls.c index 20e046f7953d..7cecf7180549 100644 --- a/tests/arch/arm/arm_thread_swap/src/arm_syscalls.c +++ b/tests/arch/arm/arm_thread_swap/src/arm_syscalls.c @@ -150,7 +150,7 @@ static void user_thread_entry(uint32_t irq_line) #endif } -void test_arm_syscalls(void) +ZTEST(arm_thread_swap, test_arm_syscalls) { int i = 0; @@ -279,7 +279,7 @@ static inline void z_vrfy_test_arm_cpu_write_reg(void) * * @ingroup kernel_memprotect_tests */ -void test_syscall_cpu_scrubs_regs(void) +ZTEST_USER(arm_thread_swap, test_syscall_cpu_scrubs_regs) { uint32_t arm_reg_val[4]; @@ -296,17 +296,6 @@ void test_syscall_cpu_scrubs_regs(void) "not scrubbed after system call."); } } -#else -void test_syscall_cpu_scrubs_regs(void) -{ - ztest_test_skip(); -} - -void test_arm_syscalls(void) -{ - ztest_test_skip(); -} - #endif /* CONFIG_USERSPACE */ /** * @} diff --git a/tests/arch/arm/arm_thread_swap/src/arm_thread_arch.c b/tests/arch/arm/arm_thread_swap/src/arm_thread_arch.c index 4cd926064224..b3f6904cf4c8 100644 --- a/tests/arch/arm/arm_thread_swap/src/arm_thread_arch.c +++ b/tests/arch/arm/arm_thread_swap/src/arm_thread_arch.c @@ -403,7 +403,7 @@ static void alt_thread_entry(void) "Alternative thread: switch flag not false on thread exit\n"); } -void test_arm_thread_swap(void) +ZTEST(arm_thread_swap, test_arm_thread_swap) { int test_flag; diff --git a/tests/arch/arm/arm_thread_swap/src/main.c b/tests/arch/arm/arm_thread_swap/src/main.c index 862c55214367..b5b78ae98a14 100644 --- a/tests/arch/arm/arm_thread_swap/src/main.c +++ b/tests/arch/arm/arm_thread_swap/src/main.c @@ -6,15 +6,4 @@ #include -extern void test_arm_thread_swap(void); -extern void test_arm_syscalls(void); -extern void test_syscall_cpu_scrubs_regs(void); - -void test_main(void) -{ - ztest_test_suite(arm_thread_swap, - ztest_unit_test(test_arm_thread_swap), - ztest_unit_test(test_arm_syscalls), - ztest_user_unit_test(test_syscall_cpu_scrubs_regs)); - ztest_run_test_suite(arm_thread_swap); -} +ZTEST_SUITE(arm_thread_swap, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_thread_swap_tz/src/main.c b/tests/arch/arm/arm_thread_swap_tz/src/main.c index c84abb0e92a1..5d452a0e8dc6 100644 --- a/tests/arch/arm/arm_thread_swap_tz/src/main.c +++ b/tests/arch/arm/arm_thread_swap_tz/src/main.c @@ -77,7 +77,7 @@ static void work_func(struct k_work *work) } -void test_thread_swap_tz(void) +ZTEST(test_thread_swap_tz, test_thread_swap_tz) { int err; char dummy_digest[HASH_LEN]; @@ -147,10 +147,4 @@ void test_thread_swap_tz(void) #endif /* CONFIG_CPU_HAS_FPU */ } -void test_main(void) -{ - ztest_test_suite(test_thread_swap_tz, - ztest_unit_test(test_thread_swap_tz) - ); - ztest_run_test_suite(test_thread_swap_tz); -} +ZTEST_SUITE(test_thread_swap_tz, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm/arm_tz_wrap_func/src/main.c b/tests/arch/arm/arm_tz_wrap_func/src/main.c index 766b2eb2a9b6..bd8742bc68ad 100644 --- a/tests/arch/arm/arm_tz_wrap_func/src/main.c +++ b/tests/arch/arm/arm_tz_wrap_func/src/main.c @@ -73,7 +73,7 @@ uint32_t __attribute__((naked)) wrap_foo1(uint32_t arg1, uint32_t arg2, } -void test_tz_wrap_func(void) +ZTEST(test_tz_wrap_func, test_tz_wrap_func) { reset_mocks(); foo1_retval = 0x01234567; @@ -100,9 +100,4 @@ void test_tz_wrap_func(void) zassert_false(expect_postface, NULL); } -void test_main(void) -{ - ztest_test_suite(tz_wrap_func, - ztest_unit_test(test_tz_wrap_func)); - ztest_run_test_suite(tz_wrap_func); -} +ZTEST_SUITE(test_tz_wrap_func, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/arm64/arm64_gicv3_its/src/main.c b/tests/arch/arm64/arm64_gicv3_its/src/main.c index af1791400aee..c499351cf03d 100644 --- a/tests/arch/arm64/arm64_gicv3_its/src/main.c +++ b/tests/arch/arm64/arm64_gicv3_its/src/main.c @@ -34,7 +34,7 @@ static void lpi_irq_handle(const void *parameter) unsigned int vectors[ITS_TEST_NUM_DEVS][ITS_TEST_NUM_ITES]; -static void test_gicv3_its_alloc(void) +ZTEST(its_func, test_gicv3_its_alloc) { int devn, event_id; const struct device *dev = DEVICE_DT_INST_GET(0); @@ -57,7 +57,7 @@ static void test_gicv3_its_alloc(void) } } -static void test_gicv3_its_connect(void) +ZTEST(its_func, test_gicv3_its_connect) { int devn, event_id; const struct device *dev = DEVICE_DT_INST_GET(0); @@ -78,7 +78,7 @@ static void test_gicv3_its_connect(void) } } -static void test_gicv3_its_irq_simple(void) +ZTEST(its_func, test_gicv3_its_irq_simple) { const struct device *dev = DEVICE_DT_INST_GET(0); unsigned int irqn = vectors[0][0]; @@ -101,7 +101,7 @@ static void test_gicv3_its_irq_simple(void) irqn, device_id, event_id); } -static void test_gicv3_its_irq_disable(void) +ZTEST(its_func, test_gicv3_its_irq_disable) { const struct device *dev = DEVICE_DT_INST_GET(0); unsigned int irqn = vectors[0][0]; @@ -140,7 +140,7 @@ static void test_gicv3_its_irq_disable(void) irqn, device_id, event_id); } -static void test_gicv3_its_irq(void) +ZTEST(its_func, test_gicv3_its_irq) { int devn, event_id; const struct device *dev = DEVICE_DT_INST_GET(0); @@ -172,13 +172,4 @@ static void test_gicv3_its_irq(void) } } -void test_main(void) -{ - ztest_test_suite(its_func, - ztest_unit_test(test_gicv3_its_alloc), - ztest_unit_test(test_gicv3_its_connect), - ztest_unit_test(test_gicv3_its_irq_simple), - ztest_unit_test(test_gicv3_its_irq_disable), - ztest_unit_test(test_gicv3_its_irq)); - ztest_run_test_suite(its_func); -} +ZTEST_SUITE(its_func, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/x86/cpu_scrubs_regs/src/main.c b/tests/arch/x86/cpu_scrubs_regs/src/main.c index 652a8b3e7f7c..1603cc28a40e 100644 --- a/tests/arch/x86/cpu_scrubs_regs/src/main.c +++ b/tests/arch/x86/cpu_scrubs_regs/src/main.c @@ -69,7 +69,7 @@ static inline void z_vrfy_test_cpu_write_reg(void) * * @ingroup kernel_memprotect_tests */ -void test_syscall_cpu_scrubs_regs(void) +ZTEST_USER(test_x86_cpu_scrubs_regs, test_syscall_cpu_scrubs_regs) { #if CONFIG_X86 #ifndef CONFIG_X86_64 @@ -125,9 +125,4 @@ void test_syscall_cpu_scrubs_regs(void) #endif } -void test_main(void) -{ - ztest_test_suite(test_x86_cpu_scrubs_regs, - ztest_user_unit_test(test_syscall_cpu_scrubs_regs)); - ztest_run_test_suite(test_x86_cpu_scrubs_regs); -} +ZTEST_SUITE(test_x86_cpu_scrubs_regs, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/x86/nmi/src/main.c b/tests/arch/x86/nmi/src/main.c index 6dc6df3c617e..7cba40be33a1 100644 --- a/tests/arch/x86/nmi/src/main.c +++ b/tests/arch/x86/nmi/src/main.c @@ -53,7 +53,7 @@ bool z_x86_do_kernel_nmi(const z_arch_esf_t *esf) return true; } -void test_nmi_handler(void) +ZTEST(nmi, test_nmi_handler) { TC_PRINT("Testing to see interrupt handler executes properly\n"); @@ -66,8 +66,4 @@ void test_nmi_handler(void) int_handler_executed); } -void test_main(void) -{ - ztest_test_suite(nmi, ztest_unit_test(test_nmi_handler)); - ztest_run_test_suite(nmi); -} +ZTEST_SUITE(nmi, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/x86/pagetables/src/main.c b/tests/arch/x86/pagetables/src/main.c index 4947be815123..a84eff87f738 100644 --- a/tests/arch/x86/pagetables/src/main.c +++ b/tests/arch/x86/pagetables/src/main.c @@ -74,7 +74,7 @@ static pentry_t get_entry(pentry_t *flags, void *addr) * * @ingroup kernel_memprotect_tests */ -void test_ram_perms(void) +ZTEST(x86_pagetables, test_ram_perms) { uint8_t *pos; @@ -200,7 +200,7 @@ void test_ram_perms(void) * * @ingroup kernel_memprotect_tests */ -void test_null_map(void) +ZTEST(x86_pagetables, test_null_map) { int level; pentry_t entry; @@ -233,7 +233,7 @@ void z_vrfy_dump_my_ptables(void) * * @ingroup kernel_memprotect_tests */ -void test_dump_ptables(void) +ZTEST_USER(x86_pagetables, test_dump_ptables) { #if CONFIG_SRAM_SIZE > (32 << 10) /* @@ -246,13 +246,4 @@ void test_dump_ptables(void) #endif } -void test_main(void) -{ - ztest_test_suite(x86_pagetables, - ztest_unit_test(test_ram_perms), - ztest_unit_test(test_null_map), - ztest_unit_test(test_dump_ptables), - ztest_user_unit_test(test_dump_ptables) - ); - ztest_run_test_suite(x86_pagetables); -} +ZTEST_SUITE(x86_pagetables, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/arch/x86/static_idt/src/main.c b/tests/arch/x86/static_idt/src/main.c index c686e3bfca78..fa89f3cb2bcb 100644 --- a/tests/arch/x86/static_idt/src/main.c +++ b/tests/arch/x86/static_idt/src/main.c @@ -109,7 +109,7 @@ extern void *_EXCEPTION_STUB_NAME(exc_divide_error_handler, IV_DIVIDE_ERROR); * and exception stubs are installed at the correct place. * */ -void test_idt_stub(void) +ZTEST(static_idt, test_idt_stub) { struct segment_descriptor *p_idt_entry; uint32_t offset; @@ -156,7 +156,7 @@ void idt_spur_task(void *arg1, void *arg2, void *arg3) * and spurious interrupt using various method, the registered handler * should get called */ -void test_static_idt(void) +ZTEST(static_idt, test_static_idt) { volatile int error; /* used to create a divide by zero error */ @@ -200,11 +200,4 @@ void test_static_idt(void) "Spurious handler did not execute as expected"); } -void test_main(void) -{ - ztest_test_suite(static_idt, - ztest_unit_test(test_idt_stub), - ztest_unit_test(test_static_idt) - ); - ztest_run_test_suite(static_idt); -} +ZTEST_SUITE(static_idt, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/benchmarks/cmsis_dsp/basicmath/src/f32.c b/tests/benchmarks/cmsis_dsp/basicmath/src/f32.c index 48b15aa656d8..1a48117283c7 100644 --- a/tests/benchmarks/cmsis_dsp/basicmath/src/f32.c +++ b/tests/benchmarks/cmsis_dsp/basicmath/src/f32.c @@ -147,7 +147,7 @@ static const uint32_t input2[256] = { 0xbf6a57bf, 0xbe9b9d13, 0x3ddf83ce, 0xbec67d55 }; -void test_benchmark_vec_add_f32(void) +ZTEST(basicmath_f32_benchmark, test_benchmark_vec_add_f32) { uint32_t irq_key, timestamp, timespan; float32_t *output; @@ -174,7 +174,7 @@ void test_benchmark_vec_add_f32(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_sub_f32(void) +ZTEST(basicmath_f32_benchmark, test_benchmark_vec_sub_f32) { uint32_t irq_key, timestamp, timespan; float32_t *output; @@ -201,7 +201,7 @@ void test_benchmark_vec_sub_f32(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_mult_f32(void) +ZTEST(basicmath_f32_benchmark, test_benchmark_vec_mult_f32) { uint32_t irq_key, timestamp, timespan; float32_t *output; @@ -228,7 +228,7 @@ void test_benchmark_vec_mult_f32(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_abs_f32(void) +ZTEST(basicmath_f32_benchmark, test_benchmark_vec_abs_f32) { uint32_t irq_key, timestamp, timespan; float32_t *output; @@ -253,7 +253,7 @@ void test_benchmark_vec_abs_f32(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_negate_f32(void) +ZTEST(basicmath_f32_benchmark, test_benchmark_vec_negate_f32) { uint32_t irq_key, timestamp, timespan; float32_t *output; @@ -278,7 +278,7 @@ void test_benchmark_vec_negate_f32(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_offset_f32(void) +ZTEST(basicmath_f32_benchmark, test_benchmark_vec_offset_f32) { uint32_t irq_key, timestamp, timespan; float32_t *output; @@ -303,7 +303,7 @@ void test_benchmark_vec_offset_f32(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_scale_f32(void) +ZTEST(basicmath_f32_benchmark, test_benchmark_vec_scale_f32) { uint32_t irq_key, timestamp, timespan; float32_t *output; @@ -328,7 +328,7 @@ void test_benchmark_vec_scale_f32(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_dot_prod_f32(void) +ZTEST(basicmath_f32_benchmark, test_benchmark_vec_dot_prod_f32) { uint32_t irq_key, timestamp, timespan; float32_t output; @@ -348,12 +348,4 @@ void test_benchmark_vec_dot_prod_f32(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -ztest_register_test_suite(basicmath_f32_benchmark, NULL, - ztest_unit_test(test_benchmark_vec_add_f32), - ztest_unit_test(test_benchmark_vec_sub_f32), - ztest_unit_test(test_benchmark_vec_mult_f32), - ztest_unit_test(test_benchmark_vec_abs_f32), - ztest_unit_test(test_benchmark_vec_negate_f32), - ztest_unit_test(test_benchmark_vec_offset_f32), - ztest_unit_test(test_benchmark_vec_scale_f32), - ztest_unit_test(test_benchmark_vec_dot_prod_f32)); +ZTEST_SUITE(basicmath_f32_benchmark, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/benchmarks/cmsis_dsp/basicmath/src/q15.c b/tests/benchmarks/cmsis_dsp/basicmath/src/q15.c index 6adcf075b6da..0bd77a648962 100644 --- a/tests/benchmarks/cmsis_dsp/basicmath/src/q15.c +++ b/tests/benchmarks/cmsis_dsp/basicmath/src/q15.c @@ -83,7 +83,7 @@ static const q15_t input2[256] = { 0xEA8B, 0x0959, 0x2D02, 0xD265, 0x3343, 0x0521, 0x4A77, 0xE225 }; -void test_benchmark_vec_add_q15(void) +ZTEST(basicmath_q15_benchmark, test_benchmark_vec_add_q15) { uint32_t irq_key, timestamp, timespan; q15_t *output; @@ -108,7 +108,7 @@ void test_benchmark_vec_add_q15(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_sub_q15(void) +ZTEST(basicmath_q15_benchmark, test_benchmark_vec_sub_q15) { uint32_t irq_key, timestamp, timespan; q15_t *output; @@ -133,7 +133,7 @@ void test_benchmark_vec_sub_q15(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_mult_q15(void) +ZTEST(basicmath_q15_benchmark, test_benchmark_vec_mult_q15) { uint32_t irq_key, timestamp, timespan; q15_t *output; @@ -158,7 +158,7 @@ void test_benchmark_vec_mult_q15(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_abs_q15(void) +ZTEST(basicmath_q15_benchmark, test_benchmark_vec_abs_q15) { uint32_t irq_key, timestamp, timespan; q15_t *output; @@ -183,7 +183,7 @@ void test_benchmark_vec_abs_q15(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_negate_q15(void) +ZTEST(basicmath_q15_benchmark, test_benchmark_vec_negate_q15) { uint32_t irq_key, timestamp, timespan; q15_t *output; @@ -208,7 +208,7 @@ void test_benchmark_vec_negate_q15(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_offset_q15(void) +ZTEST(basicmath_q15_benchmark, test_benchmark_vec_offset_q15) { uint32_t irq_key, timestamp, timespan; q15_t *output; @@ -233,7 +233,7 @@ void test_benchmark_vec_offset_q15(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_scale_q15(void) +ZTEST(basicmath_q15_benchmark, test_benchmark_vec_scale_q15) { uint32_t irq_key, timestamp, timespan; q15_t *output; @@ -258,7 +258,7 @@ void test_benchmark_vec_scale_q15(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_dot_prod_q15(void) +ZTEST(basicmath_q15_benchmark, test_benchmark_vec_dot_prod_q15) { uint32_t irq_key, timestamp, timespan; q63_t output; @@ -276,12 +276,4 @@ void test_benchmark_vec_dot_prod_q15(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -ztest_register_test_suite(basicmath_q15_benchmark, NULL, - ztest_unit_test(test_benchmark_vec_add_q15), - ztest_unit_test(test_benchmark_vec_sub_q15), - ztest_unit_test(test_benchmark_vec_mult_q15), - ztest_unit_test(test_benchmark_vec_abs_q15), - ztest_unit_test(test_benchmark_vec_negate_q15), - ztest_unit_test(test_benchmark_vec_offset_q15), - ztest_unit_test(test_benchmark_vec_scale_q15), - ztest_unit_test(test_benchmark_vec_dot_prod_q15)); +ZTEST_SUITE(basicmath_q15_benchmark, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/benchmarks/cmsis_dsp/basicmath/src/q31.c b/tests/benchmarks/cmsis_dsp/basicmath/src/q31.c index a995247f8c78..3fd30ae963bc 100644 --- a/tests/benchmarks/cmsis_dsp/basicmath/src/q31.c +++ b/tests/benchmarks/cmsis_dsp/basicmath/src/q31.c @@ -172,7 +172,7 @@ void test_benchmark_vec_add_q31(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_sub_q31(void) +ZTEST(basicmath_q31_benchmark, test_benchmark_vec_sub_q31) { uint32_t irq_key, timestamp, timespan; q31_t *output; @@ -197,7 +197,7 @@ void test_benchmark_vec_sub_q31(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_mult_q31(void) +ZTEST(basicmath_q31_benchmark, test_benchmark_vec_mult_q31) { uint32_t irq_key, timestamp, timespan; q31_t *output; @@ -222,7 +222,7 @@ void test_benchmark_vec_mult_q31(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_abs_q31(void) +ZTEST(basicmath_q31_benchmark, test_benchmark_vec_abs_q31) { uint32_t irq_key, timestamp, timespan; q31_t *output; @@ -247,7 +247,7 @@ void test_benchmark_vec_abs_q31(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_negate_q31(void) +ZTEST(basicmath_q31_benchmark, test_benchmark_vec_negate_q31) { uint32_t irq_key, timestamp, timespan; q31_t *output; @@ -272,7 +272,7 @@ void test_benchmark_vec_negate_q31(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_offset_q31(void) +ZTEST(basicmath_q31_benchmark, test_benchmark_vec_offset_q31) { uint32_t irq_key, timestamp, timespan; q31_t *output; @@ -297,7 +297,7 @@ void test_benchmark_vec_offset_q31(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_scale_q31(void) +ZTEST(basicmath_q31_benchmark, test_benchmark_vec_scale_q31) { uint32_t irq_key, timestamp, timespan; q31_t *output; @@ -322,7 +322,7 @@ void test_benchmark_vec_scale_q31(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_dot_prod_q31(void) +ZTEST(basicmath_q31_benchmark, test_benchmark_vec_dot_prod_q31) { uint32_t irq_key, timestamp, timespan; q63_t output; @@ -340,12 +340,4 @@ void test_benchmark_vec_dot_prod_q31(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -ztest_register_test_suite(basicmath_q31_benchmark, NULL, - ztest_unit_test(test_benchmark_vec_add_q31), - ztest_unit_test(test_benchmark_vec_sub_q31), - ztest_unit_test(test_benchmark_vec_mult_q31), - ztest_unit_test(test_benchmark_vec_abs_q31), - ztest_unit_test(test_benchmark_vec_negate_q31), - ztest_unit_test(test_benchmark_vec_offset_q31), - ztest_unit_test(test_benchmark_vec_scale_q31), - ztest_unit_test(test_benchmark_vec_dot_prod_q31)); +ZTEST_SUITE(basicmath_q31_benchmark, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/benchmarks/cmsis_dsp/basicmath/src/q7.c b/tests/benchmarks/cmsis_dsp/basicmath/src/q7.c index 5b250a74a86b..fe0f38ce1395 100644 --- a/tests/benchmarks/cmsis_dsp/basicmath/src/q7.c +++ b/tests/benchmarks/cmsis_dsp/basicmath/src/q7.c @@ -83,7 +83,7 @@ static const q7_t input2[PATTERN_LENGTH] = { 0xF7, 0xDB, 0xD0, 0x03, 0x4F, 0xE7, 0x0D, 0x1A }; -void test_benchmark_vec_add_q7(void) +ZTEST(basicmath_q7_benchmark, test_benchmark_vec_add_q7) { uint32_t irq_key, timestamp, timespan; q7_t *output; @@ -108,7 +108,7 @@ void test_benchmark_vec_add_q7(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_sub_q7(void) +ZTEST(basicmath_q7_benchmark, test_benchmark_vec_sub_q7) { uint32_t irq_key, timestamp, timespan; q7_t *output; @@ -132,8 +132,7 @@ void test_benchmark_vec_sub_q7(void) /* Print result */ TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } - -void test_benchmark_vec_mult_q7(void) +ZTEST(basicmath_q7_benchmark, test_benchmark_vec_mult_q7) { uint32_t irq_key, timestamp, timespan; q7_t *output; @@ -158,7 +157,7 @@ void test_benchmark_vec_mult_q7(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_abs_q7(void) +ZTEST(basicmath_q7_benchmark, test_benchmark_vec_abs_q7) { uint32_t irq_key, timestamp, timespan; q7_t *output; @@ -183,7 +182,7 @@ void test_benchmark_vec_abs_q7(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_negate_q7(void) +ZTEST(basicmath_q7_benchmark, test_benchmark_vec_negate_q7) { uint32_t irq_key, timestamp, timespan; q7_t *output; @@ -208,7 +207,7 @@ void test_benchmark_vec_negate_q7(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_offset_q7(void) +ZTEST(basicmath_q7_benchmark, test_benchmark_vec_offset_q7) { uint32_t irq_key, timestamp, timespan; q7_t *output; @@ -233,7 +232,7 @@ void test_benchmark_vec_offset_q7(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_scale_q7(void) +ZTEST(basicmath_q7_benchmark, test_benchmark_vec_scale_q7) { uint32_t irq_key, timestamp, timespan; q7_t *output; @@ -258,7 +257,7 @@ void test_benchmark_vec_scale_q7(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -void test_benchmark_vec_dot_prod_q7(void) +ZTEST(basicmath_q7_benchmark, test_benchmark_vec_dot_prod_q7) { uint32_t irq_key, timestamp, timespan; q31_t output; @@ -276,12 +275,4 @@ void test_benchmark_vec_dot_prod_q7(void) TC_PRINT(BENCHMARK_TYPE " = %u\n", timespan); } -ztest_register_test_suite(basicmath_q7_benchmark, NULL, - ztest_unit_test(test_benchmark_vec_add_q7), - ztest_unit_test(test_benchmark_vec_sub_q7), - ztest_unit_test(test_benchmark_vec_mult_q7), - ztest_unit_test(test_benchmark_vec_abs_q7), - ztest_unit_test(test_benchmark_vec_negate_q7), - ztest_unit_test(test_benchmark_vec_offset_q7), - ztest_unit_test(test_benchmark_vec_scale_q7), - ztest_unit_test(test_benchmark_vec_dot_prod_q7)); +ZTEST_SUITE(basicmath_q7_benchmark, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/benchmarks/data_structure_perf/dlist_perf/src/dlist_perf.c b/tests/benchmarks/data_structure_perf/dlist_perf/src/dlist_perf.c index 59c83c250530..38dbdb3bc03f 100644 --- a/tests/benchmarks/data_structure_perf/dlist_perf/src/dlist_perf.c +++ b/tests/benchmarks/data_structure_perf/dlist_perf/src/dlist_perf.c @@ -22,6 +22,8 @@ struct container_node { int value; }; +ZTEST_SUITE(test_dlist, NULL, NULL, NULL, NULL, NULL); + /** * @brief Test whether dlist node struct is embeddedable * in any user structure @@ -38,8 +40,7 @@ struct container_node { * * @see sys_dlist_append() */ - -void test_dlist_container(void) +ZTEST(test_dlist, test_dlist_container) { int i, count; struct container_node *cnode, *s_cnode; @@ -100,8 +101,7 @@ void test_dlist_container(void) * @see SYS_DLIST_FOR_EACH_NODE(),SYS_DLIST_FOR_EACH_NODE_SAFE() * SYS_DLIST_ITERATE_FROM_NODE() */ - -void test_dlist_for_each(void) +ZTEST(test_dlist, test_dlist_for_each) { int i, count, val; sys_dnode_t *node, *s_node; @@ -183,7 +183,7 @@ void test_dlist_for_each(void) * * @ingroup lib_dlist_tests */ -void test_dlist_peak_head_tail(void) +ZTEST(test_dlist, test_dlist_peak_head_tail) { sys_dlist_t list; sys_dnode_t node[10]; @@ -219,7 +219,7 @@ void test_dlist_peak_head_tail(void) * * @ingroup lib_dlist_tests */ -void test_dlist_insert_and_remove(void) +ZTEST(test_dlist, test_dlist_insert_and_remove) { sys_dlist_t list; sys_dlist_t node[10]; @@ -253,15 +253,3 @@ void test_dlist_insert_and_remove(void) zassert_true(insert_node != sys_dlist_peek_next(&list, &node[ARRAY_SIZE(node)/2 - 1]), "dlist can't remove a node in constant time"); } - -/* ztest main entry */ -void test_main(void) -{ - ztest_test_suite(test_dlist, - ztest_unit_test(test_dlist_container), - ztest_unit_test(test_dlist_for_each), - ztest_unit_test(test_dlist_peak_head_tail), - ztest_unit_test(test_dlist_insert_and_remove) - ); - ztest_run_test_suite(test_dlist); -} diff --git a/tests/benchmarks/data_structure_perf/rbtree_perf/src/rbtree_perf.c b/tests/benchmarks/data_structure_perf/rbtree_perf/src/rbtree_perf.c index 5acace1d9076..5d5de2977be2 100644 --- a/tests/benchmarks/data_structure_perf/rbtree_perf/src/rbtree_perf.c +++ b/tests/benchmarks/data_structure_perf/rbtree_perf/src/rbtree_perf.c @@ -21,6 +21,8 @@ struct container_node { static struct rbnode nodes[TREE_SIZE]; static struct rbtree tree; +ZTEST_SUITE(rbtree, NULL, NULL, NULL, NULL, NULL); + /* Our "lessthan" is just the location of the struct */ bool node_lessthan(struct rbnode *a, struct rbnode *b) { @@ -71,7 +73,7 @@ bool node_lessthan(struct rbnode *a, struct rbnode *b) * * @see RB_FOR_EACH(),RB_FOR_EACH_CONTAINER() */ -void test_rbtree_container(void) +ZTEST(rbtree, test_rbtree_container) { int count = 0; struct rbtree test_tree_l; @@ -186,7 +188,7 @@ void verify_rbtree_perf(struct rbnode *root, struct rbnode *test) * * @see rb_get_min(), rb_get_max() */ -void test_rbtree_perf(void) +ZTEST(rbtree, test_rbtree_perf) { init_tree(&tree, TREE_SIZE); struct rbnode *root = tree.root; @@ -206,12 +208,3 @@ void test_rbtree_perf(void) test = &nodes[TREE_SIZE/2]; verify_rbtree_perf(root, test); } - -void test_main(void) -{ - ztest_test_suite(rbtree, - ztest_unit_test(test_rbtree_container), - ztest_unit_test(test_rbtree_perf) - ); - ztest_run_test_suite(rbtree); -} diff --git a/tests/crypto/mbedtls/src/main.c b/tests/crypto/mbedtls/src/main.c index 38db964ab254..8efecdfb1ca6 100644 --- a/tests/crypto/mbedtls/src/main.c +++ b/tests/crypto/mbedtls/src/main.c @@ -7,15 +7,12 @@ #include #include -extern void test_mbedtls(void); - -/**test case main entry*/ -void test_main(void) +static void * setup_mbedtls_partition(void) { #ifdef CONFIG_USERSPACE k_mem_domain_add_partition(&k_mem_domain_default, &k_mbedtls_partition); #endif - ztest_test_suite(test_mbedtls_fn, - ztest_user_unit_test(test_mbedtls)); - ztest_run_test_suite(test_mbedtls_fn); + return NULL; } + +ZTEST_SUITE(test_mbedtls_fn, setup_mbedtls_partition, NULL, NULL, NULL, NULL); diff --git a/tests/crypto/mbedtls/src/mbedtls.c b/tests/crypto/mbedtls/src/mbedtls.c index a07f5ef0018e..d969c0fe3986 100644 --- a/tests/crypto/mbedtls/src/mbedtls.c +++ b/tests/crypto/mbedtls/src/mbedtls.c @@ -143,7 +143,7 @@ static void create_entropy_seed_file(void) ZTEST_BMEM unsigned char buf[16000]; #endif -void test_mbedtls(void) +ZTEST_USER(test_mbedtls_fn, test_mbedtls) { int v, suites_tested = 0, suites_failed = 0; diff --git a/tests/crypto/rand32/src/main.c b/tests/crypto/rand32/src/main.c index b270f2d791e9..ef4e101bfc9a 100644 --- a/tests/crypto/rand32/src/main.c +++ b/tests/crypto/rand32/src/main.c @@ -28,7 +28,7 @@ * @return N/A */ -void test_rand32(void) +ZTEST(rand32_common_test, test_rand32) { uint32_t gen, last_gen, tmp; int rnd_cnt; @@ -115,9 +115,4 @@ void test_rand32(void) } -void test_main(void) -{ - ztest_test_suite(common_test, ztest_unit_test(test_rand32)); - - ztest_run_test_suite(common_test); -} +ZTEST_SUITE(rand32_common_test, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/crypto/tinycrypt/src/aes.c b/tests/crypto/tinycrypt/src/aes.c index ea75dd5b50cb..3af694d7ee79 100644 --- a/tests/crypto/tinycrypt/src/aes.c +++ b/tests/crypto/tinycrypt/src/aes.c @@ -68,7 +68,7 @@ struct kat_table { /* * NIST test key schedule. */ -void test_aes_key_chain(void) +ZTEST(test_tinycrypt, test_aes_key_chain) { uint32_t result = TC_PASS; const uint8_t nist_key[NUM_OF_NIST_KEYS] = { @@ -108,7 +108,7 @@ void test_aes_key_chain(void) /* * NIST test vectors for encryption. */ -void test_aes_vectors(void) +ZTEST(test_tinycrypt, test_aes_vectors) { int result = TC_PASS; const uint8_t nist_key[NUM_OF_NIST_KEYS] = { @@ -167,7 +167,7 @@ uint32_t var_text_test(uint32_t r, const uint8_t *in, const uint8_t *out, /* * All NIST tests with fixed key and variable text. */ -void test_aes_fixed_key_variable_text(void) +ZTEST(test_tinycrypt, test_aes_fixed_key_variable_text) { uint32_t result = TC_PASS; const uint8_t key[NUM_OF_NIST_KEYS] = { @@ -1113,7 +1113,7 @@ uint32_t var_key_test(uint32_t r, const uint8_t *in, const uint8_t *out) /* * All NIST tests with variable key and fixed text. */ -void test_aes_variable_key_fixed_text(void) +ZTEST(test_tinycrypt, test_aes_variable_key_fixed_text) { uint32_t result = TC_PASS; const struct kat_table kat_tbl[NUM_OF_FIXED_KEYS] = { diff --git a/tests/crypto/tinycrypt/src/cbc_mode.c b/tests/crypto/tinycrypt/src/cbc_mode.c index dcc4ec2f33d4..b19de5345a44 100644 --- a/tests/crypto/tinycrypt/src/cbc_mode.c +++ b/tests/crypto/tinycrypt/src/cbc_mode.c @@ -101,7 +101,7 @@ const uint8_t ciphertext[80] = { /* * NIST SP 800-38a CBC Test for encryption and decryption. */ -void test_cbc_sp_800_38a_encrypt_decrypt(void) +ZTEST(test_tinycrypt, test_cbc_sp_800_38a_encrypt_decrypt) { TC_START("Performing AES128 tests:"); diff --git a/tests/crypto/tinycrypt/src/ccm_mode.c b/tests/crypto/tinycrypt/src/ccm_mode.c index ca48429ecc8c..100738db2afe 100644 --- a/tests/crypto/tinycrypt/src/ccm_mode.c +++ b/tests/crypto/tinycrypt/src/ccm_mode.c @@ -120,7 +120,7 @@ uint32_t do_test(const uint8_t *key, return result; } -void test_ccm_vector_1(void) +ZTEST(test_tinycrypt, test_ccm_vector_1) { uint32_t result = TC_PASS; /* RFC 3610 test vector #1 */ @@ -158,7 +158,7 @@ void test_ccm_vector_1(void) zassert_false(result, "CCM test #1 (RFC 3610 test vector #1) failed."); } -void test_ccm_vector_2(void) +ZTEST(test_tinycrypt, test_ccm_vector_2) { uint32_t result = TC_PASS; /* RFC 3610 test vector #2 */ @@ -196,7 +196,7 @@ void test_ccm_vector_2(void) zassert_false(result, "CCM test #2 failed."); } -void test_ccm_vector_3(void) +ZTEST(test_tinycrypt, test_ccm_vector_3) { uint32_t result = TC_PASS; /* RFC 3610 test vector #3 */ @@ -236,7 +236,7 @@ void test_ccm_vector_3(void) zassert_false(result, "CCM test #3 failed."); } -void test_ccm_vector_4(void) +ZTEST(test_tinycrypt, test_ccm_vector_4) { uint32_t result = TC_PASS; /* RFC 3610 test vector #7 */ @@ -275,7 +275,7 @@ void test_ccm_vector_4(void) zassert_false(result, "CCM test #4 failed."); } -void test_ccm_vector_5(void) +ZTEST(test_tinycrypt, test_ccm_vector_5) { uint32_t result = TC_PASS; /* RFC 3610 test vector #8 */ @@ -314,7 +314,7 @@ void test_ccm_vector_5(void) zassert_false(result, "CCM test #5 failed."); } -void test_ccm_vector_6(void) +ZTEST(test_tinycrypt, test_ccm_vector_6) { uint32_t result = TC_PASS; /* RFC 3610 test vector #9 */ @@ -354,7 +354,7 @@ void test_ccm_vector_6(void) zassert_false(result, "CCM test #6 failed."); } -void test_ccm_vector_7(void) +ZTEST(test_tinycrypt, test_ccm_vector_7) { uint32_t result = TC_PASS; /* Test based on RFC 3610 test vector #9 but with no associated data */ @@ -415,7 +415,7 @@ void test_ccm_vector_7(void) } -void test_ccm_vector_8(void) +ZTEST(test_tinycrypt, test_ccm_vector_8) { uint32_t result = TC_PASS; /* Test based on RFC 3610 test vector #9 but with no payload data */ diff --git a/tests/crypto/tinycrypt/src/cmac_mode.c b/tests/crypto/tinycrypt/src/cmac_mode.c index 5e016db7a39a..67cae1b73375 100644 --- a/tests/crypto/tinycrypt/src/cmac_mode.c +++ b/tests/crypto/tinycrypt/src/cmac_mode.c @@ -251,7 +251,7 @@ static uint32_t verify_cmac_512_bit_msg(TCCmacState_t s) * Main task to test CMAC */ -void test_cmac_mode(void) +ZTEST(test_tinycrypt, test_cmac_mode) { uint32_t result = TC_PASS; diff --git a/tests/crypto/tinycrypt/src/ctr_mode.c b/tests/crypto/tinycrypt/src/ctr_mode.c index d0677ff51305..9949a69a1614 100644 --- a/tests/crypto/tinycrypt/src/ctr_mode.c +++ b/tests/crypto/tinycrypt/src/ctr_mode.c @@ -49,7 +49,7 @@ /* * NIST SP 800-38a CTR Test for encryption and decryption. */ -void test_ctr_sp_800_38a_encrypt_decrypt(void) +ZTEST(test_tinycrypt, test_ctr_sp_800_38a_encrypt_decrypt) { TC_START("Performing AES128-CTR mode tests:"); diff --git a/tests/crypto/tinycrypt/src/ctr_prng.c b/tests/crypto/tinycrypt/src/ctr_prng.c index 7d3e66d99bec..119c156083ec 100644 --- a/tests/crypto/tinycrypt/src/ctr_prng.c +++ b/tests/crypto/tinycrypt/src/ctr_prng.c @@ -343,7 +343,7 @@ static int test_prng_vector(struct prng_vector *v) return rc; } -void test_ctr_prng_reseed(void) +ZTEST(test_tinycrypt, test_ctr_prng_reseed) { uint8_t expectedV1[] = {0x7E, 0xE3, 0xA0, 0xCB, 0x6D, 0x5C, 0x4B, 0xC2, 0x4B, 0x7E, 0x3C, 0x48, 0x88, 0xC3, 0x69, 0x70}; @@ -427,7 +427,7 @@ void test_ctr_prng_reseed(void) TC_PRINT("CTR PRNG reseed test succeeded\n"); } -void test_ctr_prng_uninstantiate(void) +ZTEST(test_tinycrypt, test_ctr_prng_uninstantiate) { uint8_t entropy[32] = {0}; /* value not important */ TCCtrPrng_t ctx; @@ -462,7 +462,7 @@ void test_ctr_prng_uninstantiate(void) TC_PRINT("CTR PRNG uninstantiate test succeeded\n"); } -void test_ctr_prng_robustness(void) +ZTEST(test_tinycrypt, test_ctr_prng_robustness) { uint8_t entropy[32] = {0}; /* value not important */ uint8_t output[32]; @@ -538,7 +538,7 @@ void test_ctr_prng_robustness(void) /* * Main task to test CTR PRNG */ -void test_ctr_prng_vector(void) +ZTEST(test_tinycrypt, test_ctr_prng_vector) { int elements; int rc; diff --git a/tests/crypto/tinycrypt/src/ecc_dh.c b/tests/crypto/tinycrypt/src/ecc_dh.c index 7724df7ff80d..3fbc635285ed 100644 --- a/tests/crypto/tinycrypt/src/ecc_dh.c +++ b/tests/crypto/tinycrypt/src/ecc_dh.c @@ -446,7 +446,7 @@ int montecarlo_ecdh(int num_tests, bool verbose) return TC_PASS; } -void test_ecc_dh(void) +ZTEST(test_tinycrypt, test_ecc_dh) { unsigned int result = TC_PASS; diff --git a/tests/crypto/tinycrypt/src/ecc_dsa.c b/tests/crypto/tinycrypt/src/ecc_dsa.c index d248863ad052..fc5d10a18a14 100644 --- a/tests/crypto/tinycrypt/src/ecc_dsa.c +++ b/tests/crypto/tinycrypt/src/ecc_dsa.c @@ -628,7 +628,7 @@ int default_CSPRNG(uint8_t *dest, unsigned int size) return 1; } -void test_ecc_dsa(void) +ZTEST(test_tinycrypt, test_ecc_dsa) { unsigned int result = TC_PASS; diff --git a/tests/crypto/tinycrypt/src/hmac.c b/tests/crypto/tinycrypt/src/hmac.c index 01cd320312c2..6ee2b35522de 100644 --- a/tests/crypto/tinycrypt/src/hmac.c +++ b/tests/crypto/tinycrypt/src/hmac.c @@ -60,7 +60,7 @@ uint32_t do_hmac_test(TCHmacState_t h, uint32_t testnum, const uint8_t *data, /* * NIST test vectors for encryption. */ -void test_hmac_1(void) +ZTEST(test_tinycrypt, test_hmac_1) { uint32_t result = TC_PASS; @@ -94,7 +94,7 @@ void test_hmac_1(void) zassert_false(result, "HMAC test #7 failed"); } -void test_hmac_2(void) +ZTEST(test_tinycrypt, test_hmac_2) { uint32_t result = TC_PASS; @@ -128,7 +128,7 @@ void test_hmac_2(void) zassert_false(result, "HMAC test #7 failed"); } -void test_hmac_3(void) +ZTEST(test_tinycrypt, test_hmac_3) { uint32_t result = TC_PASS; @@ -168,7 +168,7 @@ void test_hmac_3(void) zassert_false(result, "HMAC test #3 failed"); } -void test_hmac_4(void) +ZTEST(test_tinycrypt, test_hmac_4) { uint32_t result = TC_PASS; @@ -210,7 +210,7 @@ void test_hmac_4(void) zassert_false(result, "HMAC test #4 failed"); } -void test_hmac_5(void) +ZTEST(test_tinycrypt, test_hmac_5) { uint32_t result = TC_PASS; @@ -244,7 +244,7 @@ void test_hmac_5(void) zassert_false(result, "HMAC test #5 failed"); } -void test_hmac_6(void) +ZTEST(test_tinycrypt, test_hmac_6) { uint32_t result = TC_PASS; @@ -302,7 +302,7 @@ void test_hmac_6(void) zassert_false(result, "HMAC test #6 failed"); } -void test_hmac_7(void) +ZTEST(test_tinycrypt, test_hmac_7) { uint32_t result = TC_PASS; diff --git a/tests/crypto/tinycrypt/src/main.c b/tests/crypto/tinycrypt/src/main.c index 116d4dd9af1d..dfa292c01839 100644 --- a/tests/crypto/tinycrypt/src/main.c +++ b/tests/crypto/tinycrypt/src/main.c @@ -6,94 +6,4 @@ #include -extern void test_ccm_vector_1(void); -extern void test_ccm_vector_2(void); -extern void test_ccm_vector_3(void); -extern void test_ccm_vector_4(void); -extern void test_ccm_vector_5(void); -extern void test_ccm_vector_6(void); -extern void test_ccm_vector_7(void); -extern void test_ccm_vector_8(void); -extern void test_ctr_sp_800_38a_encrypt_decrypt(void); -extern void test_cbc_sp_800_38a_encrypt_decrypt(void); -extern void test_cmac_mode(void); -extern void test_ctr_prng_vector(void); -extern void test_ctr_prng_reseed(void); -extern void test_ctr_prng_uninstantiate(void); -extern void test_ctr_prng_robustness(void); -extern void test_ecc_dh(void); -extern void test_ecc_dsa(void); -extern void test_hmac_1(void); -extern void test_hmac_2(void); -extern void test_hmac_3(void); -extern void test_hmac_4(void); -extern void test_hmac_5(void); -extern void test_hmac_6(void); -extern void test_hmac_7(void); -extern void test_sha256_1(void); -extern void test_sha256_2(void); -extern void test_sha256_3(void); -extern void test_sha256_4(void); -extern void test_sha256_5(void); -extern void test_sha256_6(void); -extern void test_sha256_7(void); -extern void test_sha256_8(void); -extern void test_sha256_9(void); -extern void test_sha256_10(void); -extern void test_sha256_11(void); -extern void test_sha256_12(void); -extern void test_sha256_13_and_14(void); -extern void test_aes_key_chain(void); -extern void test_aes_vectors(void); -extern void test_aes_fixed_key_variable_text(void); -extern void test_aes_variable_key_fixed_text(void); - - -/**test case main entry*/ -void test_main(void) -{ - ztest_test_suite(test_tinycrypt, - ztest_unit_test(test_aes_key_chain), - ztest_unit_test(test_aes_vectors), - ztest_unit_test(test_aes_fixed_key_variable_text), - ztest_unit_test(test_aes_variable_key_fixed_text), - ztest_unit_test(test_sha256_1), - ztest_unit_test(test_sha256_2), - ztest_unit_test(test_sha256_3), - ztest_unit_test(test_sha256_4), - ztest_unit_test(test_sha256_5), - ztest_unit_test(test_sha256_6), - ztest_unit_test(test_sha256_7), - ztest_unit_test(test_sha256_8), - ztest_unit_test(test_sha256_9), - ztest_unit_test(test_sha256_10), - ztest_unit_test(test_sha256_11), - ztest_unit_test(test_sha256_12), - ztest_unit_test(test_sha256_13_and_14), - ztest_unit_test(test_hmac_1), - ztest_unit_test(test_hmac_2), - ztest_unit_test(test_hmac_3), - ztest_unit_test(test_hmac_4), - ztest_unit_test(test_hmac_5), - ztest_unit_test(test_hmac_6), - ztest_unit_test(test_hmac_7), - ztest_unit_test(test_ccm_vector_1), - ztest_unit_test(test_ccm_vector_2), - ztest_unit_test(test_ccm_vector_3), - ztest_unit_test(test_ccm_vector_4), - ztest_unit_test(test_ccm_vector_5), - ztest_unit_test(test_ccm_vector_6), - ztest_unit_test(test_ccm_vector_7), - ztest_unit_test(test_ccm_vector_8), - ztest_unit_test(test_ecc_dh), - ztest_unit_test(test_ecc_dsa), - ztest_unit_test(test_cmac_mode), - ztest_unit_test(test_ctr_prng_vector), - ztest_unit_test(test_ctr_prng_reseed), - ztest_unit_test(test_ctr_prng_uninstantiate), - ztest_unit_test(test_ctr_prng_robustness), - ztest_unit_test(test_ctr_sp_800_38a_encrypt_decrypt), - ztest_unit_test(test_cbc_sp_800_38a_encrypt_decrypt) - ); - ztest_run_test_suite(test_tinycrypt); -} +ZTEST_SUITE(test_tinycrypt, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/crypto/tinycrypt/src/sha256.c b/tests/crypto/tinycrypt/src/sha256.c index 1e41e1f23494..631301e2c7e2 100644 --- a/tests/crypto/tinycrypt/src/sha256.c +++ b/tests/crypto/tinycrypt/src/sha256.c @@ -50,7 +50,7 @@ /* * NIST SHA256 test vector 1. */ -void test_sha256_1(void) +ZTEST(test_tinycrypt, test_sha256_1) { TC_START("Performing SHA256 tests (NIST tests vectors):"); @@ -81,7 +81,7 @@ void test_sha256_1(void) /* * NIST SHA256 test vector 2. */ -void test_sha256_2(void) +ZTEST(test_tinycrypt, test_sha256_2) { uint32_t result = TC_PASS; @@ -109,7 +109,7 @@ void test_sha256_2(void) zassert_false(result, "SHA256 test #2 failed."); } -void test_sha256_3(void) +ZTEST(test_tinycrypt, test_sha256_3) { uint32_t result = TC_PASS; @@ -137,7 +137,7 @@ void test_sha256_3(void) } -void test_sha256_4(void) +ZTEST(test_tinycrypt, test_sha256_4) { uint32_t result = TC_PASS; @@ -165,7 +165,7 @@ void test_sha256_4(void) } -void test_sha256_5(void) +ZTEST(test_tinycrypt, test_sha256_5) { uint32_t result = TC_PASS; @@ -195,7 +195,7 @@ void test_sha256_5(void) } -void test_sha256_6(void) +ZTEST(test_tinycrypt, test_sha256_6) { uint32_t result = TC_PASS; @@ -225,7 +225,7 @@ void test_sha256_6(void) } -void test_sha256_7(void) +ZTEST(test_tinycrypt, test_sha256_7) { uint32_t result = TC_PASS; @@ -255,7 +255,7 @@ void test_sha256_7(void) } -void test_sha256_8(void) +ZTEST(test_tinycrypt, test_sha256_8) { uint32_t result = TC_PASS; @@ -285,7 +285,7 @@ void test_sha256_8(void) } -void test_sha256_9(void) +ZTEST(test_tinycrypt, test_sha256_9) { uint32_t result = TC_PASS; @@ -315,7 +315,7 @@ void test_sha256_9(void) } -void test_sha256_10(void) +ZTEST(test_tinycrypt, test_sha256_10) { uint32_t result = TC_PASS; @@ -345,7 +345,7 @@ void test_sha256_10(void) } -void test_sha256_11(void) +ZTEST(test_tinycrypt, test_sha256_11) { uint32_t result = TC_PASS; @@ -375,7 +375,7 @@ void test_sha256_11(void) } -void test_sha256_12(void) +ZTEST(test_tinycrypt, test_sha256_12) { uint32_t result = TC_PASS; @@ -407,7 +407,7 @@ void test_sha256_12(void) zassert_false(result, "SHA256 test #12 failed."); } #if EXTREME_SLOW -void test_sha256_13(void) +ZTEST(test_tinycrypt, test_sha256_13) { uint32_t result = TC_PASS; @@ -440,7 +440,7 @@ void test_sha256_13(void) } -void test_sha256_14(void) +ZTEST(test_tinycrypt, test_sha256_14) { uint32_t result = TC_PASS; @@ -474,7 +474,7 @@ void test_sha256_14(void) } #endif -void test_sha256_13_and_14(void) +ZTEST(test_tinycrypt, test_sha256_13_and_14) { #if EXTREME_SLOW result = test_sha256_13(); diff --git a/tests/crypto/tinycrypt_hmac_prng/src/hmac_prng.c b/tests/crypto/tinycrypt_hmac_prng/src/hmac_prng.c index e5d5651cd1d9..0b4a91b17cfa 100644 --- a/tests/crypto/tinycrypt_hmac_prng/src/hmac_prng.c +++ b/tests/crypto/tinycrypt_hmac_prng/src/hmac_prng.c @@ -7544,7 +7544,7 @@ unsigned int test_120(void) } -void test_hmac_prng(void) +ZTEST(test_hmac_prng_fn, test_hmac_prng) { unsigned int result = TC_PASS; diff --git a/tests/crypto/tinycrypt_hmac_prng/src/main.c b/tests/crypto/tinycrypt_hmac_prng/src/main.c index 9d7fb3230ea6..35e7279f9872 100644 --- a/tests/crypto/tinycrypt_hmac_prng/src/main.c +++ b/tests/crypto/tinycrypt_hmac_prng/src/main.c @@ -5,12 +5,5 @@ */ #include -extern void test_hmac_prng(void); -/**test case main entry*/ -void test_main(void) -{ - ztest_test_suite(test_hmac_prng_fn, - ztest_unit_test(test_hmac_prng)); - ztest_run_test_suite(test_hmac_prng_fn); -} +ZTEST_SUITE(test_hmac_prng_fn, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/kernel/fifo/fifo_api/src/main.c b/tests/kernel/fifo/fifo_api/src/main.c index 1ccb3c244a39..7ec3bc79217c 100644 --- a/tests/kernel/fifo/fifo_api/src/main.c +++ b/tests/kernel/fifo/fifo_api/src/main.c @@ -21,26 +21,6 @@ */ #include -extern void test_fifo_thread2thread(void); -extern void test_fifo_thread2isr(void); -extern void test_fifo_isr2thread(void); -extern void test_fifo_get_fail(void); -extern void test_fifo_loop(void); -extern void test_fifo_cancel_wait(void); -extern void test_fifo_is_empty_thread(void); -extern void test_fifo_is_empty_isr(void); -/*test case main entry*/ -void test_main(void) -{ - ztest_test_suite(fifo_api, - ztest_1cpu_unit_test(test_fifo_thread2thread), - ztest_unit_test(test_fifo_thread2isr), - ztest_unit_test(test_fifo_isr2thread), - ztest_unit_test(test_fifo_get_fail), - ztest_1cpu_unit_test(test_fifo_loop), - ztest_1cpu_unit_test(test_fifo_cancel_wait), - ztest_unit_test(test_fifo_is_empty_thread), - ztest_unit_test(test_fifo_is_empty_isr)); - ztest_run_test_suite(fifo_api); -} +ZTEST_SUITE(fifo_api_1cpu, NULL, NULL, ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL); +ZTEST_SUITE(fifo_api, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/kernel/fifo/fifo_api/src/test_fifo_cancel.c b/tests/kernel/fifo/fifo_api/src/test_fifo_cancel.c index 2fd219c2c8c8..8e8a02d75663 100644 --- a/tests/kernel/fifo/fifo_api/src/test_fifo_cancel.c +++ b/tests/kernel/fifo/fifo_api/src/test_fifo_cancel.c @@ -61,7 +61,7 @@ static void tfifo_thread_thread(struct k_fifo *pfifo) * to return from k_fifo_get() with NULL value (as if timeout expired). * @see k_fifo_init(),k_fifo_get(), k_fifo_cancel_wait() */ -void test_fifo_cancel_wait(void) +ZTEST(fifo_api_1cpu, test_fifo_cancel_wait) { /**TESTPOINT: init via k_fifo_init*/ k_fifo_init(&fifo_c); diff --git a/tests/kernel/fifo/fifo_api/src/test_fifo_contexts.c b/tests/kernel/fifo/fifo_api/src/test_fifo_contexts.c index d02da03e7477..f0069018d719 100644 --- a/tests/kernel/fifo/fifo_api/src/test_fifo_contexts.c +++ b/tests/kernel/fifo/fifo_api/src/test_fifo_contexts.c @@ -134,7 +134,7 @@ static void tfifo_is_empty(void *p) * @brief Test thread to thread data passing via fifo * @see k_fifo_init(), k_fifo_put(), k_fifo_get(), k_fifo_put_list() */ -void test_fifo_thread2thread(void) +ZTEST(fifo_api_1cpu, test_fifo_thread2thread) { /**TESTPOINT: init via k_fifo_init*/ k_fifo_init(&fifo); @@ -148,7 +148,7 @@ void test_fifo_thread2thread(void) * @brief Test isr to thread data passing via fifo * @see k_fifo_init(), k_fifo_put(), k_fifo_get() */ -void test_fifo_thread2isr(void) +ZTEST(fifo_api, test_fifo_thread2isr) { /**TESTPOINT: init via k_fifo_init*/ k_fifo_init(&fifo); @@ -162,7 +162,7 @@ void test_fifo_thread2isr(void) * @brief Test thread to isr data passing via fifo * @see k_fifo_init(), k_fifo_put(), k_fifo_get() */ -void test_fifo_isr2thread(void) +ZTEST(fifo_api, test_fifo_isr2thread) { /**TESTPOINT: test k_fifo_init fifo*/ k_fifo_init(&fifo); @@ -176,7 +176,7 @@ void test_fifo_isr2thread(void) * @brief Test empty fifo * @see k_fifo_init(), k_fifo_is_empty(), k_fifo_put(), k_fifo_get() */ -void test_fifo_is_empty_thread(void) +ZTEST(fifo_api, test_fifo_is_empty_thread) { k_fifo_init(&fifo); /**TESTPOINT: k_fifo_is_empty after init*/ @@ -190,7 +190,7 @@ void test_fifo_is_empty_thread(void) * @brief Test empty fifo in interrupt context * @see k_fifo_init(), fifo_is_empty(), k_fifo_put(), k_fifo_get() */ -void test_fifo_is_empty_isr(void) +ZTEST(fifo_api, test_fifo_is_empty_isr) { k_fifo_init(&fifo); /**TESTPOINT: check fifo is empty from isr*/ diff --git a/tests/kernel/fifo/fifo_api/src/test_fifo_fail.c b/tests/kernel/fifo/fifo_api/src/test_fifo_fail.c index 92913098d0af..7b27922d6380 100644 --- a/tests/kernel/fifo/fifo_api/src/test_fifo_fail.c +++ b/tests/kernel/fifo/fifo_api/src/test_fifo_fail.c @@ -19,7 +19,7 @@ * it should returns NULL. * @see k_fifo_init(), k_fifo_get() */ -void test_fifo_get_fail(void *p1, void *p2, void *p3) +ZTEST(fifo_api, test_fifo_get_fail) { static struct k_fifo fifo; diff --git a/tests/kernel/fifo/fifo_api/src/test_fifo_loop.c b/tests/kernel/fifo/fifo_api/src/test_fifo_loop.c index 051b087d64c1..7fc3c7f4652a 100644 --- a/tests/kernel/fifo/fifo_api/src/test_fifo_loop.c +++ b/tests/kernel/fifo/fifo_api/src/test_fifo_loop.c @@ -96,7 +96,7 @@ static void tfifo_read_write(struct k_fifo *pfifo) * * @see k_fifo_init(), k_fifo_put(), k_fifo_get() */ -void test_fifo_loop(void) +ZTEST(fifo_api_1cpu, test_fifo_loop) { k_fifo_init(&fifo); for (int i = 0; i < LOOPS; i++) { diff --git a/tests/kernel/fifo/fifo_timeout/src/main.c b/tests/kernel/fifo/fifo_timeout/src/main.c index 0da4e3c272c2..491b11673951 100644 --- a/tests/kernel/fifo/fifo_timeout/src/main.c +++ b/tests/kernel/fifo/fifo_timeout/src/main.c @@ -295,7 +295,7 @@ static void test_thread_timeout_reply_values_wfe(void *p1, void *p2, void *p3) * @brief Test empty fifo with timeout and K_NO_WAIT * @see k_fifo_get() */ -static void test_timeout_empty_fifo(void) +ZTEST(fifo_timeout_1cpu, test_timeout_empty_fifo) { void *packet; uint32_t start_time, timeout; @@ -318,7 +318,7 @@ static void test_timeout_empty_fifo(void) * @brief Test non empty fifo with timeout and K_NO_WAIT * @see k_fifo_get(), k_fifo_put() */ -static void test_timeout_non_empty_fifo(void) +ZTEST(fifo_timeout, test_timeout_non_empty_fifo) { void *packet, *scratch_packet; @@ -347,7 +347,7 @@ static void test_timeout_non_empty_fifo(void) * the child thread based on the data availability on another fifo. * @see k_fifo_get(), k_fifo_put() */ -static void test_timeout_fifo_thread(void) +ZTEST(fifo_timeout_1cpu, test_timeout_fifo_thread) { void *packet, *scratch_packet; struct reply_packet reply_packet; @@ -434,7 +434,7 @@ static void test_timeout_fifo_thread(void) * different timeouts * @see k_fifo_get(), k_fifo_put() */ -static void test_timeout_threads_pend_on_fifo(void) +ZTEST(fifo_timeout_1cpu, test_timeout_threads_pend_on_fifo) { int32_t rv, test_data_size; @@ -453,7 +453,7 @@ static void test_timeout_threads_pend_on_fifo(void) * with different timeouts * @see k_fifo_get(), k_fifo_put() */ -static void test_timeout_threads_pend_on_dual_fifos(void) +ZTEST(fifo_timeout_1cpu, test_timeout_threads_pend_on_dual_fifos) { int32_t rv, test_data_size; @@ -474,7 +474,7 @@ static void test_timeout_threads_pend_on_dual_fifos(void) * different timeouts but getting the data in time * @see k_fifo_get(), k_fifo_put() */ -static void test_timeout_threads_pend_fail_on_fifo(void) +ZTEST(fifo_timeout_1cpu, test_timeout_threads_pend_fail_on_fifo) { int32_t rv, test_data_size; @@ -492,7 +492,7 @@ static void test_timeout_threads_pend_fail_on_fifo(void) * @brief Test fifo init * @see k_fifo_init(), k_fifo_put() */ -static void test_timeout_setup(void) +static void *test_timeout_setup(void) { intptr_t ii; @@ -509,22 +509,12 @@ static void test_timeout_setup(void) (void *)&scratch_fifo_packets[ii]); } + return NULL; } /** * @} */ -/*test case main entry*/ -void test_main(void) -{ - test_timeout_setup(); - - ztest_test_suite(test_fifo_timeout, - ztest_1cpu_unit_test(test_timeout_empty_fifo), - ztest_unit_test(test_timeout_non_empty_fifo), - ztest_1cpu_unit_test(test_timeout_fifo_thread), - ztest_1cpu_unit_test(test_timeout_threads_pend_on_fifo), - ztest_1cpu_unit_test(test_timeout_threads_pend_on_dual_fifos), - ztest_1cpu_unit_test(test_timeout_threads_pend_fail_on_fifo)); - ztest_run_test_suite(test_fifo_timeout); -} +ZTEST_SUITE(fifo_timeout_1cpu, NULL, test_timeout_setup, ztest_simple_1cpu_before, + ztest_simple_1cpu_after, NULL); +ZTEST_SUITE(fifo_timeout, NULL, test_timeout_setup, NULL, NULL, NULL); diff --git a/tests/kernel/fifo/fifo_usage/prj.conf b/tests/kernel/fifo/fifo_usage/prj.conf index 19b7ff845de6..40eac807859c 100644 --- a/tests/kernel/fifo/fifo_usage/prj.conf +++ b/tests/kernel/fifo/fifo_usage/prj.conf @@ -1,3 +1,4 @@ CONFIG_ZTEST=y +CONFIG_ZTEST_RULE_1CPU=y CONFIG_IRQ_OFFLOAD=y CONFIG_MP_NUM_CPUS=1 diff --git a/tests/kernel/fifo/fifo_usage/src/main.c b/tests/kernel/fifo/fifo_usage/src/main.c index 7e3a832da839..cb2d0c7c4827 100644 --- a/tests/kernel/fifo/fifo_usage/src/main.c +++ b/tests/kernel/fifo/fifo_usage/src/main.c @@ -127,6 +127,8 @@ static void thread_entry_fn_isr(void *p1, void *p2, void *p3) k_sem_give(&end_sema); } +ZTEST_SUITE(fifo_usage, NULL, NULL, NULL, NULL, NULL); + /** * @addtogroup kernel_fifo_tests * @{ @@ -141,7 +143,7 @@ static void thread_entry_fn_isr(void *p1, void *p2, void *p3) * is returned back to Test Thread, it extracts all items from the fifo. * @see k_fifo_get(), k_fifo_is_empty(), k_fifo_put(), #K_FIFO_DEFINE(x) */ -static void test_single_fifo_play(void) +ZTEST(fifo_usage, test_single_fifo_play) { void *rx_data; uint32_t i; @@ -180,7 +182,7 @@ static void test_single_fifo_play(void) * Child Thread and so forth. * @see k_fifo_get(), k_fifo_is_empty(), k_fifo_put(), #K_FIFO_DEFINE(x) */ -static void test_dual_fifo_play(void) +ZTEST(fifo_usage, test_dual_fifo_play) { void *rx_data; uint32_t i; @@ -212,7 +214,7 @@ static void test_dual_fifo_play(void) * All the Push and Pop operations happen in ISR Context. * @see k_fifo_get(), k_fifo_is_empty(), k_fifo_put(), #K_FIFO_DEFINE(x) */ -static void test_isr_fifo_play(void) +ZTEST(fifo_usage, test_isr_fifo_play) { /* Init kernel objects */ k_sem_init(&end_sema, 0, 1); @@ -238,13 +240,3 @@ static void test_isr_fifo_play(void) /** * @} */ - -/*test case main entry*/ -void test_main(void) -{ - ztest_test_suite(test_fifo_usage, - ztest_1cpu_unit_test(test_single_fifo_play), - ztest_1cpu_unit_test(test_dual_fifo_play), - ztest_1cpu_unit_test(test_isr_fifo_play)); - ztest_run_test_suite(test_fifo_usage); -} diff --git a/tests/kernel/msgq/msgq_api/src/main.c b/tests/kernel/msgq/msgq_api/src/main.c index e8304477d010..1f9bfd29f52a 100644 --- a/tests/kernel/msgq/msgq_api/src/main.c +++ b/tests/kernel/msgq/msgq_api/src/main.c @@ -12,38 +12,6 @@ */ #include -extern void test_msgq_thread(void); -extern void test_msgq_thread_overflow(void); -extern void test_msgq_isr(void); -extern void test_msgq_put_fail(void); -extern void test_msgq_get_fail(void); -extern void test_msgq_purge_when_put(void); -extern void test_msgq_attrs_get(void); -extern void test_msgq_alloc(void); -extern void test_msgq_pend_thread(void); -extern void test_msgq_empty(void); -extern void test_msgq_full(void); -#ifdef CONFIG_USERSPACE -extern void test_msgq_user_thread(void); -extern void test_msgq_user_thread_overflow(void); -extern void test_msgq_user_put_fail(void); -extern void test_msgq_user_get_fail(void); -extern void test_msgq_user_attrs_get(void); -extern void test_msgq_user_purge_when_put(void); -#else -#define dummy_test(_name) \ - static void _name(void) \ - { \ - ztest_test_skip(); \ - } - -dummy_test(test_msgq_user_thread); -dummy_test(test_msgq_user_thread_overflow); -dummy_test(test_msgq_user_put_fail); -dummy_test(test_msgq_user_get_fail); -dummy_test(test_msgq_user_attrs_get); -dummy_test(test_msgq_user_purge_when_put); -#endif /* CONFIG_USERSPACE */ #ifdef CONFIG_64BIT #define MAX_SZ 256 @@ -59,6 +27,9 @@ extern struct k_sem end_sema; extern struct k_thread tdata; K_THREAD_STACK_EXTERN(tstack); +ZTEST_SUITE(msgq_api_1cpu, NULL, NULL, ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL); +ZTEST_SUITE(msgq_api, NULL, NULL, NULL, NULL, NULL); + /*test case main entry*/ void test_main(void) { @@ -67,23 +38,6 @@ void test_main(void) k_thread_heap_assign(k_current_get(), &test_pool); - ztest_test_suite(msgq_api, - ztest_1cpu_unit_test(test_msgq_thread), - ztest_unit_test(test_msgq_thread_overflow), - ztest_user_unit_test(test_msgq_user_thread), - ztest_user_unit_test(test_msgq_user_thread_overflow), - ztest_unit_test(test_msgq_isr), - ztest_1cpu_unit_test(test_msgq_put_fail), - ztest_1cpu_unit_test(test_msgq_get_fail), - ztest_user_unit_test(test_msgq_user_put_fail), - ztest_user_unit_test(test_msgq_user_get_fail), - ztest_unit_test(test_msgq_attrs_get), - ztest_user_unit_test(test_msgq_user_attrs_get), - ztest_1cpu_unit_test(test_msgq_purge_when_put), - ztest_user_unit_test(test_msgq_user_purge_when_put), - ztest_1cpu_unit_test(test_msgq_pend_thread), - ztest_1cpu_unit_test(test_msgq_empty), - ztest_1cpu_unit_test(test_msgq_full), - ztest_unit_test(test_msgq_alloc)); - ztest_run_test_suite(msgq_api); + ztest_run_test_suites(NULL); + ztest_verify_all_test_suites_ran(); } diff --git a/tests/kernel/msgq/msgq_api/src/test_msgq_attrs.c b/tests/kernel/msgq/msgq_api/src/test_msgq_attrs.c index 7c85d1f10705..c9e87c4fcfe4 100644 --- a/tests/kernel/msgq/msgq_api/src/test_msgq_attrs.c +++ b/tests/kernel/msgq/msgq_api/src/test_msgq_attrs.c @@ -46,7 +46,7 @@ static void attrs_get(struct k_msgq *q) * * @see k_msgq_get_attrs() */ -void test_msgq_attrs_get(void) +ZTEST(msgq_api, test_msgq_attrs_get) { k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN); attrs_get(&msgq); @@ -59,7 +59,7 @@ void test_msgq_attrs_get(void) * * @see k_msgq_get_attrs() */ -void test_msgq_user_attrs_get(void) +ZTEST_USER(msgq_api, test_msgq_user_attrs_get) { struct k_msgq *q; diff --git a/tests/kernel/msgq/msgq_api/src/test_msgq_contexts.c b/tests/kernel/msgq/msgq_api/src/test_msgq_contexts.c index dc07d88f6a2a..f1dc48fb32a1 100644 --- a/tests/kernel/msgq/msgq_api/src/test_msgq_contexts.c +++ b/tests/kernel/msgq/msgq_api/src/test_msgq_contexts.c @@ -250,7 +250,7 @@ static void put_full_entry(void *p1, void *p2, void *p3) * @brief Test thread to thread data passing via message queue * @see k_msgq_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge() */ -void test_msgq_thread(void) +ZTEST(msgq_api_1cpu, test_msgq_thread) { int ret; @@ -267,7 +267,7 @@ void test_msgq_thread(void) * @brief Test thread to thread data passing via message queue * @see k_msgq_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge() */ -void test_msgq_thread_overflow(void) +ZTEST(msgq_api, test_msgq_thread_overflow) { int ret; @@ -292,7 +292,7 @@ void test_msgq_thread_overflow(void) * @brief Test user thread to kernel thread data passing via message queue * @see k_msgq_alloc_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge() */ -void test_msgq_user_thread(void) +ZTEST_USER(msgq_api, test_msgq_user_thread) { struct k_msgq *q; int ret; @@ -310,7 +310,7 @@ void test_msgq_user_thread(void) * @brief Test thread to thread data passing via message queue * @see k_msgq_alloc_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge() */ -void test_msgq_user_thread_overflow(void) +ZTEST_USER(msgq_api, test_msgq_user_thread_overflow) { struct k_msgq *q; int ret; @@ -329,7 +329,7 @@ void test_msgq_user_thread_overflow(void) * @brief Test thread to isr data passing via message queue * @see k_msgq_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge() */ -void test_msgq_isr(void) +ZTEST(msgq_api, test_msgq_isr) { static struct k_msgq stack_msgq; @@ -344,7 +344,7 @@ void test_msgq_isr(void) * @brief Test pending writer in msgq * @see k_msgq_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge() */ -void test_msgq_pend_thread(void) +ZTEST(msgq_api_1cpu, test_msgq_pend_thread) { int ret; @@ -361,7 +361,7 @@ void test_msgq_pend_thread(void) * pool with various parameters * @see k_msgq_alloc_init(), k_msgq_cleanup() */ -void test_msgq_alloc(void) +ZTEST(msgq_api, test_msgq_alloc) { int ret; @@ -390,7 +390,7 @@ void test_msgq_alloc(void) * * @see k_msgq_get() */ -void test_msgq_empty(void) +ZTEST(msgq_api_1cpu, test_msgq_empty) { int pri = k_thread_priority_get(k_current_get()) - 1; int ret; @@ -430,7 +430,7 @@ void test_msgq_empty(void) * * @see k_msgq_put() */ -void test_msgq_full(void) +ZTEST(msgq_api_1cpu, test_msgq_full) { int pri = k_thread_priority_get(k_current_get()) - 1; int ret; diff --git a/tests/kernel/msgq/msgq_api/src/test_msgq_fail.c b/tests/kernel/msgq/msgq_api/src/test_msgq_fail.c index 50b050217dae..a2bd0b8618eb 100644 --- a/tests/kernel/msgq/msgq_api/src/test_msgq_fail.c +++ b/tests/kernel/msgq/msgq_api/src/test_msgq_fail.c @@ -48,7 +48,7 @@ static void get_fail(struct k_msgq *q) * @brief Test returned error code during writing in msgq * @see k_msgq_init() */ -void test_msgq_put_fail(void) +ZTEST(msgq_api_1cpu, test_msgq_put_fail) { k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN); put_fail(&msgq); @@ -59,7 +59,7 @@ void test_msgq_put_fail(void) * @brief Test returned error code during writing in msgq * @see k_msgq_alloc_init() */ -void test_msgq_user_put_fail(void) +ZTEST_USER(msgq_api, test_msgq_user_put_fail) { struct k_msgq *q; @@ -74,7 +74,7 @@ void test_msgq_user_put_fail(void) * @brief Test returned error code during reading from msgq * @see k_msgq_init(), k_msgq_put() */ -void test_msgq_get_fail(void) +ZTEST(msgq_api_1cpu, test_msgq_get_fail) { k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN); get_fail(&msgq); @@ -85,7 +85,7 @@ void test_msgq_get_fail(void) * @brief Test returned error code during reading from msgq * @see k_msgq_alloc_init(), k_msgq_get() */ -void test_msgq_user_get_fail(void) +ZTEST_USER(msgq_api, test_msgq_user_get_fail) { struct k_msgq *q; diff --git a/tests/kernel/msgq/msgq_api/src/test_msgq_purge.c b/tests/kernel/msgq/msgq_api/src/test_msgq_purge.c index 3ac547904d2e..075292f40add 100644 --- a/tests/kernel/msgq/msgq_api/src/test_msgq_purge.c +++ b/tests/kernel/msgq/msgq_api/src/test_msgq_purge.c @@ -55,7 +55,7 @@ static void purge_when_put(struct k_msgq *q) * @brief Test purge a message queue * @see k_msgq_init(), k_msgq_purge(), k_msgq_put() */ -void test_msgq_purge_when_put(void) +ZTEST(msgq_api_1cpu, test_msgq_purge_when_put) { k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN); @@ -67,7 +67,7 @@ void test_msgq_purge_when_put(void) * @brief Test purge a message queue * @see k_msgq_init(), k_msgq_purge(), k_msgq_put() */ -void test_msgq_user_purge_when_put(void) +ZTEST_USER(msgq_api, test_msgq_user_purge_when_put) { struct k_msgq *q; diff --git a/tests/kernel/msgq/msgq_usage/src/main.c b/tests/kernel/msgq/msgq_usage/src/main.c index f80a7e2abda4..c9ba3376eb11 100644 --- a/tests/kernel/msgq/msgq_usage/src/main.c +++ b/tests/kernel/msgq/msgq_usage/src/main.c @@ -259,7 +259,9 @@ static void start_client(void) 0, K_NO_WAIT); } -void test_msgq_usage(void) +ZTEST_SUITE(msgq_usage, NULL, NULL, NULL, NULL, NULL); + +ZTEST(msgq_usage, test_msgq_usage) { start_service_manager(); register_service(); @@ -283,9 +285,3 @@ void test_msgq_usage(void) k_thread_join(tclient, K_FOREVER); k_thread_abort(tservice_manager); } - -void test_main(void) -{ - ztest_test_suite(msgq_usage, ztest_unit_test(test_msgq_usage)); - ztest_run_test_suite(msgq_usage); -} diff --git a/tests/kernel/mutex/mutex_api/src/test_mutex_apis.c b/tests/kernel/mutex/mutex_api/src/test_mutex_apis.c index 0f61d794cd57..c2c81b7ee36a 100644 --- a/tests/kernel/mutex/mutex_api/src/test_mutex_apis.c +++ b/tests/kernel/mutex/mutex_api/src/test_mutex_apis.c @@ -188,7 +188,11 @@ static void tThread_waiter(void *p1, void *p2, void *p3) } /*test cases*/ -void test_mutex_reent_lock_forever(void) + +ZTEST_SUITE(mutex_api_1cpu, NULL, NULL, ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL); +ZTEST_SUITE(mutex_api, NULL, NULL, NULL, NULL, NULL); + +ZTEST_USER(mutex_api_1cpu, test_mutex_reent_lock_forever) { /**TESTPOINT: test k_mutex_init mutex*/ k_mutex_init(&mutex); @@ -200,7 +204,7 @@ void test_mutex_reent_lock_forever(void) k_thread_abort(&tdata); } -void test_mutex_reent_lock_no_wait(void) +ZTEST_USER(mutex_api, test_mutex_reent_lock_no_wait) { /**TESTPOINT: test k_mutex_init mutex*/ tmutex_test_lock(&mutex, tThread_entry_lock_no_wait); @@ -209,7 +213,7 @@ void test_mutex_reent_lock_no_wait(void) tmutex_test_lock(&kmutex, tThread_entry_lock_no_wait); } -void test_mutex_reent_lock_timeout_fail(void) +ZTEST_USER(mutex_api, test_mutex_reent_lock_timeout_fail) { /**TESTPOINT: test k_mutex_init mutex*/ tmutex_test_lock_timeout(&mutex, tThread_entry_lock_timeout_fail); @@ -218,7 +222,7 @@ void test_mutex_reent_lock_timeout_fail(void) tmutex_test_lock_timeout(&kmutex, tThread_entry_lock_no_wait); } -void test_mutex_reent_lock_timeout_pass(void) +ZTEST_USER(mutex_api_1cpu, test_mutex_reent_lock_timeout_pass) { /**TESTPOINT: test k_mutex_init mutex*/ tmutex_test_lock_timeout(&mutex, tThread_entry_lock_timeout_pass); @@ -227,7 +231,7 @@ void test_mutex_reent_lock_timeout_pass(void) tmutex_test_lock_timeout(&kmutex, tThread_entry_lock_no_wait); } -void test_mutex_lock_unlock(void) +ZTEST_USER(mutex_api_1cpu, test_mutex_lock_unlock) { /**TESTPOINT: test k_mutex_init mutex*/ tmutex_test_lock_unlock(&mutex); @@ -243,7 +247,7 @@ void test_mutex_lock_unlock(void) * reaches zero. * @ingroup kernel_mutex_tests */ -void test_mutex_recursive(void) +ZTEST_USER(mutex_api, test_mutex_recursive) { k_mutex_init(&mutex); @@ -294,7 +298,7 @@ void test_mutex_recursive(void) * wait for timeout and T3 got the mutex. * @ingroup kernel_mutex_tests */ -void test_mutex_priority_inheritance(void) +ZTEST_USER(mutex_api, test_mutex_priority_inheritance) { /**TESTPOINT: run test case 1, given priority T1 < T2 */ k_mutex_init(&mutex); @@ -393,14 +397,6 @@ void test_main(void) &tstack2, &tdata3, &tstack3, &kmutex, &mutex); - ztest_test_suite(mutex_api, - ztest_1cpu_user_unit_test(test_mutex_lock_unlock), - ztest_1cpu_user_unit_test(test_mutex_reent_lock_forever), - ztest_user_unit_test(test_mutex_reent_lock_no_wait), - ztest_user_unit_test(test_mutex_reent_lock_timeout_fail), - ztest_1cpu_user_unit_test(test_mutex_reent_lock_timeout_pass), - ztest_user_unit_test(test_mutex_recursive), - ztest_user_unit_test(test_mutex_priority_inheritance) - ); - ztest_run_test_suite(mutex_api); + ztest_run_test_suites(NULL); + ztest_verify_all_test_suites_ran(); } diff --git a/tests/kernel/mutex/sys_mutex/src/main.c b/tests/kernel/mutex/sys_mutex/src/main.c index 0a4761519fbc..0463e484b4a5 100644 --- a/tests/kernel/mutex/sys_mutex/src/main.c +++ b/tests/kernel/mutex/sys_mutex/src/main.c @@ -69,6 +69,8 @@ static ZTEST_BMEM SYS_MUTEX_DEFINE(not_my_mutex); static ZTEST_BMEM SYS_MUTEX_DEFINE(bad_count_mutex); extern void test_mutex_multithread_competition(void); +ZTEST_SUITE(mutex_complex, NULL, NULL, NULL, NULL, NULL); + /** * * thread_05 - @@ -245,8 +247,7 @@ extern void thread_12(void); * * @return N/A */ - -void test_mutex(void) +ZTEST_AUTOSPACE(mutex_complex, test_mutex) { /* * Main thread(test_main) priority was 10 but ztest thread runs at @@ -362,7 +363,7 @@ void test_mutex(void) TC_PRINT("Recursive locking tests successful\n"); } -void test_supervisor_access(void) +ZTEST_AUTOSPACE(mutex_complex, test_supervisor_access) { int rv; @@ -384,19 +385,17 @@ void test_supervisor_access(void) zassert_true(rv == -EINVAL, "mutex wasn't locked"); } -void test_user_access(void) -{ #ifdef CONFIG_USERSPACE +ZTEST_USER(mutex_complex, test_user_access) +{ int rv; rv = sys_mutex_lock(&no_access_mutex, K_NO_WAIT); zassert_true(rv == -EACCES, "accessed mutex not in memory domain"); rv = sys_mutex_unlock(&no_access_mutex); zassert_true(rv == -EACCES, "accessed mutex not in memory domain"); -#else - ztest_test_skip(); -#endif /* CONFIG_USERSPACE */ } +#endif /* CONFIG_USERSPACE */ K_THREAD_DEFINE(THREAD_05, STACKSIZE, thread_05, NULL, NULL, NULL, 5, K_USER, 0); @@ -436,22 +435,6 @@ void test_main(void) * This requires us to not attempt to start the tests in user * mode, as this will otherwise fail an assertion in the thread code. */ -#ifdef CONFIG_USERSPACE - ztest_test_suite(mutex_complex, - ztest_user_unit_test(test_mutex), - ztest_user_unit_test(test_user_access), - ztest_unit_test(test_supervisor_access)); - - ztest_run_test_suite(mutex_complex); -#else - ztest_test_suite(mutex_complex, - ztest_unit_test(test_mutex), - ztest_unit_test(test_user_access), - ztest_unit_test(test_supervisor_access), - ztest_unit_test(test_mutex_multithread_competition)); - - ztest_run_test_suite(mutex_complex); -#endif - - + ztest_run_test_suites(NULL); + ztest_verify_all_test_suites_ran(); } diff --git a/tests/kernel/mutex/sys_mutex/src/thread_competition.c b/tests/kernel/mutex/sys_mutex/src/thread_competition.c index bd7047021fcc..f1f9c11fcc1b 100644 --- a/tests/kernel/mutex/sys_mutex/src/thread_competition.c +++ b/tests/kernel/mutex/sys_mutex/src/thread_competition.c @@ -86,7 +86,8 @@ static void high_prio_t2_wait_for_mutex(void *p1, void *p2, void *p3) * * @ingroup kernel_mutex_tests */ -void test_mutex_multithread_competition(void) +#ifndef CONFIG_USERSPACE +ZTEST(mutex_complex, test_mutex_multithread_competition) { int old_prio = k_thread_priority_get(k_current_get()); int prio = 10; @@ -136,3 +137,4 @@ void test_mutex_multithread_competition(void) /* Revert priority of the main thread */ k_thread_priority_set(k_current_get(), old_prio); } +#endif /* !CONFIG_USERSPACE */ diff --git a/tests/kernel/pending/prj.conf b/tests/kernel/pending/prj.conf index c2adf7ce0128..ddf55ad7e079 100644 --- a/tests/kernel/pending/prj.conf +++ b/tests/kernel/pending/prj.conf @@ -1,2 +1,3 @@ CONFIG_ZTEST=y +CONFIG_ZTEST_RULE_1CPU=y CONFIG_MP_NUM_CPUS=1 diff --git a/tests/kernel/pending/src/main.c b/tests/kernel/pending/src/main.c index 043f07db4b66..f798c9703068 100644 --- a/tests/kernel/pending/src/main.c +++ b/tests/kernel/pending/src/main.c @@ -279,6 +279,8 @@ void task_low(void) lifo_tests(FOURTH_SECOND, &task_low_state, my_lifo_get, k_sem_take); } +ZTEST_SUITE(pend, NULL, NULL, NULL, NULL, NULL); + /** * @brief Test pending * @@ -294,7 +296,7 @@ void task_low(void) * * @see k_sleep(), K_THREAD_DEFINE() */ -void test_pending_fifo(void) +ZTEST(pend, test_pending_fifo) { /* * Main thread(test_main) priority was 9 but ztest thread runs at @@ -361,7 +363,7 @@ void test_pending_fifo(void) } -void test_pending_lifo(void) +ZTEST(pend, test_pending_lifo) { /* * Main thread(test_main) priority was 9 but ztest thread runs at @@ -428,7 +430,7 @@ void test_pending_lifo(void) } -void test_pending_timer(void) +ZTEST(pend, test_pending_timer) { /* * Main thread(test_main) priority was 9 but ztest thread runs at @@ -470,15 +472,6 @@ void test_pending_timer(void) /** * @} */ -void test_main(void) -{ - ztest_test_suite(pend, - ztest_1cpu_unit_test(test_pending_fifo), - ztest_1cpu_unit_test(test_pending_lifo), - ztest_1cpu_unit_test(test_pending_timer) - ); - ztest_run_test_suite(pend); -} K_THREAD_DEFINE(TASK_LOW, PREEM_STACKSIZE, task_low, NULL, NULL, NULL, 7, 0, 0); diff --git a/tests/kernel/pipe/pipe/src/main.c b/tests/kernel/pipe/pipe/src/main.c index 57a9650df102..d61c4c5bf0a7 100644 --- a/tests/kernel/pipe/pipe/src/main.c +++ b/tests/kernel/pipe/pipe/src/main.c @@ -6,18 +6,6 @@ #include -extern void test_pipe_on_single_elements(void); -extern void test_pipe_on_multiple_elements(void); -extern void test_pipe_forever_wait(void); -extern void test_pipe_timeout(void); -extern void test_pipe_get_on_empty_pipe(void); -extern void test_pipe_forever_timeout(void); -extern void test_pipe_get_timeout(void); -extern void test_pipe_get_invalid_size(void); -extern void test_pipe_get_min_xfer(void); -extern void test_pipe_put_min_xfer(void); -extern void test_pipe_define_at_runtime(void); - extern struct k_pipe test_pipe; extern struct k_sem put_sem, get_sem, sync_sem, multiple_send_sem; extern struct k_stack stack_1; @@ -31,19 +19,6 @@ void test_main(void) &sync_sem, &multiple_send_sem, &get_single_tid, &stack_1); - ztest_test_suite(test_pipe, - ztest_user_unit_test(test_pipe_on_single_elements), - ztest_user_unit_test(test_pipe_on_multiple_elements), - ztest_user_unit_test(test_pipe_forever_wait), - ztest_user_unit_test(test_pipe_timeout), - ztest_user_unit_test(test_pipe_get_on_empty_pipe), - ztest_user_unit_test(test_pipe_forever_timeout), - ztest_user_unit_test(test_pipe_get_timeout), - ztest_user_unit_test(test_pipe_get_invalid_size), - ztest_user_unit_test(test_pipe_get_min_xfer), - ztest_user_unit_test(test_pipe_put_min_xfer), - ztest_unit_test(test_pipe_define_at_runtime) - ); - - ztest_run_test_suite(test_pipe); + ztest_run_test_suites(NULL); + ztest_verify_all_test_suites_ran(); } diff --git a/tests/kernel/pipe/pipe/src/test_pipe.c b/tests/kernel/pipe/pipe/src/test_pipe.c index b1a20c40efc5..978f631883db 100644 --- a/tests/kernel/pipe/pipe/src/test_pipe.c +++ b/tests/kernel/pipe/pipe/src/test_pipe.c @@ -402,6 +402,9 @@ void pipe_put_timeout(void) int return_value; /* 1. fill the pipe. */ + written = k_pipe_write_avail(&test_pipe); + zassert_equal(written, PIPE_SIZE, "Expected %u bytes available for writing, but got %u", + PIPE_SIZE, written); return_value = k_pipe_put(&test_pipe, &tx_buffer, PIPE_SIZE, &written, PIPE_SIZE, TIMEOUT_VAL); @@ -685,6 +688,21 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) /******************************************************************************/ /* Test case entry points */ +static void test_pipe_before(void *data) +{ + size_t current_size; + uint8_t dest[PIPE_SIZE]; + size_t bytes_read; + + ARG_UNUSED(data); + + while ((current_size = k_pipe_read_avail(&test_pipe)) != 0) { + k_pipe_get(&test_pipe, dest, current_size, &bytes_read, 1, K_NO_WAIT); + } +} + +ZTEST_SUITE(test_pipe, NULL, NULL, test_pipe_before, NULL, NULL); + /** * @brief Verify pipe with 1 element insert. * @@ -722,7 +740,7 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) * * @see k_pipe_put(), k_pipe_get() */ -void test_pipe_on_single_elements(void) +ZTEST_USER(test_pipe, test_pipe_on_single_elements) { /* initialize the tx buffer */ for (int i = 0; i < sizeof(tx_buffer); i++) { @@ -748,7 +766,7 @@ void test_pipe_on_single_elements(void) * @ingroup kernel_pipe_tests * @see k_pipe_put() */ -void test_pipe_on_multiple_elements(void) +ZTEST_USER(test_pipe, test_pipe_on_multiple_elements) { k_thread_create(&get_single_tid, stack_1, STACK_SIZE, pipe_get_multiple, NULL, NULL, NULL, @@ -766,7 +784,7 @@ void test_pipe_on_multiple_elements(void) * @ingroup kernel_pipe_tests * @see k_pipe_put() */ -void test_pipe_forever_wait(void) +ZTEST_USER(test_pipe, test_pipe_forever_wait) { k_thread_create(&get_single_tid, stack_1, STACK_SIZE, pipe_get_forever_wait, NULL, NULL, NULL, @@ -817,7 +835,7 @@ void test_pipe_forever_wait(void) * * @see k_pipe_put() */ -void test_pipe_timeout(void) +ZTEST_USER(test_pipe, test_pipe_timeout) { k_thread_create(&get_single_tid, stack_1, STACK_SIZE, pipe_get_timeout, NULL, NULL, NULL, @@ -835,7 +853,7 @@ void test_pipe_timeout(void) * @ingroup kernel_pipe_tests * @see k_pipe_get() */ -void test_pipe_get_on_empty_pipe(void) +ZTEST_USER(test_pipe, test_pipe_get_on_empty_pipe) { pipe_get_on_empty_pipe(); ztest_test_pass(); @@ -848,7 +866,7 @@ void test_pipe_get_on_empty_pipe(void) * @ingroup kernel_pipe_tests * @see k_pipe_put() */ -void test_pipe_forever_timeout(void) +ZTEST_USER(test_pipe, test_pipe_forever_timeout) { k_thread_priority_set(k_current_get(), K_PRIO_PREEMPT(0)); @@ -867,7 +885,7 @@ void test_pipe_forever_timeout(void) * @ingroup kernel_pipe_tests * @see k_pipe_get() */ -void test_pipe_get_timeout(void) +ZTEST_USER(test_pipe, test_pipe_get_timeout) { pipe_put_get_timeout(); @@ -879,7 +897,7 @@ void test_pipe_get_timeout(void) * @ingroup kernel_pipe_tests * @see k_pipe_get() */ -void test_pipe_get_invalid_size(void) +ZTEST_USER(test_pipe, test_pipe_get_invalid_size) { size_t read; int ret; @@ -898,7 +916,7 @@ void test_pipe_get_invalid_size(void) * @ingroup kernel_pipe_tests * @see k_pipe_get() */ -void test_pipe_get_min_xfer(void) +ZTEST_USER(test_pipe, test_pipe_get_min_xfer) { int res; size_t bytes_written = 0; @@ -921,7 +939,7 @@ void test_pipe_get_min_xfer(void) * @ingroup kernel_pipe_tests * @see k_pipe_put() */ -void test_pipe_put_min_xfer(void) +ZTEST_USER(test_pipe, test_pipe_put_min_xfer) { int res; size_t bytes_written = 0; @@ -979,7 +997,7 @@ void test_pipe_put_min_xfer(void) * * @see k_pipe_init() */ -void test_pipe_define_at_runtime(void) +ZTEST(test_pipe, test_pipe_define_at_runtime) { unsigned char ring_buffer[PIPE_SIZE]; struct k_pipe pipe; diff --git a/tests/kernel/pipe/pipe_api/src/main.c b/tests/kernel/pipe/pipe_api/src/main.c index d57f3c82c5e4..1ef89790d8d4 100644 --- a/tests/kernel/pipe/pipe_api/src/main.c +++ b/tests/kernel/pipe/pipe_api/src/main.c @@ -12,42 +12,6 @@ */ #include -extern void test_pipe_thread2thread(void); -extern void test_pipe_put_fail(void); -extern void test_pipe_get_fail(void); -extern void test_pipe_block_put(void); -extern void test_pipe_block_put_sema(void); -extern void test_pipe_get_put(void); -extern void test_pipe_get_large(void); - -extern void test_half_pipe_put_get(void); -extern void test_half_pipe_saturating_block_put(void); -extern void test_half_pipe_block_put_sema(void); -extern void test_pipe_alloc(void); -extern void test_pipe_reader_wait(void); -extern void test_pipe_block_writer_wait(void); -extern void test_pipe_cleanup(void); -#ifdef CONFIG_USERSPACE -extern void test_pipe_user_thread2thread(void); -extern void test_pipe_user_put_fail(void); -extern void test_pipe_user_get_fail(void); -extern void test_resource_pool_auto_free(void); -extern void test_pipe_alloc_not_init(void); -extern void test_pipe_get_null(void); -extern void test_pipe_get_unreach_data(void); -extern void test_pipe_get_unreach_size(void); -extern void test_pipe_put_null(void); -extern void test_pipe_put_unreach_data(void); -extern void test_pipe_put_unreach_size(void); -extern void test_pipe_read_avail_null(void); -extern void test_pipe_write_avail_null(void); -#endif - -extern void test_pipe_avail_r_lt_w(void); -extern void test_pipe_avail_w_lt_r(void); -extern void test_pipe_avail_r_eq_w_full(void); -extern void test_pipe_avail_r_eq_w_empty(void); -extern void test_pipe_avail_no_buffer(void); /* k objects */ extern struct k_pipe pipe, kpipe, khalfpipe, put_get_pipe; @@ -56,27 +20,8 @@ extern struct k_stack tstack; extern struct k_thread tdata; extern struct k_heap test_pool; -#ifndef CONFIG_USERSPACE -#define dummy_test(_name) \ - static void _name(void) \ - { \ - ztest_test_skip(); \ - } - -dummy_test(test_pipe_user_thread2thread); -dummy_test(test_pipe_user_put_fail); -dummy_test(test_pipe_user_get_fail); -dummy_test(test_resource_pool_auto_free); -dummy_test(test_pipe_alloc_not_init); -dummy_test(test_pipe_get_null); -dummy_test(test_pipe_get_unreach_data); -dummy_test(test_pipe_get_unreach_size); -dummy_test(test_pipe_put_null); -dummy_test(test_pipe_put_unreach_data); -dummy_test(test_pipe_put_unreach_size); -dummy_test(test_pipe_read_avail_null); -dummy_test(test_pipe_write_avail_null); -#endif /* !CONFIG_USERSPACE */ +ZTEST_SUITE(pipe_api_1cpu, NULL, NULL, ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL); +ZTEST_SUITE(pipe_api, NULL, NULL, NULL, NULL, NULL); /*test case main entry*/ void test_main(void) @@ -87,33 +32,6 @@ void test_main(void) k_thread_heap_assign(k_current_get(), &test_pool); - ztest_test_suite(pipe_api, - ztest_1cpu_unit_test(test_pipe_thread2thread), - ztest_1cpu_user_unit_test(test_pipe_user_thread2thread), - ztest_1cpu_user_unit_test(test_pipe_user_put_fail), - ztest_user_unit_test(test_pipe_user_get_fail), - ztest_user_unit_test(test_pipe_alloc_not_init), - ztest_user_unit_test(test_pipe_get_null), - ztest_user_unit_test(test_pipe_get_unreach_data), - ztest_user_unit_test(test_pipe_get_unreach_size), - ztest_user_unit_test(test_pipe_put_null), - ztest_user_unit_test(test_pipe_put_unreach_data), - ztest_user_unit_test(test_pipe_put_unreach_size), - ztest_user_unit_test(test_pipe_read_avail_null), - ztest_user_unit_test(test_pipe_write_avail_null), - ztest_unit_test(test_resource_pool_auto_free), - ztest_1cpu_unit_test(test_pipe_put_fail), - ztest_unit_test(test_pipe_get_fail), - ztest_unit_test(test_half_pipe_put_get), - ztest_unit_test(test_pipe_get_put), - ztest_unit_test(test_pipe_get_large), - ztest_1cpu_unit_test(test_pipe_alloc), - ztest_unit_test(test_pipe_cleanup), - ztest_unit_test(test_pipe_reader_wait), - ztest_unit_test(test_pipe_avail_r_lt_w), - ztest_unit_test(test_pipe_avail_w_lt_r), - ztest_unit_test(test_pipe_avail_r_eq_w_full), - ztest_unit_test(test_pipe_avail_r_eq_w_empty), - ztest_unit_test(test_pipe_avail_no_buffer)); - ztest_run_test_suite(pipe_api); + ztest_run_test_suites(NULL); + ztest_verify_all_test_suites_ran(); } diff --git a/tests/kernel/pipe/pipe_api/src/test_pipe_avail.c b/tests/kernel/pipe/pipe_api/src/test_pipe_avail.c index 46749136d7e8..a3d730d14866 100644 --- a/tests/kernel/pipe/pipe_api/src/test_pipe_avail.c +++ b/tests/kernel/pipe/pipe_api/src/test_pipe_avail.c @@ -40,7 +40,7 @@ static struct k_pipe bufferless1 = { * simultaneously return 0 for a buffered pipe, but they will both return 0 * for an unbuffered pipe. */ -void test_pipe_avail_no_buffer(void) +ZTEST(pipe_api, test_pipe_avail_no_buffer) { size_t r_avail; size_t w_avail; @@ -80,7 +80,7 @@ void test_pipe_avail_no_buffer(void) * w_avail = N - (w - r) = 5 * would overwrite: e f g h */ -void test_pipe_avail_r_lt_w(void) +ZTEST(pipe_api, test_pipe_avail_r_lt_w) { size_t r_avail; size_t w_avail; @@ -119,7 +119,7 @@ void test_pipe_avail_r_lt_w(void) * w_avail = r - w = 3 * would overwrite: a b c d */ -void test_pipe_avail_w_lt_r(void) +ZTEST(pipe_api, test_pipe_avail_w_lt_r) { size_t r_avail; size_t w_avail; @@ -162,7 +162,7 @@ void test_pipe_avail_w_lt_r(void) * w_avail = N - 0 = 8 * would overwrite: e f g h a b c d */ -void test_pipe_avail_r_eq_w_empty(void) +ZTEST(pipe_api, test_pipe_avail_r_eq_w_empty) { size_t r_avail; size_t w_avail; @@ -205,7 +205,7 @@ void test_pipe_avail_r_eq_w_empty(void) * w_avail = N - 8 = 0 * would overwrite: */ -void test_pipe_avail_r_eq_w_full(void) +ZTEST(pipe_api, test_pipe_avail_r_eq_w_full) { size_t r_avail; size_t w_avail; diff --git a/tests/kernel/pipe/pipe_api/src/test_pipe_contexts.c b/tests/kernel/pipe/pipe_api/src/test_pipe_contexts.c index a7912ff90bb9..2c22e683fa1b 100644 --- a/tests/kernel/pipe/pipe_api/src/test_pipe_contexts.c +++ b/tests/kernel/pipe/pipe_api/src/test_pipe_contexts.c @@ -184,7 +184,7 @@ static void tpipe_get_large_size(struct k_pipe *ppipe, k_timeout_t timeout) * with various parameters * @see k_pipe_alloc_init(), k_pipe_cleanup() */ -void test_pipe_alloc(void) +ZTEST(pipe_api_1cpu, test_pipe_alloc) { int ret; @@ -206,7 +206,7 @@ static void thread_for_get_forever(void *p1, void *p2, void *p3) tpipe_get((struct k_pipe *)p1, K_FOREVER); } -void test_pipe_cleanup(void) +ZTEST(pipe_api, test_pipe_cleanup) { int ret; @@ -288,8 +288,7 @@ static void thread_handler(void *p1, void *p2, void *p3) * * @see k_pipe_init(), k_pipe_put(), #K_PIPE_DEFINE(x) */ - -void test_pipe_thread2thread(void) +ZTEST(pipe_api_1cpu, test_pipe_thread2thread) { /**TESTPOINT: test k_pipe_init pipe*/ k_pipe_init(&pipe, data, PIPE_LEN); @@ -304,7 +303,7 @@ void test_pipe_thread2thread(void) * @brief Test data passing using pipes between user threads * @see k_pipe_init(), k_pipe_put(), #K_PIPE_DEFINE(x) */ -void test_pipe_user_thread2thread(void) +ZTEST_USER(pipe_api_1cpu, test_pipe_user_thread2thread) { /**TESTPOINT: test k_object_alloc pipe*/ struct k_pipe *p = k_object_alloc(K_OBJ_PIPE); @@ -323,7 +322,7 @@ void test_pipe_user_thread2thread(void) * @see k_heap_alloc() */ #ifdef CONFIG_USERSPACE -void test_resource_pool_auto_free(void) +ZTEST_USER(pipe_api, test_resource_pool_auto_free) { /* Pool has 2 blocks, both should succeed if kernel object and pipe * buffer are auto-freed when the allocating threads exit @@ -347,7 +346,7 @@ static void tThread_half_pipe_get(void *p1, void *p2, void *p3) * @brief Test put/get with smaller pipe buffer * @see k_pipe_put(), k_pipe_get() */ -void test_half_pipe_put_get(void) +ZTEST(pipe_api, test_half_pipe_put_get) { unsigned char rx_data[PIPE_LEN]; size_t rd_byte = 0; @@ -378,7 +377,7 @@ void test_half_pipe_put_get(void) k_thread_abort(tid2); } -void test_pipe_get_put(void) +ZTEST(pipe_api, test_pipe_get_put) { unsigned char rx_data[PIPE_LEN]; size_t rd_byte = 0; @@ -409,7 +408,7 @@ void test_pipe_get_put(void) k_thread_abort(tid2); } -void test_pipe_get_large(void) +ZTEST(pipe_api, test_pipe_get_large) { /**TESTPOINT: thread-thread data passing via pipe*/ k_tid_t tid1 = k_thread_create(&tdata1, tstack1, STACK_SIZE, @@ -435,7 +434,7 @@ void test_pipe_get_large(void) * @brief Test pending reader in pipe * @see k_pipe_put(), k_pipe_get() */ -void test_pipe_reader_wait(void) +ZTEST(pipe_api, test_pipe_reader_wait) { /**TESTPOINT: test k_pipe_block_put with semaphore*/ k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE, diff --git a/tests/kernel/pipe/pipe_api/src/test_pipe_fail.c b/tests/kernel/pipe/pipe_api/src/test_pipe_fail.c index bbba7b894b2b..2d24bc587294 100644 --- a/tests/kernel/pipe/pipe_api/src/test_pipe_fail.c +++ b/tests/kernel/pipe/pipe_api/src/test_pipe_fail.c @@ -38,7 +38,7 @@ static void put_fail(struct k_pipe *p) * @ingroup kernel_pipe_tests * @see k_pipe_init(), k_pipe_put() */ -void test_pipe_put_fail(void) +ZTEST(pipe_api_1cpu, test_pipe_put_fail) { k_pipe_init(&put_get_pipe, data, PIPE_LEN); @@ -50,7 +50,7 @@ void test_pipe_put_fail(void) * @see k_pipe_put() */ #ifdef CONFIG_USERSPACE -void test_pipe_user_put_fail(void) +ZTEST_USER(pipe_api_1cpu, test_pipe_user_put_fail) { struct k_pipe *p = k_object_alloc(K_OBJ_PIPE); @@ -87,7 +87,7 @@ static void get_fail(struct k_pipe *p) * @ingroup kernel_pipe_tests * @see k_pipe_init(), k_pipe_get() */ -void test_pipe_get_fail(void) +ZTEST(pipe_api, test_pipe_get_fail) { k_pipe_init(&put_get_pipe, data, PIPE_LEN); @@ -103,7 +103,7 @@ static size_t unreach_byte; * @ingroup kernel_pipe_tests * @see k_pipe_alloc_init() */ -void test_pipe_user_get_fail(void) +ZTEST_USER(pipe_api, test_pipe_user_get_fail) { struct k_pipe *p = k_object_alloc(K_OBJ_PIPE); @@ -123,7 +123,7 @@ void test_pipe_user_get_fail(void) * * @see k_pipe_alloc_init() */ -void test_pipe_alloc_not_init(void) +ZTEST_USER(pipe_api, test_pipe_alloc_not_init) { struct k_pipe pipe; @@ -141,7 +141,7 @@ void test_pipe_alloc_not_init(void) * * @see k_pipe_get() */ -void test_pipe_get_null(void) +ZTEST_USER(pipe_api, test_pipe_get_null) { unsigned char rx_data[PIPE_LEN]; size_t rd_byte = 0; @@ -161,7 +161,7 @@ void test_pipe_get_null(void) * * @see k_pipe_get() */ -void test_pipe_get_unreach_data(void) +ZTEST_USER(pipe_api, test_pipe_get_unreach_data) { struct k_pipe *p = k_object_alloc(K_OBJ_PIPE); size_t rd_byte = 0; @@ -185,7 +185,7 @@ void test_pipe_get_unreach_data(void) * * @see k_pipe_get() */ -void test_pipe_get_unreach_size(void) +ZTEST_USER(pipe_api, test_pipe_get_unreach_size) { struct k_pipe *p = k_object_alloc(K_OBJ_PIPE); unsigned char rx_data[PIPE_LEN]; @@ -209,7 +209,7 @@ void test_pipe_get_unreach_size(void) * * @see k_pipe_put() */ -void test_pipe_put_null(void) +ZTEST_USER(pipe_api, test_pipe_put_null) { unsigned char tx_data = 0xa; size_t to_wt = 0, wt_byte = 0; @@ -229,7 +229,7 @@ void test_pipe_put_null(void) * * @see k_pipe_put() */ -void test_pipe_put_unreach_data(void) +ZTEST_USER(pipe_api, test_pipe_put_unreach_data) { struct k_pipe *p = k_object_alloc(K_OBJ_PIPE); size_t to_wt = 0, wt_byte = 0; @@ -253,7 +253,7 @@ void test_pipe_put_unreach_data(void) * * @see k_pipe_put() */ -void test_pipe_put_unreach_size(void) +ZTEST_USER(pipe_api, test_pipe_put_unreach_size) { struct k_pipe *p = k_object_alloc(K_OBJ_PIPE); unsigned char tx_data = 0xa; @@ -277,7 +277,7 @@ void test_pipe_put_unreach_size(void) * * @see k_pipe_read_avail() */ -void test_pipe_read_avail_null(void) +ZTEST_USER(pipe_api, test_pipe_read_avail_null) { ztest_set_fault_valid(true); k_pipe_read_avail(NULL); @@ -293,7 +293,7 @@ void test_pipe_read_avail_null(void) * * @see k_pipe_write_avail() */ -void test_pipe_write_avail_null(void) +ZTEST_USER(pipe_api, test_pipe_write_avail_null) { ztest_set_fault_valid(true); k_pipe_write_avail(NULL); diff --git a/tests/lib/c_lib/src/main.c b/tests/lib/c_lib/src/main.c index 1a2fe6d0872e..fb20e7e79b1d 100644 --- a/tests/lib/c_lib/src/main.c +++ b/tests/lib/c_lib/src/main.c @@ -48,6 +48,8 @@ static struct k_thread tdata; #pragma GCC diagnostic ignored "-Wstringop-truncation" #endif +ZTEST_SUITE(test_c_lib, NULL, NULL, NULL, NULL, NULL); + /* * variables used during limits library testing; must be marked as "volatile" * to prevent compiler from computing results at compile time @@ -65,7 +67,7 @@ volatile long long_one = 1L; * */ -void test_limits(void) +ZTEST(test_c_lib, test_limits) { zassert_true((long_max + long_one == LONG_MIN), NULL); @@ -76,7 +78,7 @@ static ssize_t foobar(void) return -1; } -void test_ssize_t(void) +ZTEST(test_c_lib, test_ssize_t) { zassert_true(foobar() < 0, NULL); } @@ -86,7 +88,7 @@ void test_ssize_t(void) * @brief Test boolean types and values library * */ -void test_stdbool(void) +ZTEST(test_c_lib, test_stdbool) { zassert_true((true == 1), "true value"); @@ -106,7 +108,7 @@ volatile size_t size_of_long_variable = sizeof(long_variable); * @brief Test standard type definitions library * */ -void test_stddef(void) +ZTEST(test_c_lib, test_stddef) { #ifdef CONFIG_64BIT zassert_true((size_of_long_variable == 8), "sizeof"); @@ -128,7 +130,7 @@ volatile uint32_t unsigned_int = 0xffffff00; * @brief Test integer types library * */ -void test_stdint(void) +ZTEST(test_c_lib, test_stdint) { zassert_true((unsigned_int + unsigned_byte + 1u == 0U), NULL); @@ -161,7 +163,7 @@ char buffer[BUFSIZE]; * @brief Test string memset * */ -void test_memset(void) +ZTEST(test_c_lib, test_memset) { int i, ret; const char set = 'a'; @@ -183,7 +185,7 @@ void test_memset(void) * @see strlen(), strnlen(). * */ -void test_strlen(void) +ZTEST(test_c_lib, test_strlen) { (void)memset(buffer, '\0', BUFSIZE); (void)memset(buffer, 'b', 5); /* 5 is BUFSIZE / 2 */ @@ -200,7 +202,7 @@ void test_strlen(void) * @see strcmp(), strncasecmp(). * */ -void test_strcmp(void) +ZTEST(test_c_lib, test_strcmp) { strcpy(buffer, "eeeee"); char test = 0; @@ -221,7 +223,7 @@ void test_strcmp(void) * * @see strncmp(). */ -void test_strncmp(void) +ZTEST(test_c_lib, test_strncmp) { static const char pattern[] = "eeeeeeeeeeee"; @@ -248,7 +250,7 @@ void test_strncmp(void) * * @see strcpy(). */ -void test_strcpy(void) +ZTEST(test_c_lib, test_strcpy) { (void)memset(buffer, '\0', BUFSIZE); strcpy(buffer, "10 chars!\0"); @@ -262,7 +264,7 @@ void test_strcpy(void) * * @see strncpy(). */ -void test_strncpy(void) +ZTEST(test_c_lib, test_strncpy) { int ret; @@ -281,7 +283,7 @@ void test_strncpy(void) * * @see strchr(). */ -void test_strchr(void) +ZTEST(test_c_lib, test_strchr) { char *rs = NULL; int ret; @@ -305,7 +307,7 @@ void test_strchr(void) * * @see strspn(),strcspn(). */ -void test_strxspn(void) +ZTEST(test_c_lib, test_strxspn) { const char *empty = ""; const char *cset = "abc"; @@ -329,7 +331,7 @@ void test_strxspn(void) * * @see memcmp() */ -void test_memcmp(void) +ZTEST(test_c_lib, test_memcmp) { int ret; unsigned char m1[] = "a\0$def"; @@ -360,7 +362,7 @@ int cmp_func(const void *a, const void *b) return (*(int *)a - *(int *)b); } -void test_bsearch(void) +ZTEST(test_c_lib, test_bsearch) { void *result = NULL; int arr[5] = { 2, 5, 20, 50, 60 }; @@ -381,7 +383,7 @@ void test_bsearch(void) * * @see abs() */ -void test_abs(void) +ZTEST(test_c_lib, test_abs) { int val = -5, value = 5; @@ -395,7 +397,7 @@ void test_abs(void) * * @see atoi() */ -void test_atoi(void) +ZTEST(test_c_lib, test_atoi) { zassert_equal(atoi("123"), 123, "atoi error"); zassert_equal(atoi("2c5"), 2, "atoi error"); @@ -419,7 +421,7 @@ void test_atoi(void) * isprint(), isspace(), isupper(), isxdigit(). * */ -void test_checktype(void) +ZTEST(test_c_lib, test_checktype) { static const char exp_alnum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -506,7 +508,7 @@ void test_checktype(void) * * @see memchr(). */ -void test_memchr(void) +ZTEST(test_c_lib, test_memchr) { static const char str[] = "testfunction"; @@ -525,7 +527,7 @@ void test_memchr(void) * * @see memcpy(). */ -void test_memcpy(void) +ZTEST(test_c_lib, test_memcpy) { /* make sure the buffer is word aligned */ uintptr_t mem_dest[4] = {0}; @@ -575,7 +577,7 @@ void test_memcpy(void) * * @see memmove(). */ -void test_memmove(void) +ZTEST(test_c_lib, test_memmove) { char move_buffer[6] = "12123"; char move_new[6] = {0}; @@ -601,7 +603,7 @@ void test_memmove(void) * @see strcat(), strcspn(), strncat(). * */ -void test_str_operate(void) +ZTEST(test_c_lib, test_str_operate) { char str1[10] = "aabbcc", ncat[10] = "ddee"; char *str2 = "b"; @@ -646,7 +648,7 @@ void test_str_operate(void) * @see strtol(). * */ -void test_strtol(void) +ZTEST(test_c_lib, test_strtol) { static const char buf1[] = "+10379aegi"; static const char buf2[] = " -10379aegi"; @@ -735,7 +737,7 @@ void test_strtol(void) * @see strtoul(). * */ -void test_strtoul(void) +ZTEST(test_c_lib, test_strtoul) { static const char buf1[] = "+10379aegi"; static const char buf2[] = " -10379aegi"; @@ -817,7 +819,7 @@ void test_strtoul(void) * @brief test convert function * */ -void test_tolower_toupper(void) +ZTEST(test_c_lib, test_tolower_toupper) { static const char test[] = "Az09Za{#!"; static const char toup[] = "AZ09ZA{#!"; @@ -861,7 +863,7 @@ void test_strtok_r_do(char *str, char *sep, int tlen, } } -void test_strtok_r(void) +ZTEST(test_c_lib, test_strtok_r) { static const char * const tc01[] = { "1", "2", "3", "4", "5" }; @@ -882,7 +884,7 @@ void test_strtok_r(void) * * @see gmtime(),gmtime_r(). */ -void test_time(void) +ZTEST(test_c_lib, test_time) { time_t tests1 = 0; time_t tests2 = -5; @@ -904,7 +906,7 @@ void test_time(void) * @brief Test rand function * */ -void test_rand(void) +ZTEST(test_c_lib, test_rand) { int a; @@ -918,7 +920,7 @@ void test_rand(void) * @brief Test srand function * */ -void test_srand(void) +ZTEST(test_c_lib, test_srand) { int a; @@ -948,7 +950,7 @@ void test_srand(void) * @brief Test rand function for reproducibility * */ -void test_rand_reproducibility(void) +ZTEST(test_c_lib, test_rand_reproducibility) { int a; int b; @@ -1011,7 +1013,7 @@ void test_rand_reproducibility(void) * * @see abort(). */ -void test_abort(void) +ZTEST(test_c_lib, test_abort) { int a = 0; @@ -1030,7 +1032,7 @@ static void exit_program(void *p1, void *p2, void *p3) _exit(1); } -void test_exit(void) +ZTEST(test_c_lib, test_exit) { int a = 0; @@ -1040,55 +1042,3 @@ void test_exit(void) k_thread_abort(tid); zassert_equal(a, 0, "exit failed"); } - -/** - * - * @brief Test qsort function - * - * @see qsort() - */ -extern void test_qsort(void); - -/** - * @} - */ - -void test_main(void) -{ - ztest_test_suite(test_c_lib, - ztest_unit_test(test_limits), - ztest_unit_test(test_ssize_t), - ztest_unit_test(test_stdbool), - ztest_unit_test(test_stddef), - ztest_unit_test(test_stdint), - ztest_unit_test(test_memcmp), - ztest_unit_test(test_strchr), - ztest_unit_test(test_strcpy), - ztest_unit_test(test_strncpy), - ztest_unit_test(test_memset), - ztest_unit_test(test_strlen), - ztest_unit_test(test_strcmp), - ztest_unit_test(test_strxspn), - ztest_unit_test(test_bsearch), - ztest_unit_test(test_abs), - ztest_unit_test(test_atoi), - ztest_unit_test(test_strncmp), - ztest_unit_test(test_strtol), - ztest_unit_test(test_strtoul), - ztest_unit_test(test_checktype), - ztest_unit_test(test_memchr), - ztest_unit_test(test_memcpy), - ztest_unit_test(test_memmove), - ztest_unit_test(test_time), - ztest_unit_test(test_rand), - ztest_unit_test(test_srand), - ztest_unit_test(test_rand_reproducibility), - ztest_unit_test(test_abort), - ztest_unit_test(test_exit), - ztest_unit_test(test_str_operate), - ztest_unit_test(test_tolower_toupper), - ztest_unit_test(test_strtok_r), - ztest_unit_test(test_qsort) - ); - ztest_run_test_suite(test_c_lib); -} diff --git a/tests/lib/c_lib/src/test_qsort.c b/tests/lib/c_lib/src/test_qsort.c index a4205a9fdeb0..80dde4fd85e3 100644 --- a/tests/lib/c_lib/src/test_qsort.c +++ b/tests/lib/c_lib/src/test_qsort.c @@ -16,7 +16,14 @@ static int compare_ints(const void *a, const void *b) return (aa > bb) - (aa < bb); } -void test_qsort(void) +ZTEST_SUITE(tets_c_lib_qsort, NULL, NULL, NULL, NULL, NULL); + +/** + * + * @brief Test qsort function + * + */ +ZTEST(tets_c_lib_qsort, test_qsort) { { int actual_int[] = { 1, 3, 2 }; diff --git a/tests/lib/cbprintf_package/CMakeLists.txt b/tests/lib/cbprintf_package/CMakeLists.txt index 3e7c6b03c558..dfef0a76c404 100644 --- a/tests/lib/cbprintf_package/CMakeLists.txt +++ b/tests/lib/cbprintf_package/CMakeLists.txt @@ -4,4 +4,4 @@ cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(cbprintf_package) -target_sources(app PRIVATE src/main.c src/maincxx.cxx) +target_sources(app PRIVATE src/main.c) diff --git a/tests/lib/cbprintf_package/src/main.c b/tests/lib/cbprintf_package/src/main.c index 8dfea7d4f960..1dee4e6acce3 100644 --- a/tests/lib/cbprintf_package/src/main.c +++ b/tests/lib/cbprintf_package/src/main.c @@ -4,15 +4,274 @@ * SPDX-License-Identifier: Apache-2.0 */ #include -#include +#include -#include "test.inc" +#define CBPRINTF_DEBUG 1 -void test_cxx(void); -void test_cc(void); +#ifndef CBPRINTF_PACKAGE_ALIGN_OFFSET +#define CBPRINTF_PACKAGE_ALIGN_OFFSET 0 +#endif -void test_main(void) +#define ALIGN_OFFSET (sizeof(void *) * CBPRINTF_PACKAGE_ALIGN_OFFSET) + +struct out_buffer { + char *buf; + size_t idx; + size_t size; +}; + +static int out(int c, void *dest) +{ + int rv = EOF; + struct out_buffer *buf = (struct out_buffer *)dest; + + if (buf->idx < buf->size) { + buf->buf[buf->idx++] = (char)(unsigned char)c; + rv = (int)(unsigned char)c; + } + return rv; +} + +static char static_buf[512]; +static char runtime_buf[512]; +static char compare_buf[128]; + +static void dump(const char *desc, uint8_t *package, size_t len) +{ + printk("%s package %p:\n", desc, package); + for (size_t i = 0; i < len; i++) { + printk("%02x ", package[i]); + } + printk("\n"); +} + +static void unpack(const char *desc, struct out_buffer *buf, + uint8_t *package, size_t len) +{ + cbpprintf((cbprintf_cb)out, buf, package); + buf->buf[buf->idx] = 0; + zassert_equal(strcmp(buf->buf, compare_buf), 0, + "Strings differ\nexp: |%s|\ngot: |%s|\n", + compare_buf, buf->buf); +} + +#define TEST_PACKAGING(fmt, ...) do { \ + int must_runtime = CBPRINTF_MUST_RUNTIME_PACKAGE(0, fmt, __VA_ARGS__); \ + zassert_equal(must_runtime, !Z_C_GENERIC, NULL); \ + snprintfcb(compare_buf, sizeof(compare_buf), fmt, __VA_ARGS__); \ + printk("-----------------------------------------\n"); \ + printk("%s\n", compare_buf); \ + uint8_t *pkg; \ + struct out_buffer rt_buf = { \ + .buf = runtime_buf, .idx = 0, .size = sizeof(runtime_buf) \ + }; \ + int rc = cbprintf_package(NULL, ALIGN_OFFSET, 0, fmt, __VA_ARGS__); \ + zassert_true(rc > 0, "cbprintf_package() returned %d", rc); \ + int len = rc; \ + /* Aligned so the package is similar to the static one. */ \ + uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) \ + rt_package[len + ALIGN_OFFSET]; \ + memset(rt_package, 0, len + ALIGN_OFFSET); \ + pkg = &rt_package[ALIGN_OFFSET]; \ + rc = cbprintf_package(pkg, len, 0, fmt, __VA_ARGS__); \ + zassert_equal(rc, len, "cbprintf_package() returned %d, expected %d", \ + rc, len); \ + dump("runtime", pkg, len); \ + unpack("runtime", &rt_buf, pkg, len); \ + struct out_buffer st_buf = { \ + .buf = static_buf, .idx = 0, .size = sizeof(static_buf) \ + }; \ + CBPRINTF_STATIC_PACKAGE(NULL, 0, len, ALIGN_OFFSET, 0, fmt, __VA_ARGS__); \ + zassert_true(len > 0, "CBPRINTF_STATIC_PACKAGE() returned %d", len); \ + uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) \ + package[len + ALIGN_OFFSET];\ + int outlen; \ + pkg = &package[ALIGN_OFFSET]; \ + CBPRINTF_STATIC_PACKAGE(pkg, len, outlen, ALIGN_OFFSET, 0, fmt, __VA_ARGS__);\ + zassert_equal(len, outlen, NULL); \ + dump("static", pkg, len); \ + unpack("static", &st_buf, pkg, len); \ +} while (0) + +ZTEST_SUITE(test_cbprintf_package, NULL, NULL, NULL, NULL, NULL); + +ZTEST(test_cbprintf_package, test_cbprintf_package) { - test_cc(); - test_cxx(); + volatile signed char sc = -11; + int i = 100; + char c = 'a'; + static const short s = -300; + long li = -1111111111; + long long lli = 0x1122334455667788; + unsigned char uc = 100; + unsigned int ui = 0x12345; + unsigned short us = 0x1234; + unsigned long ul = 0xaabbaabb; + unsigned long long ull = 0xaabbaabbaabb; + void *vp = NULL; + + + /* tests to exercize different element alignments */ + TEST_PACKAGING("test long %x %lx %x", 0xb1b2b3b4, li, 0xe4e3e2e1); + TEST_PACKAGING("test long long %x %llx %x", 0xb1b2b3b4, lli, 0xe4e3e2e1); + + /* tests with varied elements */ + TEST_PACKAGING("test %d %hd %hhd", i, s, sc); + TEST_PACKAGING("test %ld %llx %hhu %hu %u", li, lli, uc, us, ui); + TEST_PACKAGING("test %lu %llu", ul, ull); + TEST_PACKAGING("test %c %p", c, vp); + + if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) { + float f = -1.234; + double d = 1.2333; + + TEST_PACKAGING("test double %x %f %x", 0xb1b2b3b4, d, 0xe4e3e2e1); + TEST_PACKAGING("test %f %a", f, d); +#if CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE + long double ld = 1.2333; + + TEST_PACKAGING("test %Lf", ld); +#endif + } +} + +ZTEST(test_cbprintf_package, test_cbprintf_rw_str_indexes) +{ + int len0, len1, len2; + static const char *test_str = "test %d %s"; + static const char *test_str1 = "lorem ipsum"; + uint8_t str_idx; + char *addr; + + len0 = cbprintf_package(NULL, 0, 0, test_str, 100, test_str1); + if (len0 > (int)(4 * sizeof(void *))) { + TC_PRINT("Skipping test, platform does not detect RO strings.\n"); + ztest_test_skip(); + } + + zassert_true(len0 > 0, NULL); + len1 = cbprintf_package(NULL, 0, CBPRINTF_PACKAGE_ADD_STRING_IDXS, + test_str, 100, test_str1); + zassert_true(len1 > 0, NULL); + + CBPRINTF_STATIC_PACKAGE(NULL, 0, len2, 0, + CBPRINTF_PACKAGE_ADD_STRING_IDXS, + test_str, 100, test_str1); + zassert_true(len2 > 0, NULL); + + /* package with string indexes will contain two more bytes holding indexes + * of string parameter locations. + */ + zassert_equal(len0 + 2, len1, NULL); + zassert_equal(len0 + 2, len2, NULL); + + uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package0[len0]; + uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package1[len1]; + uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package2[len2]; + + len0 = cbprintf_package(package0, sizeof(package0), 0, + test_str, 100, test_str1); + + len1 = cbprintf_package(package1, sizeof(package1) - 1, + CBPRINTF_PACKAGE_ADD_STRING_IDXS, + test_str, 100, test_str1); + zassert_equal(-ENOSPC, len1, NULL); + + CBPRINTF_STATIC_PACKAGE(package2, sizeof(package2) - 1, len2, 0, + CBPRINTF_PACKAGE_ADD_STRING_IDXS, + test_str, 100, test_str1); + zassert_equal(-ENOSPC, len2, NULL); + + len1 = cbprintf_package(package1, sizeof(package1), + CBPRINTF_PACKAGE_ADD_STRING_IDXS, + test_str, 100, test_str1); + zassert_equal(len0 + 2, len1, NULL); + + CBPRINTF_STATIC_PACKAGE(package2, sizeof(package2), len2, 0, + CBPRINTF_PACKAGE_ADD_STRING_IDXS, + test_str, 100, test_str1); + zassert_equal(len0 + 2, len2, NULL); + + struct z_cbprintf_desc *desc0 = (struct z_cbprintf_desc *)package0; + struct z_cbprintf_desc *desc1 = (struct z_cbprintf_desc *)package1; + struct z_cbprintf_desc *desc2 = (struct z_cbprintf_desc *)package2; + + /* Compare descriptor content. Second package has one ro string index. */ + zassert_equal(desc0->ro_str_cnt, 0, NULL); + zassert_equal(desc1->ro_str_cnt, 2, NULL); + zassert_equal(desc2->ro_str_cnt, 2, NULL); + + int *p = (int *)package1; + + str_idx = package1[len0]; + addr = *(char **)&p[str_idx]; + zassert_equal(addr, test_str, NULL); + + str_idx = package2[len0]; + addr = *(char **)&p[str_idx]; + zassert_equal(addr, test_str, NULL); + + str_idx = package1[len0 + 1]; + addr = *(char **)&p[str_idx]; + zassert_equal(addr, test_str1, NULL); + + str_idx = package2[len0 + 1]; + addr = *(char **)&p[str_idx]; + zassert_equal(addr, test_str1, NULL); } + +ZTEST(test_cbprintf_package, test_cbprintf_fsc_package) +{ + int len; + static const char *test_str = "test %d %s"; + static const char *test_str1 = "lorem ipsum"; + char *addr; + int fsc_len; + + len = cbprintf_package(NULL, 0, CBPRINTF_PACKAGE_ADD_STRING_IDXS, + test_str, 100, test_str1); + if (len > (int)(4 * sizeof(void *) + 2)) { + TC_PRINT("Skipping test, platform does not detect RO strings.\n"); + ztest_test_skip(); + } + + uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package[len]; + + len = cbprintf_package(package, sizeof(package), + CBPRINTF_PACKAGE_ADD_STRING_IDXS, + test_str, 100, test_str1); + + struct z_cbprintf_desc *desc = (struct z_cbprintf_desc *)package; + + zassert_equal(desc->ro_str_cnt, 2, NULL); + zassert_equal(desc->str_cnt, 0, NULL); + + /* Get length of fsc package. */ + fsc_len = cbprintf_fsc_package(package, len, NULL, 0); + + int exp_len = len + (int)strlen(test_str) + 1 + (int)strlen(test_str1) + 1; + + zassert_equal(exp_len, fsc_len, NULL); + + uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) fsc_package[fsc_len]; + + fsc_len = cbprintf_fsc_package(package, len, fsc_package, sizeof(fsc_package) - 1); + zassert_equal(fsc_len, -ENOSPC, NULL); + + fsc_len = cbprintf_fsc_package(package, len, fsc_package, sizeof(fsc_package)); + zassert_equal((int)sizeof(fsc_package), fsc_len, NULL); + + /* New package has no RO string locations, only copied one. */ + desc = (struct z_cbprintf_desc *)fsc_package; + zassert_equal(desc->ro_str_cnt, 0, NULL); + zassert_equal(desc->str_cnt, 2, NULL); + + /* Get pointer to the first string in the package. */ + addr = (char *)&fsc_package[desc->len * sizeof(int) + 1]; + + zassert_equal(strcmp(test_str, addr), 0, NULL); + + /* Get address of the second string. */ + addr += strlen(addr) + 2; + zassert_equal(strcmp(test_str1, addr), 0, NULL); +} \ No newline at end of file diff --git a/tests/lib/cbprintf_package/src/maincxx.cxx b/tests/lib/cbprintf_package/src/maincxx.cxx deleted file mode 100644 index 2b9fe8c57606..000000000000 --- a/tests/lib/cbprintf_package/src/maincxx.cxx +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include - -#include "test.inc" diff --git a/tests/lib/cbprintf_package/src/test.inc b/tests/lib/cbprintf_package/src/test.inc deleted file mode 100644 index 3f942f748031..000000000000 --- a/tests/lib/cbprintf_package/src/test.inc +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#define CBPRINTF_DEBUG 1 - -#ifndef CBPRINTF_PACKAGE_ALIGN_OFFSET -#define CBPRINTF_PACKAGE_ALIGN_OFFSET 0 -#endif - -#define ALIGN_OFFSET (sizeof(void *) * CBPRINTF_PACKAGE_ALIGN_OFFSET) - -struct out_buffer { - char *buf; - size_t idx; - size_t size; -}; - -static int out(int c, void *dest) -{ - int rv = EOF; - struct out_buffer *buf = (struct out_buffer *)dest; - - if (buf->idx < buf->size) { - buf->buf[buf->idx++] = (char)(unsigned char)c; - rv = (int)(unsigned char)c; - } - return rv; -} - -static char static_buf[512]; -static char runtime_buf[512]; -static char compare_buf[128]; - -static void dump(const char *desc, uint8_t *package, size_t len) -{ - printk("%s package %p:\n", desc, package); - for (size_t i = 0; i < len; i++) { - printk("%02x ", package[i]); - } - printk("\n"); -} - -static void unpack(const char *desc, struct out_buffer *buf, - uint8_t *package, size_t len) -{ - cbpprintf((cbprintf_cb)out, buf, package); - buf->buf[buf->idx] = 0; - zassert_equal(strcmp(buf->buf, compare_buf), 0, - "Strings differ\nexp: |%s|\ngot: |%s|\n", - compare_buf, buf->buf); -} - -#define TEST_PACKAGING(fmt, ...) do { \ - int must_runtime = CBPRINTF_MUST_RUNTIME_PACKAGE(0, fmt, __VA_ARGS__); \ - zassert_equal(must_runtime, !Z_C_GENERIC, NULL); \ - snprintfcb(compare_buf, sizeof(compare_buf), fmt, __VA_ARGS__); \ - printk("-----------------------------------------\n"); \ - printk("%s\n", compare_buf); \ - uint8_t *pkg; \ - struct out_buffer rt_buf = { \ - .buf = runtime_buf, .idx = 0, .size = sizeof(runtime_buf) \ - }; \ - int rc = cbprintf_package(NULL, ALIGN_OFFSET, 0, fmt, __VA_ARGS__); \ - zassert_true(rc > 0, "cbprintf_package() returned %d", rc); \ - int len = rc; \ - /* Aligned so the package is similar to the static one. */ \ - uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) \ - rt_package[len + ALIGN_OFFSET]; \ - memset(rt_package, 0, len + ALIGN_OFFSET); \ - pkg = &rt_package[ALIGN_OFFSET]; \ - rc = cbprintf_package(pkg, len, 0, fmt, __VA_ARGS__); \ - zassert_equal(rc, len, "cbprintf_package() returned %d, expected %d", \ - rc, len); \ - dump("runtime", pkg, len); \ - unpack("runtime", &rt_buf, pkg, len); \ - struct out_buffer st_buf = { \ - .buf = static_buf, .idx = 0, .size = sizeof(static_buf) \ - }; \ - CBPRINTF_STATIC_PACKAGE(NULL, 0, len, ALIGN_OFFSET, 0, fmt, __VA_ARGS__); \ - zassert_true(len > 0, "CBPRINTF_STATIC_PACKAGE() returned %d", len); \ - uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) \ - package[len + ALIGN_OFFSET];\ - int outlen; \ - pkg = &package[ALIGN_OFFSET]; \ - CBPRINTF_STATIC_PACKAGE(pkg, len, outlen, ALIGN_OFFSET, 0, fmt, __VA_ARGS__);\ - zassert_equal(len, outlen, NULL); \ - dump("static", pkg, len); \ - unpack("static", &st_buf, pkg, len); \ -} while (0) - -void test_cbprintf_package(void) -{ - volatile signed char sc = -11; - int i = 100; - char c = 'a'; - static const short s = -300; - long li = -1111111111; - long long lli = 0x1122334455667788; - unsigned char uc = 100; - unsigned int ui = 0x12345; - unsigned short us = 0x1234; - unsigned long ul = 0xaabbaabb; - unsigned long long ull = 0xaabbaabbaabb; - void *vp = NULL; - - - /* tests to exercize different element alignments */ - TEST_PACKAGING("test long %x %lx %x", 0xb1b2b3b4, li, 0xe4e3e2e1); - TEST_PACKAGING("test long long %x %llx %x", 0xb1b2b3b4, lli, 0xe4e3e2e1); - - /* tests with varied elements */ - TEST_PACKAGING("test %d %hd %hhd", i, s, sc); - TEST_PACKAGING("test %ld %llx %hhu %hu %u", li, lli, uc, us, ui); - TEST_PACKAGING("test %lu %llu", ul, ull); - TEST_PACKAGING("test %c %p", c, vp); - - if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) { - float f = -1.234; - double d = 1.2333; - - TEST_PACKAGING("test double %x %f %x", 0xb1b2b3b4, d, 0xe4e3e2e1); - TEST_PACKAGING("test %f %a", f, d); -#if CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE - long double ld = 1.2333; - - TEST_PACKAGING("test %Lf", ld); -#endif - } -} - -void test_cbprintf_rw_str_indexes(void) -{ - int len0, len1, len2; - static const char *test_str = "test %d %s"; - static const char *test_str1 = "lorem ipsum"; - uint8_t str_idx; - char *addr; - - len0 = cbprintf_package(NULL, 0, 0, test_str, 100, test_str1); - if (len0 > (int)(4 * sizeof(void *))) { - TC_PRINT("Skipping test, platform does not detect RO strings.\n"); - ztest_test_skip(); - } - - zassert_true(len0 > 0, NULL); - len1 = cbprintf_package(NULL, 0, CBPRINTF_PACKAGE_ADD_STRING_IDXS, - test_str, 100, test_str1); - zassert_true(len1 > 0, NULL); - - CBPRINTF_STATIC_PACKAGE(NULL, 0, len2, 0, - CBPRINTF_PACKAGE_ADD_STRING_IDXS, - test_str, 100, test_str1); - zassert_true(len2 > 0, NULL); - - /* package with string indexes will contain two more bytes holding indexes - * of string parameter locations. - */ - zassert_equal(len0 + 2, len1, NULL); - zassert_equal(len0 + 2, len2, NULL); - - uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package0[len0]; - uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package1[len1]; - uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package2[len2]; - - len0 = cbprintf_package(package0, sizeof(package0), 0, - test_str, 100, test_str1); - - len1 = cbprintf_package(package1, sizeof(package1) - 1, - CBPRINTF_PACKAGE_ADD_STRING_IDXS, - test_str, 100, test_str1); - zassert_equal(-ENOSPC, len1, NULL); - - CBPRINTF_STATIC_PACKAGE(package2, sizeof(package2) - 1, len2, 0, - CBPRINTF_PACKAGE_ADD_STRING_IDXS, - test_str, 100, test_str1); - zassert_equal(-ENOSPC, len2, NULL); - - len1 = cbprintf_package(package1, sizeof(package1), - CBPRINTF_PACKAGE_ADD_STRING_IDXS, - test_str, 100, test_str1); - zassert_equal(len0 + 2, len1, NULL); - - CBPRINTF_STATIC_PACKAGE(package2, sizeof(package2), len2, 0, - CBPRINTF_PACKAGE_ADD_STRING_IDXS, - test_str, 100, test_str1); - zassert_equal(len0 + 2, len2, NULL); - - struct z_cbprintf_desc *desc0 = (struct z_cbprintf_desc *)package0; - struct z_cbprintf_desc *desc1 = (struct z_cbprintf_desc *)package1; - struct z_cbprintf_desc *desc2 = (struct z_cbprintf_desc *)package2; - - /* Compare descriptor content. Second package has one ro string index. */ - zassert_equal(desc0->ro_str_cnt, 0, NULL); - zassert_equal(desc1->ro_str_cnt, 2, NULL); - zassert_equal(desc2->ro_str_cnt, 2, NULL); - - int *p = (int *)package1; - - str_idx = package1[len0]; - addr = *(char **)&p[str_idx]; - zassert_equal(addr, test_str, NULL); - - str_idx = package2[len0]; - addr = *(char **)&p[str_idx]; - zassert_equal(addr, test_str, NULL); - - str_idx = package1[len0 + 1]; - addr = *(char **)&p[str_idx]; - zassert_equal(addr, test_str1, NULL); - - str_idx = package2[len0 + 1]; - addr = *(char **)&p[str_idx]; - zassert_equal(addr, test_str1, NULL); -} - -static void test_cbprintf_fsc_package(void) -{ - int len; - static const char *test_str = "test %d %s"; - static const char *test_str1 = "lorem ipsum"; - char *addr; - int fsc_len; - - len = cbprintf_package(NULL, 0, CBPRINTF_PACKAGE_ADD_STRING_IDXS, - test_str, 100, test_str1); - if (len > (int)(4 * sizeof(void *) + 2)) { - TC_PRINT("Skipping test, platform does not detect RO strings.\n"); - ztest_test_skip(); - } - - uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package[len]; - - len = cbprintf_package(package, sizeof(package), - CBPRINTF_PACKAGE_ADD_STRING_IDXS, - test_str, 100, test_str1); - - struct z_cbprintf_desc *desc = (struct z_cbprintf_desc *)package; - - zassert_equal(desc->ro_str_cnt, 2, NULL); - zassert_equal(desc->str_cnt, 0, NULL); - - /* Get length of fsc package. */ - fsc_len = cbprintf_fsc_package(package, len, NULL, 0); - - int exp_len = len + (int)strlen(test_str) + 1 + (int)strlen(test_str1) + 1; - - zassert_equal(exp_len, fsc_len, NULL); - - uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) fsc_package[fsc_len]; - - fsc_len = cbprintf_fsc_package(package, len, fsc_package, sizeof(fsc_package) - 1); - zassert_equal(fsc_len, -ENOSPC, NULL); - - fsc_len = cbprintf_fsc_package(package, len, fsc_package, sizeof(fsc_package)); - zassert_equal((int)sizeof(fsc_package), fsc_len, NULL); - - /* New package has no RO string locations, only copied one. */ - desc = (struct z_cbprintf_desc *)fsc_package; - zassert_equal(desc->ro_str_cnt, 0, NULL); - zassert_equal(desc->str_cnt, 2, NULL); - - /* Get pointer to the first string in the package. */ - addr = (char *)&fsc_package[desc->len * sizeof(int) + 1]; - - zassert_equal(strcmp(test_str, addr), 0, NULL); - - /* Get address of the second string. */ - addr += strlen(addr) + 2; - zassert_equal(strcmp(test_str1, addr), 0, NULL); -} - -#if __cplusplus -extern "C" void test_cxx(void); -void test_cxx(void) -#else -void test_cc(void) -#endif -{ -#ifdef __cplusplus - printk("C++\n"); -#else - printk("sizeof: int=%zu long=%zu ptr=%zu long long=%zu double=%zu long double=%zu\n", - sizeof(int), sizeof(long), sizeof(void *), sizeof(long long), - sizeof(double), sizeof(long double)); - printk("alignof: int=%zu long=%zu ptr=%zu long long=%zu double=%zu long double=%zu\n", - __alignof__(int), __alignof__(long), __alignof__(void *), - __alignof__(long long), __alignof__(double), __alignof__(long double)); - printk("%s C11 _Generic\n", Z_C_GENERIC ? "With" : "Without"); -#endif - - ztest_test_suite(cbprintf_package, - ztest_unit_test(test_cbprintf_package), - ztest_unit_test(test_cbprintf_rw_str_indexes), - ztest_unit_test(test_cbprintf_fsc_package) - ); - - ztest_run_test_suite(cbprintf_package); -} diff --git a/tests/lib/cmsis_dsp/basicmath/src/f16.c b/tests/lib/cmsis_dsp/basicmath/src/f16.c index 650ff20f133d..182961356bbb 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/f16.c +++ b/tests/lib/cmsis_dsp/basicmath/src/f16.c @@ -45,10 +45,10 @@ static void test_arm_add_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_add_f16, 7, in_com1, in_com2, ref_add, 7); -DEFINE_TEST_VARIANT4(arm_add_f16, 16, in_com1, in_com2, ref_add, 16); -DEFINE_TEST_VARIANT4(arm_add_f16, 23, in_com1, in_com2, ref_add, 23); -DEFINE_TEST_VARIANT4(arm_add_f16, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_add_f16, 7, in_com1, in_com2, ref_add, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_add_f16, 16, in_com1, in_com2, ref_add, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_add_f16, 23, in_com1, in_com2, ref_add, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_add_f16, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); static void test_arm_sub_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -78,10 +78,10 @@ static void test_arm_sub_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_sub_f16, 7, in_com1, in_com2, ref_sub, 7); -DEFINE_TEST_VARIANT4(arm_sub_f16, 16, in_com1, in_com2, ref_sub, 16); -DEFINE_TEST_VARIANT4(arm_sub_f16, 23, in_com1, in_com2, ref_sub, 23); -DEFINE_TEST_VARIANT4(arm_sub_f16, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_sub_f16, 7, in_com1, in_com2, ref_sub, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_sub_f16, 16, in_com1, in_com2, ref_sub, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_sub_f16, 23, in_com1, in_com2, ref_sub, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_sub_f16, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); static void test_arm_mult_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -111,10 +111,10 @@ static void test_arm_mult_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_mult_f16, 7, in_com1, in_com2, ref_mult, 7); -DEFINE_TEST_VARIANT4(arm_mult_f16, 16, in_com1, in_com2, ref_mult, 16); -DEFINE_TEST_VARIANT4(arm_mult_f16, 23, in_com1, in_com2, ref_mult, 23); -DEFINE_TEST_VARIANT4(arm_mult_f16, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_mult_f16, 7, in_com1, in_com2, ref_mult, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_mult_f16, 16, in_com1, in_com2, ref_mult, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_mult_f16, 23, in_com1, in_com2, ref_mult, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_mult_f16, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); static void test_arm_negate_f16( const uint16_t *input1, const uint16_t *ref, size_t length) @@ -143,10 +143,10 @@ static void test_arm_negate_f16( free(output); } -DEFINE_TEST_VARIANT3(arm_negate_f16, 7, in_com1, ref_negate, 7); -DEFINE_TEST_VARIANT3(arm_negate_f16, 16, in_com1, ref_negate, 16); -DEFINE_TEST_VARIANT3(arm_negate_f16, 23, in_com1, ref_negate, 23); -DEFINE_TEST_VARIANT3(arm_negate_f16, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_f16, arm_negate_f16, 7, in_com1, ref_negate, 7); +DEFINE_TEST_VARIANT3(basic_math_f16, arm_negate_f16, 16, in_com1, ref_negate, 16); +DEFINE_TEST_VARIANT3(basic_math_f16, arm_negate_f16, 23, in_com1, ref_negate, 23); +DEFINE_TEST_VARIANT3(basic_math_f16, arm_negate_f16, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); static void test_arm_offset_f16( const uint16_t *input1, float16_t scalar, const uint16_t *ref, @@ -176,10 +176,10 @@ static void test_arm_offset_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_offset_f16, 0p5_7, in_com1, 0.5f, ref_offset, 7); -DEFINE_TEST_VARIANT4(arm_offset_f16, 0p5_16, in_com1, 0.5f, ref_offset, 16); -DEFINE_TEST_VARIANT4(arm_offset_f16, 0p5_23, in_com1, 0.5f, ref_offset, 23); -DEFINE_TEST_VARIANT4(arm_offset_f16, long, in_com1, 0.5f, ref_offset, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_offset_f16, 0p5_7, in_com1, 0.5f, ref_offset, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_offset_f16, 0p5_16, in_com1, 0.5f, ref_offset, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_offset_f16, 0p5_23, in_com1, 0.5f, ref_offset, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_offset_f16, long, in_com1, 0.5f, ref_offset, ARRAY_SIZE(in_com1)); static void test_arm_scale_f16( const uint16_t *input1, float16_t scalar, const uint16_t *ref, @@ -209,10 +209,10 @@ static void test_arm_scale_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_scale_f16, 0p5_7, in_com1, 0.5f, ref_scale, 7); -DEFINE_TEST_VARIANT4(arm_scale_f16, 0p5_16, in_com1, 0.5f, ref_scale, 16); -DEFINE_TEST_VARIANT4(arm_scale_f16, 0p5_23, in_com1, 0.5f, ref_scale, 23); -DEFINE_TEST_VARIANT4(arm_scale_f16, long, in_com1, 0.5f, ref_scale, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_scale_f16, 0p5_7, in_com1, 0.5f, ref_scale, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_scale_f16, 0p5_16, in_com1, 0.5f, ref_scale, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_scale_f16, 0p5_23, in_com1, 0.5f, ref_scale, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_scale_f16, long, in_com1, 0.5f, ref_scale, ARRAY_SIZE(in_com1)); static void test_arm_dot_prod_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -243,10 +243,10 @@ static void test_arm_dot_prod_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_dot_prod_f16, 7, in_com1, in_com2, ref_dot_prod_3, 7); -DEFINE_TEST_VARIANT4(arm_dot_prod_f16, 16, in_com1, in_com2, ref_dot_prod_4, 16); -DEFINE_TEST_VARIANT4(arm_dot_prod_f16, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); -DEFINE_TEST_VARIANT4(arm_dot_prod_f16, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_f16, arm_dot_prod_f16, 7, in_com1, in_com2, ref_dot_prod_3, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_dot_prod_f16, 16, in_com1, in_com2, ref_dot_prod_4, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_dot_prod_f16, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, arm_dot_prod_f16, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); static void test_arm_abs_f16( @@ -276,10 +276,10 @@ static void test_arm_abs_f16( free(output); } -DEFINE_TEST_VARIANT3(arm_abs_f16, 7, in_com1, ref_abs, 7); -DEFINE_TEST_VARIANT3(arm_abs_f16, 16, in_com1, ref_abs, 16); -DEFINE_TEST_VARIANT3(arm_abs_f16, 23, in_com1, ref_abs, 23); -DEFINE_TEST_VARIANT3(arm_abs_f16, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_f16, arm_abs_f16, 7, in_com1, ref_abs, 7); +DEFINE_TEST_VARIANT3(basic_math_f16, arm_abs_f16, 16, in_com1, ref_abs, 16); +DEFINE_TEST_VARIANT3(basic_math_f16, arm_abs_f16, 23, in_com1, ref_abs, 23); +DEFINE_TEST_VARIANT3(basic_math_f16, arm_abs_f16, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); static void test_arm_clip_f16( const uint16_t *input, const uint16_t *ref, float16_t min, float16_t max, size_t length) @@ -308,52 +308,9 @@ static void test_arm_clip_f16( free(output); } -DEFINE_TEST_VARIANT5(arm_clip_f16, m0p5_m0p1, in_clip, ref_clip1, +DEFINE_TEST_VARIANT5(basic_math_f16, arm_clip_f16, m0p5_m0p1, in_clip, ref_clip1, -0.5f, -0.1f, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(arm_clip_f16, m0p5_0p5, in_clip, ref_clip2, +DEFINE_TEST_VARIANT5(basic_math_f16, arm_clip_f16, m0p5_0p5, in_clip, ref_clip2, -0.5f, 0.5f, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(arm_clip_f16, 0p1_0p5, in_clip, ref_clip3, +DEFINE_TEST_VARIANT5(basic_math_f16, arm_clip_f16, 0p1_0p5, in_clip, ref_clip3, 0.1f, 0.5f, ARRAY_SIZE(ref_clip3)); - -void test_basicmath_f16(void) -{ - ztest_test_suite(basicmath_f16, - ztest_unit_test(test_arm_add_f16_7), - ztest_unit_test(test_arm_add_f16_16), - ztest_unit_test(test_arm_add_f16_23), - ztest_unit_test(test_arm_sub_f16_7), - ztest_unit_test(test_arm_sub_f16_16), - ztest_unit_test(test_arm_sub_f16_23), - ztest_unit_test(test_arm_mult_f16_7), - ztest_unit_test(test_arm_mult_f16_16), - ztest_unit_test(test_arm_mult_f16_23), - ztest_unit_test(test_arm_negate_f16_7), - ztest_unit_test(test_arm_negate_f16_16), - ztest_unit_test(test_arm_negate_f16_23), - ztest_unit_test(test_arm_offset_f16_0p5_7), - ztest_unit_test(test_arm_offset_f16_0p5_16), - ztest_unit_test(test_arm_offset_f16_0p5_23), - ztest_unit_test(test_arm_scale_f16_0p5_7), - ztest_unit_test(test_arm_scale_f16_0p5_16), - ztest_unit_test(test_arm_scale_f16_0p5_23), - ztest_unit_test(test_arm_dot_prod_f16_7), - ztest_unit_test(test_arm_dot_prod_f16_16), - ztest_unit_test(test_arm_dot_prod_f16_23), - ztest_unit_test(test_arm_abs_f16_7), - ztest_unit_test(test_arm_abs_f16_16), - ztest_unit_test(test_arm_abs_f16_23), - ztest_unit_test(test_arm_add_f16_long), - ztest_unit_test(test_arm_sub_f16_long), - ztest_unit_test(test_arm_mult_f16_long), - ztest_unit_test(test_arm_negate_f16_long), - ztest_unit_test(test_arm_offset_f16_long), - ztest_unit_test(test_arm_scale_f16_long), - ztest_unit_test(test_arm_dot_prod_f16_long), - ztest_unit_test(test_arm_abs_f16_long), - ztest_unit_test(test_arm_clip_f16_m0p5_m0p1), - ztest_unit_test(test_arm_clip_f16_m0p5_0p5), - ztest_unit_test(test_arm_clip_f16_0p1_0p5) - ); - - ztest_run_test_suite(basicmath_f16); -} diff --git a/tests/lib/cmsis_dsp/basicmath/src/f32.c b/tests/lib/cmsis_dsp/basicmath/src/f32.c index 3fb4801b7556..b01d3e675a9c 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/f32.c +++ b/tests/lib/cmsis_dsp/basicmath/src/f32.c @@ -44,10 +44,10 @@ static void test_arm_add_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_add_f32, 3, in_com1, in_com2, ref_add, 3); -DEFINE_TEST_VARIANT4(arm_add_f32, 8, in_com1, in_com2, ref_add, 8); -DEFINE_TEST_VARIANT4(arm_add_f32, 11, in_com1, in_com2, ref_add, 11); -DEFINE_TEST_VARIANT4(arm_add_f32, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_add_f32, 3, in_com1, in_com2, ref_add, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_add_f32, 8, in_com1, in_com2, ref_add, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_add_f32, 11, in_com1, in_com2, ref_add, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_add_f32, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); static void test_arm_sub_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, @@ -77,10 +77,10 @@ static void test_arm_sub_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_sub_f32, 3, in_com1, in_com2, ref_sub, 3); -DEFINE_TEST_VARIANT4(arm_sub_f32, 8, in_com1, in_com2, ref_sub, 8); -DEFINE_TEST_VARIANT4(arm_sub_f32, 11, in_com1, in_com2, ref_sub, 11); -DEFINE_TEST_VARIANT4(arm_sub_f32, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_sub_f32, 3, in_com1, in_com2, ref_sub, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_sub_f32, 8, in_com1, in_com2, ref_sub, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_sub_f32, 11, in_com1, in_com2, ref_sub, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_sub_f32, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); static void test_arm_mult_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, @@ -110,10 +110,10 @@ static void test_arm_mult_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_mult_f32, 3, in_com1, in_com2, ref_mult, 3); -DEFINE_TEST_VARIANT4(arm_mult_f32, 8, in_com1, in_com2, ref_mult, 8); -DEFINE_TEST_VARIANT4(arm_mult_f32, 11, in_com1, in_com2, ref_mult, 11); -DEFINE_TEST_VARIANT4(arm_mult_f32, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_mult_f32, 3, in_com1, in_com2, ref_mult, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_mult_f32, 8, in_com1, in_com2, ref_mult, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_mult_f32, 11, in_com1, in_com2, ref_mult, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_mult_f32, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); static void test_arm_negate_f32( const uint32_t *input1, const uint32_t *ref, size_t length) @@ -142,10 +142,10 @@ static void test_arm_negate_f32( free(output); } -DEFINE_TEST_VARIANT3(arm_negate_f32, 3, in_com1, ref_negate, 3); -DEFINE_TEST_VARIANT3(arm_negate_f32, 8, in_com1, ref_negate, 8); -DEFINE_TEST_VARIANT3(arm_negate_f32, 11, in_com1, ref_negate, 11); -DEFINE_TEST_VARIANT3(arm_negate_f32, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_f32, arm_negate_f32, 3, in_com1, ref_negate, 3); +DEFINE_TEST_VARIANT3(basic_math_f32, arm_negate_f32, 8, in_com1, ref_negate, 8); +DEFINE_TEST_VARIANT3(basic_math_f32, arm_negate_f32, 11, in_com1, ref_negate, 11); +DEFINE_TEST_VARIANT3(basic_math_f32, arm_negate_f32, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); static void test_arm_offset_f32( const uint32_t *input1, float32_t scalar, const uint32_t *ref, @@ -175,10 +175,10 @@ static void test_arm_offset_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_offset_f32, 0p5_3, in_com1, 0.5f, ref_offset, 3); -DEFINE_TEST_VARIANT4(arm_offset_f32, 0p5_8, in_com1, 0.5f, ref_offset, 8); -DEFINE_TEST_VARIANT4(arm_offset_f32, 0p5_11, in_com1, 0.5f, ref_offset, 11); -DEFINE_TEST_VARIANT4(arm_offset_f32, long, in_com1, 0.5f, ref_offset, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_offset_f32, 0p5_3, in_com1, 0.5f, ref_offset, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_offset_f32, 0p5_8, in_com1, 0.5f, ref_offset, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_offset_f32, 0p5_11, in_com1, 0.5f, ref_offset, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_offset_f32, long, in_com1, 0.5f, ref_offset, ARRAY_SIZE(in_com1)); static void test_arm_scale_f32( const uint32_t *input1, float32_t scalar, const uint32_t *ref, @@ -208,10 +208,10 @@ static void test_arm_scale_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_scale_f32, 0p5_3, in_com1, 0.5f, ref_scale, 3); -DEFINE_TEST_VARIANT4(arm_scale_f32, 0p5_8, in_com1, 0.5f, ref_scale, 8); -DEFINE_TEST_VARIANT4(arm_scale_f32, 0p5_11, in_com1, 0.5f, ref_scale, 11); -DEFINE_TEST_VARIANT4(arm_scale_f32, long, in_com1, 0.5f, ref_scale, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_scale_f32, 0p5_3, in_com1, 0.5f, ref_scale, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_scale_f32, 0p5_8, in_com1, 0.5f, ref_scale, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_scale_f32, 0p5_11, in_com1, 0.5f, ref_scale, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_scale_f32, long, in_com1, 0.5f, ref_scale, ARRAY_SIZE(in_com1)); static void test_arm_dot_prod_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, @@ -242,10 +242,10 @@ static void test_arm_dot_prod_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_dot_prod_f32, 3, in_com1, in_com2, ref_dot_prod_3, 3); -DEFINE_TEST_VARIANT4(arm_dot_prod_f32, 8, in_com1, in_com2, ref_dot_prod_4, 8); -DEFINE_TEST_VARIANT4(arm_dot_prod_f32, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); -DEFINE_TEST_VARIANT4(arm_dot_prod_f32, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_f32, arm_dot_prod_f32, 3, in_com1, in_com2, ref_dot_prod_3, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_dot_prod_f32, 8, in_com1, in_com2, ref_dot_prod_4, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_dot_prod_f32, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, arm_dot_prod_f32, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); static void test_arm_abs_f32( @@ -275,10 +275,10 @@ static void test_arm_abs_f32( free(output); } -DEFINE_TEST_VARIANT3(arm_abs_f32, 3, in_com1, ref_abs, 3); -DEFINE_TEST_VARIANT3(arm_abs_f32, 8, in_com1, ref_abs, 8); -DEFINE_TEST_VARIANT3(arm_abs_f32, 11, in_com1, ref_abs, 11); -DEFINE_TEST_VARIANT3(arm_abs_f32, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_f32, arm_abs_f32, 3, in_com1, ref_abs, 3); +DEFINE_TEST_VARIANT3(basic_math_f32, arm_abs_f32, 8, in_com1, ref_abs, 8); +DEFINE_TEST_VARIANT3(basic_math_f32, arm_abs_f32, 11, in_com1, ref_abs, 11); +DEFINE_TEST_VARIANT3(basic_math_f32, arm_abs_f32, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); static void test_arm_clip_f32( const uint32_t *input, const uint32_t *ref, float32_t min, float32_t max, size_t length) @@ -307,52 +307,9 @@ static void test_arm_clip_f32( free(output); } -DEFINE_TEST_VARIANT5(arm_clip_f32, m0p5_m0p1, in_clip, ref_clip1, +DEFINE_TEST_VARIANT5(basic_math_f32, arm_clip_f32, m0p5_m0p1, in_clip, ref_clip1, -0.5f, -0.1f, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(arm_clip_f32, m0p5_0p5, in_clip, ref_clip2, +DEFINE_TEST_VARIANT5(basic_math_f32, arm_clip_f32, m0p5_0p5, in_clip, ref_clip2, -0.5f, 0.5f, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(arm_clip_f32, 0p1_0p5, in_clip, ref_clip3, +DEFINE_TEST_VARIANT5(basic_math_f32, arm_clip_f32, 0p1_0p5, in_clip, ref_clip3, 0.1f, 0.5f, ARRAY_SIZE(ref_clip3)); - -void test_basicmath_f32(void) -{ - ztest_test_suite(basicmath_f32, - ztest_unit_test(test_arm_add_f32_3), - ztest_unit_test(test_arm_add_f32_8), - ztest_unit_test(test_arm_add_f32_11), - ztest_unit_test(test_arm_sub_f32_3), - ztest_unit_test(test_arm_sub_f32_8), - ztest_unit_test(test_arm_sub_f32_11), - ztest_unit_test(test_arm_mult_f32_3), - ztest_unit_test(test_arm_mult_f32_8), - ztest_unit_test(test_arm_mult_f32_11), - ztest_unit_test(test_arm_negate_f32_3), - ztest_unit_test(test_arm_negate_f32_8), - ztest_unit_test(test_arm_negate_f32_11), - ztest_unit_test(test_arm_offset_f32_0p5_3), - ztest_unit_test(test_arm_offset_f32_0p5_8), - ztest_unit_test(test_arm_offset_f32_0p5_11), - ztest_unit_test(test_arm_scale_f32_0p5_3), - ztest_unit_test(test_arm_scale_f32_0p5_8), - ztest_unit_test(test_arm_scale_f32_0p5_11), - ztest_unit_test(test_arm_dot_prod_f32_3), - ztest_unit_test(test_arm_dot_prod_f32_8), - ztest_unit_test(test_arm_dot_prod_f32_11), - ztest_unit_test(test_arm_abs_f32_3), - ztest_unit_test(test_arm_abs_f32_8), - ztest_unit_test(test_arm_abs_f32_11), - ztest_unit_test(test_arm_add_f32_long), - ztest_unit_test(test_arm_sub_f32_long), - ztest_unit_test(test_arm_mult_f32_long), - ztest_unit_test(test_arm_negate_f32_long), - ztest_unit_test(test_arm_offset_f32_long), - ztest_unit_test(test_arm_scale_f32_long), - ztest_unit_test(test_arm_dot_prod_f32_long), - ztest_unit_test(test_arm_abs_f32_long), - ztest_unit_test(test_arm_clip_f32_m0p5_m0p1), - ztest_unit_test(test_arm_clip_f32_m0p5_0p5), - ztest_unit_test(test_arm_clip_f32_0p1_0p5) - ); - - ztest_run_test_suite(basicmath_f32); -} diff --git a/tests/lib/cmsis_dsp/basicmath/src/main.c b/tests/lib/cmsis_dsp/basicmath/src/main.c deleted file mode 100644 index ee05da2f1307..000000000000 --- a/tests/lib/cmsis_dsp/basicmath/src/main.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2020 Stephanos Ioannidis - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -extern void test_basicmath_q7(void); -extern void test_basicmath_q15(void); -extern void test_basicmath_q31(void); -extern void test_basicmath_f16(void); -extern void test_basicmath_f32(void); - -void test_main(void) -{ - test_basicmath_q7(); - test_basicmath_q15(); - test_basicmath_q31(); -#ifdef CONFIG_CMSIS_DSP_FLOAT16 - test_basicmath_f16(); -#endif - test_basicmath_f32(); -} diff --git a/tests/lib/cmsis_dsp/basicmath/src/q15.c b/tests/lib/cmsis_dsp/basicmath/src/q15.c index 26c0521718ca..e4323fd43574 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/q15.c +++ b/tests/lib/cmsis_dsp/basicmath/src/q15.c @@ -44,12 +44,12 @@ static void test_arm_add_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_add_q15, 7, in_com1, in_com2, ref_add, 7); -DEFINE_TEST_VARIANT4(arm_add_q15, 16, in_com1, in_com2, ref_add, 16); -DEFINE_TEST_VARIANT4(arm_add_q15, 23, in_com1, in_com2, ref_add, 23); -DEFINE_TEST_VARIANT4(arm_add_q15, possat, in_maxpos, in_maxpos, ref_add_possat, 17); -DEFINE_TEST_VARIANT4(arm_add_q15, negsat, in_maxneg, in_maxneg, ref_add_negsat, 17); -DEFINE_TEST_VARIANT4(arm_add_q15, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, 7, in_com1, in_com2, ref_add, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, 16, in_com1, in_com2, ref_add, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, 23, in_com1, in_com2, ref_add, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, possat, in_maxpos, in_maxpos, ref_add_possat, 17); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, negsat, in_maxneg, in_maxneg, ref_add_negsat, 17); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); static void test_arm_sub_q15( const q15_t *input1, const q15_t *input2, const q15_t *ref, @@ -77,12 +77,12 @@ static void test_arm_sub_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_sub_q15, 7, in_com1, in_com2, ref_sub, 7); -DEFINE_TEST_VARIANT4(arm_sub_q15, 16, in_com1, in_com2, ref_sub, 16); -DEFINE_TEST_VARIANT4(arm_sub_q15, 23, in_com1, in_com2, ref_sub, 23); -DEFINE_TEST_VARIANT4(arm_sub_q15, possat, in_maxpos, in_maxneg, ref_sub_possat, 17); -DEFINE_TEST_VARIANT4(arm_sub_q15, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 17); -DEFINE_TEST_VARIANT4(arm_sub_q15, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, 7, in_com1, in_com2, ref_sub, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, 16, in_com1, in_com2, ref_sub, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, 23, in_com1, in_com2, ref_sub, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, possat, in_maxpos, in_maxneg, ref_sub_possat, 17); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 17); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); static void test_arm_mult_q15( const q15_t *input1, const q15_t *input2, const q15_t *ref, @@ -110,11 +110,11 @@ static void test_arm_mult_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_mult_q15, 7, in_com1, in_com2, ref_mult, 7); -DEFINE_TEST_VARIANT4(arm_mult_q15, 16, in_com1, in_com2, ref_mult, 16); -DEFINE_TEST_VARIANT4(arm_mult_q15, 23, in_com1, in_com2, ref_mult, 23); -DEFINE_TEST_VARIANT4(arm_mult_q15, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 17); -DEFINE_TEST_VARIANT4(arm_mult_q15, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, 7, in_com1, in_com2, ref_mult, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, 16, in_com1, in_com2, ref_mult, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, 23, in_com1, in_com2, ref_mult, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 17); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); static void test_arm_negate_q15( const q15_t *input1, const q15_t *ref, size_t length) @@ -141,11 +141,11 @@ static void test_arm_negate_q15( free(output); } -DEFINE_TEST_VARIANT3(arm_negate_q15, 7, in_com1, ref_negate, 7); -DEFINE_TEST_VARIANT3(arm_negate_q15, 16, in_com1, ref_negate, 16); -DEFINE_TEST_VARIANT3(arm_negate_q15, 23, in_com1, ref_negate, 23); -DEFINE_TEST_VARIANT3(arm_negate_q15, possat, in_maxneg2, ref_negate_possat, 17); -DEFINE_TEST_VARIANT3(arm_negate_q15, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, 7, in_com1, ref_negate, 7); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, 16, in_com1, ref_negate, 16); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, 23, in_com1, ref_negate, 23); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, possat, in_maxneg2, ref_negate_possat, 17); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); static void test_arm_offset_q15( const q15_t *input1, q15_t scalar, const q15_t *ref, size_t length) @@ -172,12 +172,12 @@ static void test_arm_offset_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_offset_q15, 0p5_7, in_com1, 0x4000, ref_offset, 7); -DEFINE_TEST_VARIANT4(arm_offset_q15, 0p5_16, in_com1, 0x4000, ref_offset, 16); -DEFINE_TEST_VARIANT4(arm_offset_q15, 0p5_23, in_com1, 0x4000, ref_offset, 23); -DEFINE_TEST_VARIANT4(arm_offset_q15, possat, in_maxpos, 0x7333, ref_offset_possat, 17); -DEFINE_TEST_VARIANT4(arm_offset_q15, negsat, in_maxneg, 0x8ccd, ref_offset_negsat, 17); -DEFINE_TEST_VARIANT4(arm_offset_q15, long, in_com1, 0x4000, ref_offset, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, 0p5_7, in_com1, 0x4000, ref_offset, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, 0p5_16, in_com1, 0x4000, ref_offset, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, 0p5_23, in_com1, 0x4000, ref_offset, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, possat, in_maxpos, 0x7333, ref_offset_possat, 17); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, negsat, in_maxneg, 0x8ccd, ref_offset_negsat, 17); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, long, in_com1, 0x4000, ref_offset, ARRAY_SIZE(in_com1)); static void test_arm_scale_q15( const q15_t *input1, q15_t scalar, const q15_t *ref, size_t length) @@ -204,11 +204,11 @@ static void test_arm_scale_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_scale_q15, 0p5_7, in_com1, 0x4000, ref_scale, 7); -DEFINE_TEST_VARIANT4(arm_scale_q15, 0p5_16, in_com1, 0x4000, ref_scale, 16); -DEFINE_TEST_VARIANT4(arm_scale_q15, 0p5_23, in_com1, 0x4000, ref_scale, 23); -DEFINE_TEST_VARIANT4(arm_scale_q15, possat, in_maxneg2, 0x8000, ref_scale_possat, 17); -DEFINE_TEST_VARIANT4(arm_scale_q15, long, in_com1, 0x4000, ref_scale, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, 0p5_7, in_com1, 0x4000, ref_scale, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, 0p5_16, in_com1, 0x4000, ref_scale, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, 0p5_23, in_com1, 0x4000, ref_scale, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, possat, in_maxneg2, 0x8000, ref_scale_possat, 17); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, long, in_com1, 0x4000, ref_scale, ARRAY_SIZE(in_com1)); static void test_arm_dot_prod_q15( const q15_t *input1, const q15_t *input2, const q63_t *ref, @@ -236,10 +236,10 @@ static void test_arm_dot_prod_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_dot_prod_q15, 7, in_com1, in_com2, ref_dot_prod_3, 7); -DEFINE_TEST_VARIANT4(arm_dot_prod_q15, 16, in_com1, in_com2, ref_dot_prod_4, 16); -DEFINE_TEST_VARIANT4(arm_dot_prod_q15, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); -DEFINE_TEST_VARIANT4(arm_dot_prod_q15, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_q15, arm_dot_prod_q15, 7, in_com1, in_com2, ref_dot_prod_3, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_dot_prod_q15, 16, in_com1, in_com2, ref_dot_prod_4, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_dot_prod_q15, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_dot_prod_q15, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); static void test_arm_abs_q15( @@ -267,10 +267,10 @@ static void test_arm_abs_q15( free(output); } -DEFINE_TEST_VARIANT3(arm_abs_q15, 7, in_com1, ref_abs, 7); -DEFINE_TEST_VARIANT3(arm_abs_q15, 16, in_com1, ref_abs, 16); -DEFINE_TEST_VARIANT3(arm_abs_q15, 23, in_com1, ref_abs, 23); -DEFINE_TEST_VARIANT3(arm_abs_q15, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_abs_q15, 7, in_com1, ref_abs, 7); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_abs_q15, 16, in_com1, ref_abs, 16); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_abs_q15, 23, in_com1, ref_abs, 23); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_abs_q15, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); static void test_arm_shift_q15( const q15_t *input1, const q15_t *ref, size_t length) @@ -297,9 +297,9 @@ static void test_arm_shift_q15( free(output); } -DEFINE_TEST_VARIANT3(arm_shift_q15, rand, in_rand, ref_shift, 17); -DEFINE_TEST_VARIANT3(arm_shift_q15, possat, in_maxpos, ref_shift_possat, 17); -DEFINE_TEST_VARIANT3(arm_shift_q15, negsat, in_maxneg, ref_shift_negsat, 17); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_shift_q15, rand, in_rand, ref_shift, 17); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_shift_q15, possat, in_maxpos, ref_shift_possat, 17); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_shift_q15, negsat, in_maxneg, ref_shift_negsat, 17); static void test_arm_and_u16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -323,9 +323,9 @@ static void test_arm_and_u16( free(output); } -DEFINE_TEST_VARIANT4(arm_and_u16, 7, in_bitwise1, in_bitwise2, ref_and, 7); -DEFINE_TEST_VARIANT4(arm_and_u16, 16, in_bitwise1, in_bitwise2, ref_and, 16); -DEFINE_TEST_VARIANT4(arm_and_u16, 23, in_bitwise1, in_bitwise2, ref_and, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_and_u16, 7, in_bitwise1, in_bitwise2, ref_and, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_and_u16, 16, in_bitwise1, in_bitwise2, ref_and, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_and_u16, 23, in_bitwise1, in_bitwise2, ref_and, 23); static void test_arm_or_u16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -349,9 +349,9 @@ static void test_arm_or_u16( free(output); } -DEFINE_TEST_VARIANT4(arm_or_u16, 7, in_bitwise1, in_bitwise2, ref_or, 7); -DEFINE_TEST_VARIANT4(arm_or_u16, 16, in_bitwise1, in_bitwise2, ref_or, 16); -DEFINE_TEST_VARIANT4(arm_or_u16, 23, in_bitwise1, in_bitwise2, ref_or, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_or_u16, 7, in_bitwise1, in_bitwise2, ref_or, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_or_u16, 16, in_bitwise1, in_bitwise2, ref_or, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_or_u16, 23, in_bitwise1, in_bitwise2, ref_or, 23); static void test_arm_not_u16( const uint16_t *input1, const uint16_t *ref, size_t length) @@ -374,9 +374,9 @@ static void test_arm_not_u16( free(output); } -DEFINE_TEST_VARIANT3(arm_not_u16, 7, in_bitwise1, ref_not, 7); -DEFINE_TEST_VARIANT3(arm_not_u16, 16, in_bitwise1, ref_not, 16); -DEFINE_TEST_VARIANT3(arm_not_u16, 23, in_bitwise1, ref_not, 23); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_not_u16, 7, in_bitwise1, ref_not, 7); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_not_u16, 16, in_bitwise1, ref_not, 16); +DEFINE_TEST_VARIANT3(basic_math_q15, arm_not_u16, 23, in_bitwise1, ref_not, 23); static void test_arm_xor_u16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -400,9 +400,9 @@ static void test_arm_xor_u16( free(output); } -DEFINE_TEST_VARIANT4(arm_xor_u16, 7, in_bitwise1, in_bitwise2, ref_xor, 7); -DEFINE_TEST_VARIANT4(arm_xor_u16, 16, in_bitwise1, in_bitwise2, ref_xor, 16); -DEFINE_TEST_VARIANT4(arm_xor_u16, 23, in_bitwise1, in_bitwise2, ref_xor, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_xor_u16, 7, in_bitwise1, in_bitwise2, ref_xor, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_xor_u16, 16, in_bitwise1, in_bitwise2, ref_xor, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, arm_xor_u16, 23, in_bitwise1, in_bitwise2, ref_xor, 23); static void test_arm_clip_q15( const q15_t *input, const q15_t *ref, q15_t min, q15_t max, size_t length) @@ -425,76 +425,9 @@ static void test_arm_clip_q15( free(output); } -DEFINE_TEST_VARIANT5(arm_clip_q15, c000_f333, in_clip, ref_clip1, +DEFINE_TEST_VARIANT5(basic_math_q15, arm_clip_q15, c000_f333, in_clip, ref_clip1, 0xc000, 0xf333, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(arm_clip_q15, c000_4000, in_clip, ref_clip2, +DEFINE_TEST_VARIANT5(basic_math_q15, arm_clip_q15, c000_4000, in_clip, ref_clip2, 0xc000, 0x4000, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(arm_clip_q15, 0ccd_4000, in_clip, ref_clip3, +DEFINE_TEST_VARIANT5(basic_math_q15, arm_clip_q15, 0ccd_4000, in_clip, ref_clip3, 0x0ccd, 0x4000, ARRAY_SIZE(ref_clip3)); - -void test_basicmath_q15(void) -{ - ztest_test_suite(basicmath_q15, - ztest_unit_test(test_arm_add_q15_7), - ztest_unit_test(test_arm_add_q15_16), - ztest_unit_test(test_arm_add_q15_23), - ztest_unit_test(test_arm_sub_q15_7), - ztest_unit_test(test_arm_sub_q15_16), - ztest_unit_test(test_arm_sub_q15_23), - ztest_unit_test(test_arm_mult_q15_7), - ztest_unit_test(test_arm_mult_q15_16), - ztest_unit_test(test_arm_mult_q15_23), - ztest_unit_test(test_arm_negate_q15_7), - ztest_unit_test(test_arm_negate_q15_16), - ztest_unit_test(test_arm_negate_q15_23), - ztest_unit_test(test_arm_offset_q15_0p5_7), - ztest_unit_test(test_arm_offset_q15_0p5_16), - ztest_unit_test(test_arm_offset_q15_0p5_23), - ztest_unit_test(test_arm_scale_q15_0p5_7), - ztest_unit_test(test_arm_scale_q15_0p5_16), - ztest_unit_test(test_arm_scale_q15_0p5_23), - ztest_unit_test(test_arm_dot_prod_q15_7), - ztest_unit_test(test_arm_dot_prod_q15_16), - ztest_unit_test(test_arm_dot_prod_q15_23), - ztest_unit_test(test_arm_abs_q15_7), - ztest_unit_test(test_arm_abs_q15_16), - ztest_unit_test(test_arm_abs_q15_23), - ztest_unit_test(test_arm_shift_q15_rand), - ztest_unit_test(test_arm_add_q15_possat), - ztest_unit_test(test_arm_add_q15_negsat), - ztest_unit_test(test_arm_sub_q15_possat), - ztest_unit_test(test_arm_sub_q15_negsat), - ztest_unit_test(test_arm_mult_q15_possat), - ztest_unit_test(test_arm_negate_q15_possat), - ztest_unit_test(test_arm_offset_q15_possat), - ztest_unit_test(test_arm_offset_q15_negsat), - ztest_unit_test(test_arm_scale_q15_possat), - ztest_unit_test(test_arm_shift_q15_possat), - ztest_unit_test(test_arm_shift_q15_negsat), - ztest_unit_test(test_arm_and_u16_7), - ztest_unit_test(test_arm_and_u16_16), - ztest_unit_test(test_arm_and_u16_23), - ztest_unit_test(test_arm_or_u16_7), - ztest_unit_test(test_arm_or_u16_16), - ztest_unit_test(test_arm_or_u16_23), - ztest_unit_test(test_arm_not_u16_7), - ztest_unit_test(test_arm_not_u16_16), - ztest_unit_test(test_arm_not_u16_23), - ztest_unit_test(test_arm_xor_u16_7), - ztest_unit_test(test_arm_xor_u16_16), - ztest_unit_test(test_arm_xor_u16_23), - ztest_unit_test(test_arm_add_q15_long), - ztest_unit_test(test_arm_sub_q15_long), - ztest_unit_test(test_arm_mult_q15_long), - ztest_unit_test(test_arm_negate_q15_long), - ztest_unit_test(test_arm_offset_q15_long), - ztest_unit_test(test_arm_scale_q15_long), - ztest_unit_test(test_arm_dot_prod_q15_long), - ztest_unit_test(test_arm_abs_q15_long), - ztest_unit_test(test_arm_clip_q15_c000_f333), - ztest_unit_test(test_arm_clip_q15_c000_4000), - ztest_unit_test(test_arm_clip_q15_0ccd_4000) - ); - - ztest_run_test_suite(basicmath_q15); -} diff --git a/tests/lib/cmsis_dsp/basicmath/src/q31.c b/tests/lib/cmsis_dsp/basicmath/src/q31.c index 2554a094853c..36e000e3a2df 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/q31.c +++ b/tests/lib/cmsis_dsp/basicmath/src/q31.c @@ -42,12 +42,12 @@ static void test_arm_add_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_add_q31, 3, in_com1, in_com2, ref_add, 3); -DEFINE_TEST_VARIANT4(arm_add_q31, 8, in_com1, in_com2, ref_add, 8); -DEFINE_TEST_VARIANT4(arm_add_q31, 11, in_com1, in_com2, ref_add, 11); -DEFINE_TEST_VARIANT4(arm_add_q31, possat, in_maxpos, in_maxpos, ref_add_possat, 9); -DEFINE_TEST_VARIANT4(arm_add_q31, negsat, in_maxneg, in_maxneg, ref_add_negsat, 9); -DEFINE_TEST_VARIANT4(arm_add_q31, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, 3, in_com1, in_com2, ref_add, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, 8, in_com1, in_com2, ref_add, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, 11, in_com1, in_com2, ref_add, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, possat, in_maxpos, in_maxpos, ref_add_possat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, negsat, in_maxneg, in_maxneg, ref_add_negsat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); static void test_arm_sub_q31( const q31_t *input1, const q31_t *input2, const q31_t *ref, size_t length) @@ -74,12 +74,12 @@ static void test_arm_sub_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_sub_q31, 3, in_com1, in_com2, ref_sub, 3); -DEFINE_TEST_VARIANT4(arm_sub_q31, 8, in_com1, in_com2, ref_sub, 8); -DEFINE_TEST_VARIANT4(arm_sub_q31, 11, in_com1, in_com2, ref_sub, 11); -DEFINE_TEST_VARIANT4(arm_sub_q31, possat, in_maxpos, in_maxneg, ref_sub_possat, 9); -DEFINE_TEST_VARIANT4(arm_sub_q31, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 9); -DEFINE_TEST_VARIANT4(arm_sub_q31, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, 3, in_com1, in_com2, ref_sub, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, 8, in_com1, in_com2, ref_sub, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, 11, in_com1, in_com2, ref_sub, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, possat, in_maxpos, in_maxneg, ref_sub_possat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); static void test_arm_mult_q31( const q31_t *input1, const q31_t *input2, const q31_t *ref, size_t length) @@ -106,11 +106,11 @@ static void test_arm_mult_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_mult_q31, 3, in_com1, in_com2, ref_mult, 3); -DEFINE_TEST_VARIANT4(arm_mult_q31, 8, in_com1, in_com2, ref_mult, 8); -DEFINE_TEST_VARIANT4(arm_mult_q31, 11, in_com1, in_com2, ref_mult, 11); -DEFINE_TEST_VARIANT4(arm_mult_q31, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 9); -DEFINE_TEST_VARIANT4(arm_mult_q31, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, 3, in_com1, in_com2, ref_mult, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, 8, in_com1, in_com2, ref_mult, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, 11, in_com1, in_com2, ref_mult, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); static void test_arm_negate_q31( const q31_t *input1, const q31_t *ref, size_t length) @@ -137,11 +137,11 @@ static void test_arm_negate_q31( free(output); } -DEFINE_TEST_VARIANT3(arm_negate_q31, 3, in_com1, ref_negate, 3); -DEFINE_TEST_VARIANT3(arm_negate_q31, 8, in_com1, ref_negate, 8); -DEFINE_TEST_VARIANT3(arm_negate_q31, 11, in_com1, ref_negate, 11); -DEFINE_TEST_VARIANT3(arm_negate_q31, possat, in_maxneg2, ref_negate_possat, 9); -DEFINE_TEST_VARIANT3(arm_negate_q31, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, 3, in_com1, ref_negate, 3); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, 8, in_com1, ref_negate, 8); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, 11, in_com1, ref_negate, 11); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, possat, in_maxneg2, ref_negate_possat, 9); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); static void test_arm_offset_q31( const q31_t *input1, q31_t scalar, const q31_t *ref, size_t length) @@ -168,12 +168,12 @@ static void test_arm_offset_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_offset_q31, 0p5_3, in_com1, 0x40000000, ref_offset, 3); -DEFINE_TEST_VARIANT4(arm_offset_q31, 0p5_8, in_com1, 0x40000000, ref_offset, 8); -DEFINE_TEST_VARIANT4(arm_offset_q31, 0p5_11, in_com1, 0x40000000, ref_offset, 11); -DEFINE_TEST_VARIANT4(arm_offset_q31, possat, in_maxpos, 0x73333333, ref_offset_possat, 9); -DEFINE_TEST_VARIANT4(arm_offset_q31, negsat, in_maxneg, 0x8ccccccd, ref_offset_negsat, 9); -DEFINE_TEST_VARIANT4(arm_offset_q31, long, in_com1, 0x40000000, ref_offset, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, 0p5_3, in_com1, 0x40000000, ref_offset, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, 0p5_8, in_com1, 0x40000000, ref_offset, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, 0p5_11, in_com1, 0x40000000, ref_offset, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, possat, in_maxpos, 0x73333333, ref_offset_possat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, negsat, in_maxneg, 0x8ccccccd, ref_offset_negsat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, long, in_com1, 0x40000000, ref_offset, ARRAY_SIZE(in_com1)); static void test_arm_scale_q31( const q31_t *input1, q31_t scalar, const q31_t *ref, size_t length) @@ -200,11 +200,11 @@ static void test_arm_scale_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_scale_q31, 0p5_3, in_com1, 0x40000000, ref_scale, 3); -DEFINE_TEST_VARIANT4(arm_scale_q31, 0p5_8, in_com1, 0x40000000, ref_scale, 8); -DEFINE_TEST_VARIANT4(arm_scale_q31, 0p5_11, in_com1, 0x40000000, ref_scale, 11); -DEFINE_TEST_VARIANT4(arm_scale_q31, possat, in_maxneg2, 0x80000000, ref_scale_possat, 9); -DEFINE_TEST_VARIANT4(arm_scale_q31, long, in_com1, 0x40000000, ref_scale, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, 0p5_3, in_com1, 0x40000000, ref_scale, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, 0p5_8, in_com1, 0x40000000, ref_scale, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, 0p5_11, in_com1, 0x40000000, ref_scale, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, possat, in_maxneg2, 0x80000000, ref_scale_possat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, long, in_com1, 0x40000000, ref_scale, ARRAY_SIZE(in_com1)); static void test_arm_dot_prod_q31( const q31_t *input1, const q31_t *input2, const q63_t *ref, size_t length) @@ -231,10 +231,10 @@ static void test_arm_dot_prod_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_dot_prod_q31, 3, in_com1, in_com2, ref_dot_prod_3, 3); -DEFINE_TEST_VARIANT4(arm_dot_prod_q31, 8, in_com1, in_com2, ref_dot_prod_4, 8); -DEFINE_TEST_VARIANT4(arm_dot_prod_q31, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); -DEFINE_TEST_VARIANT4(arm_dot_prod_q31, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_q31, arm_dot_prod_q31, 3, in_com1, in_com2, ref_dot_prod_3, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_dot_prod_q31, 8, in_com1, in_com2, ref_dot_prod_4, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_dot_prod_q31, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_dot_prod_q31, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); static void test_arm_abs_q31( @@ -262,10 +262,10 @@ static void test_arm_abs_q31( free(output); } -DEFINE_TEST_VARIANT3(arm_abs_q31, 3, in_com1, ref_abs, 3); -DEFINE_TEST_VARIANT3(arm_abs_q31, 8, in_com1, ref_abs, 8); -DEFINE_TEST_VARIANT3(arm_abs_q31, 11, in_com1, ref_abs, 11); -DEFINE_TEST_VARIANT3(arm_abs_q31, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_abs_q31, 3, in_com1, ref_abs, 3); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_abs_q31, 8, in_com1, ref_abs, 8); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_abs_q31, 11, in_com1, ref_abs, 11); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_abs_q31, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); static void test_arm_shift_q31( const q31_t *input1, const q31_t *ref, size_t length) @@ -292,9 +292,9 @@ static void test_arm_shift_q31( free(output); } -DEFINE_TEST_VARIANT3(arm_shift_q31, rand, in_rand, ref_shift, 9); -DEFINE_TEST_VARIANT3(arm_shift_q31, possat, in_maxpos, ref_shift_possat, 9); -DEFINE_TEST_VARIANT3(arm_shift_q31, negsat, in_maxneg, ref_shift_negsat, 9); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_shift_q31, rand, in_rand, ref_shift, 9); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_shift_q31, possat, in_maxpos, ref_shift_possat, 9); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_shift_q31, negsat, in_maxneg, ref_shift_negsat, 9); static void test_arm_and_u32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) @@ -317,9 +317,9 @@ static void test_arm_and_u32( free(output); } -DEFINE_TEST_VARIANT4(arm_and_u32, 3, in_bitwise1, in_bitwise2, ref_and, 3); -DEFINE_TEST_VARIANT4(arm_and_u32, 8, in_bitwise1, in_bitwise2, ref_and, 8); -DEFINE_TEST_VARIANT4(arm_and_u32, 11, in_bitwise1, in_bitwise2, ref_and, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_and_u32, 3, in_bitwise1, in_bitwise2, ref_and, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_and_u32, 8, in_bitwise1, in_bitwise2, ref_and, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_and_u32, 11, in_bitwise1, in_bitwise2, ref_and, 11); static void test_arm_or_u32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) @@ -342,9 +342,9 @@ static void test_arm_or_u32( free(output); } -DEFINE_TEST_VARIANT4(arm_or_u32, 3, in_bitwise1, in_bitwise2, ref_or, 3); -DEFINE_TEST_VARIANT4(arm_or_u32, 8, in_bitwise1, in_bitwise2, ref_or, 8); -DEFINE_TEST_VARIANT4(arm_or_u32, 11, in_bitwise1, in_bitwise2, ref_or, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_or_u32, 3, in_bitwise1, in_bitwise2, ref_or, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_or_u32, 8, in_bitwise1, in_bitwise2, ref_or, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_or_u32, 11, in_bitwise1, in_bitwise2, ref_or, 11); static void test_arm_not_u32( const uint32_t *input1, const uint32_t *ref, size_t length) @@ -367,9 +367,9 @@ static void test_arm_not_u32( free(output); } -DEFINE_TEST_VARIANT3(arm_not_u32, 3, in_bitwise1, ref_not, 3); -DEFINE_TEST_VARIANT3(arm_not_u32, 8, in_bitwise1, ref_not, 8); -DEFINE_TEST_VARIANT3(arm_not_u32, 11, in_bitwise1, ref_not, 11); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_not_u32, 3, in_bitwise1, ref_not, 3); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_not_u32, 8, in_bitwise1, ref_not, 8); +DEFINE_TEST_VARIANT3(basic_math_q31, arm_not_u32, 11, in_bitwise1, ref_not, 11); static void test_arm_xor_u32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) @@ -392,9 +392,9 @@ static void test_arm_xor_u32( free(output); } -DEFINE_TEST_VARIANT4(arm_xor_u32, 3, in_bitwise1, in_bitwise2, ref_xor, 3); -DEFINE_TEST_VARIANT4(arm_xor_u32, 8, in_bitwise1, in_bitwise2, ref_xor, 8); -DEFINE_TEST_VARIANT4(arm_xor_u32, 11, in_bitwise1, in_bitwise2, ref_xor, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_xor_u32, 3, in_bitwise1, in_bitwise2, ref_xor, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_xor_u32, 8, in_bitwise1, in_bitwise2, ref_xor, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, arm_xor_u32, 11, in_bitwise1, in_bitwise2, ref_xor, 11); static void test_arm_clip_q31( const q31_t *input, const q31_t *ref, q31_t min, q31_t max, size_t length) @@ -417,76 +417,9 @@ static void test_arm_clip_q31( free(output); } -DEFINE_TEST_VARIANT5(arm_clip_q31, c0000000_f3333333, in_clip, ref_clip1, +DEFINE_TEST_VARIANT5(basic_math_q31, arm_clip_q31, c0000000_f3333333, in_clip, ref_clip1, 0xc0000000, 0xf3333333, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(arm_clip_q31, c0000000_40000000, in_clip, ref_clip2, +DEFINE_TEST_VARIANT5(basic_math_q31, arm_clip_q31, c0000000_40000000, in_clip, ref_clip2, 0xc0000000, 0x40000000, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(arm_clip_q31, 0ccccccd_40000000, in_clip, ref_clip3, +DEFINE_TEST_VARIANT5(basic_math_q31, arm_clip_q31, 0ccccccd_40000000, in_clip, ref_clip3, 0x0ccccccd, 0x40000000, ARRAY_SIZE(ref_clip3)); - -void test_basicmath_q31(void) -{ - ztest_test_suite(basicmath_q31, - ztest_unit_test(test_arm_add_q31_3), - ztest_unit_test(test_arm_add_q31_8), - ztest_unit_test(test_arm_add_q31_11), - ztest_unit_test(test_arm_sub_q31_3), - ztest_unit_test(test_arm_sub_q31_8), - ztest_unit_test(test_arm_sub_q31_11), - ztest_unit_test(test_arm_mult_q31_3), - ztest_unit_test(test_arm_mult_q31_8), - ztest_unit_test(test_arm_mult_q31_11), - ztest_unit_test(test_arm_negate_q31_3), - ztest_unit_test(test_arm_negate_q31_8), - ztest_unit_test(test_arm_negate_q31_11), - ztest_unit_test(test_arm_offset_q31_0p5_3), - ztest_unit_test(test_arm_offset_q31_0p5_8), - ztest_unit_test(test_arm_offset_q31_0p5_11), - ztest_unit_test(test_arm_scale_q31_0p5_3), - ztest_unit_test(test_arm_scale_q31_0p5_8), - ztest_unit_test(test_arm_scale_q31_0p5_11), - ztest_unit_test(test_arm_dot_prod_q31_3), - ztest_unit_test(test_arm_dot_prod_q31_8), - ztest_unit_test(test_arm_dot_prod_q31_11), - ztest_unit_test(test_arm_abs_q31_3), - ztest_unit_test(test_arm_abs_q31_8), - ztest_unit_test(test_arm_abs_q31_11), - ztest_unit_test(test_arm_shift_q31_rand), - ztest_unit_test(test_arm_add_q31_possat), - ztest_unit_test(test_arm_add_q31_negsat), - ztest_unit_test(test_arm_sub_q31_possat), - ztest_unit_test(test_arm_sub_q31_negsat), - ztest_unit_test(test_arm_mult_q31_possat), - ztest_unit_test(test_arm_negate_q31_possat), - ztest_unit_test(test_arm_offset_q31_possat), - ztest_unit_test(test_arm_offset_q31_negsat), - ztest_unit_test(test_arm_scale_q31_possat), - ztest_unit_test(test_arm_shift_q31_possat), - ztest_unit_test(test_arm_shift_q31_negsat), - ztest_unit_test(test_arm_and_u32_3), - ztest_unit_test(test_arm_and_u32_8), - ztest_unit_test(test_arm_and_u32_11), - ztest_unit_test(test_arm_or_u32_3), - ztest_unit_test(test_arm_or_u32_8), - ztest_unit_test(test_arm_or_u32_11), - ztest_unit_test(test_arm_not_u32_3), - ztest_unit_test(test_arm_not_u32_8), - ztest_unit_test(test_arm_not_u32_11), - ztest_unit_test(test_arm_xor_u32_3), - ztest_unit_test(test_arm_xor_u32_8), - ztest_unit_test(test_arm_xor_u32_11), - ztest_unit_test(test_arm_add_q31_long), - ztest_unit_test(test_arm_sub_q31_long), - ztest_unit_test(test_arm_mult_q31_long), - ztest_unit_test(test_arm_negate_q31_long), - ztest_unit_test(test_arm_offset_q31_long), - ztest_unit_test(test_arm_scale_q31_long), - ztest_unit_test(test_arm_dot_prod_q31_long), - ztest_unit_test(test_arm_abs_q31_long), - ztest_unit_test(test_arm_clip_q31_c0000000_f3333333), - ztest_unit_test(test_arm_clip_q31_c0000000_40000000), - ztest_unit_test(test_arm_clip_q31_0ccccccd_40000000) - ); - - ztest_run_test_suite(basicmath_q31); -} diff --git a/tests/lib/cmsis_dsp/basicmath/src/q7.c b/tests/lib/cmsis_dsp/basicmath/src/q7.c index aadcdf11fb1f..839f47682f20 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/q7.c +++ b/tests/lib/cmsis_dsp/basicmath/src/q7.c @@ -42,12 +42,12 @@ static void test_arm_add_q7( free(output); } -DEFINE_TEST_VARIANT4(arm_add_q7, 15, in_com1, in_com2, ref_add, 15); -DEFINE_TEST_VARIANT4(arm_add_q7, 32, in_com1, in_com2, ref_add, 32); -DEFINE_TEST_VARIANT4(arm_add_q7, 47, in_com1, in_com2, ref_add, 47); -DEFINE_TEST_VARIANT4(arm_add_q7, possat, in_maxpos, in_maxpos, ref_add_possat, 33); -DEFINE_TEST_VARIANT4(arm_add_q7, negsat, in_maxneg, in_maxneg, ref_add_negsat, 33); -DEFINE_TEST_VARIANT4(arm_add_q7, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, 15, in_com1, in_com2, ref_add, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, 32, in_com1, in_com2, ref_add, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, 47, in_com1, in_com2, ref_add, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, possat, in_maxpos, in_maxpos, ref_add_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, negsat, in_maxneg, in_maxneg, ref_add_negsat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); static void test_arm_sub_q7( const q7_t *input1, const q7_t *input2, const q7_t *ref, size_t length) @@ -74,12 +74,12 @@ static void test_arm_sub_q7( free(output); } -DEFINE_TEST_VARIANT4(arm_sub_q7, 15, in_com1, in_com2, ref_sub, 15); -DEFINE_TEST_VARIANT4(arm_sub_q7, 32, in_com1, in_com2, ref_sub, 32); -DEFINE_TEST_VARIANT4(arm_sub_q7, 47, in_com1, in_com2, ref_sub, 47); -DEFINE_TEST_VARIANT4(arm_sub_q7, possat, in_maxpos, in_maxneg, ref_sub_possat, 33); -DEFINE_TEST_VARIANT4(arm_sub_q7, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 33); -DEFINE_TEST_VARIANT4(arm_sub_q7, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, 15, in_com1, in_com2, ref_sub, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, 32, in_com1, in_com2, ref_sub, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, 47, in_com1, in_com2, ref_sub, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, possat, in_maxpos, in_maxneg, ref_sub_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); static void test_arm_mult_q7( const q7_t *input1, const q7_t *input2, const q7_t *ref, size_t length) @@ -106,11 +106,11 @@ static void test_arm_mult_q7( free(output); } -DEFINE_TEST_VARIANT4(arm_mult_q7, 15, in_com1, in_com2, ref_mult, 15); -DEFINE_TEST_VARIANT4(arm_mult_q7, 32, in_com1, in_com2, ref_mult, 32); -DEFINE_TEST_VARIANT4(arm_mult_q7, 47, in_com1, in_com2, ref_mult, 47); -DEFINE_TEST_VARIANT4(arm_mult_q7, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 33); -DEFINE_TEST_VARIANT4(arm_mult_q7, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, 15, in_com1, in_com2, ref_mult, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, 32, in_com1, in_com2, ref_mult, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, 47, in_com1, in_com2, ref_mult, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); static void test_arm_negate_q7( const q7_t *input1, const q7_t *ref, size_t length) @@ -137,11 +137,11 @@ static void test_arm_negate_q7( free(output); } -DEFINE_TEST_VARIANT3(arm_negate_q7, 15, in_com1, ref_negate, 15); -DEFINE_TEST_VARIANT3(arm_negate_q7, 32, in_com1, ref_negate, 32); -DEFINE_TEST_VARIANT3(arm_negate_q7, 47, in_com1, ref_negate, 47); -DEFINE_TEST_VARIANT3(arm_negate_q7, possat, in_maxneg2, ref_negate_possat, 33); -DEFINE_TEST_VARIANT3(arm_negate_q7, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, 15, in_com1, ref_negate, 15); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, 32, in_com1, ref_negate, 32); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, 47, in_com1, ref_negate, 47); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, possat, in_maxneg2, ref_negate_possat, 33); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); static void test_arm_offset_q7( const q7_t *input1, q7_t scalar, const q7_t *ref, size_t length) @@ -168,12 +168,12 @@ static void test_arm_offset_q7( free(output); } -DEFINE_TEST_VARIANT4(arm_offset_q7, 0p5_15, in_com1, 0x40, ref_offset, 15); -DEFINE_TEST_VARIANT4(arm_offset_q7, 0p5_32, in_com1, 0x40, ref_offset, 32); -DEFINE_TEST_VARIANT4(arm_offset_q7, 0p5_47, in_com1, 0x40, ref_offset, 47); -DEFINE_TEST_VARIANT4(arm_offset_q7, possat, in_maxpos, 0x73, ref_offset_possat, 33); -DEFINE_TEST_VARIANT4(arm_offset_q7, negsat, in_maxneg, 0x8d, ref_offset_negsat, 33); -DEFINE_TEST_VARIANT4(arm_offset_q7, long, in_com1, 0x40, ref_offset, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, 0p5_15, in_com1, 0x40, ref_offset, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, 0p5_32, in_com1, 0x40, ref_offset, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, 0p5_47, in_com1, 0x40, ref_offset, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, possat, in_maxpos, 0x73, ref_offset_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, negsat, in_maxneg, 0x8d, ref_offset_negsat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, long, in_com1, 0x40, ref_offset, ARRAY_SIZE(in_com1)); static void test_arm_scale_q7( const q7_t *input1, q7_t scalar, const q7_t *ref, size_t length) @@ -200,11 +200,11 @@ static void test_arm_scale_q7( free(output); } -DEFINE_TEST_VARIANT4(arm_scale_q7, 0p5_15, in_com1, 0x40, ref_scale, 15); -DEFINE_TEST_VARIANT4(arm_scale_q7, 0p5_32, in_com1, 0x40, ref_scale, 32); -DEFINE_TEST_VARIANT4(arm_scale_q7, 0p5_47, in_com1, 0x40, ref_scale, 47); -DEFINE_TEST_VARIANT4(arm_scale_q7, possat, in_maxneg2, 0x80, ref_scale_possat, 33); -DEFINE_TEST_VARIANT4(arm_scale_q7, long, in_com1, 0x40, ref_scale, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, 0p5_15, in_com1, 0x40, ref_scale, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, 0p5_32, in_com1, 0x40, ref_scale, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, 0p5_47, in_com1, 0x40, ref_scale, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, possat, in_maxneg2, 0x80, ref_scale_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, long, in_com1, 0x40, ref_scale, ARRAY_SIZE(in_com1)); static void test_arm_dot_prod_q7( const q7_t *input1, const q7_t *input2, const q31_t *ref, @@ -232,10 +232,10 @@ static void test_arm_dot_prod_q7( free(output); } -DEFINE_TEST_VARIANT4(arm_dot_prod_q7, 15, in_com1, in_com2, ref_dot_prod_3, 15); -DEFINE_TEST_VARIANT4(arm_dot_prod_q7, 32, in_com1, in_com2, ref_dot_prod_4, 32); -DEFINE_TEST_VARIANT4(arm_dot_prod_q7, 47, in_com1, in_com2, ref_dot_prod_4n1, 47); -DEFINE_TEST_VARIANT4(arm_dot_prod_q7, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_q7, arm_dot_prod_q7, 15, in_com1, in_com2, ref_dot_prod_3, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_dot_prod_q7, 32, in_com1, in_com2, ref_dot_prod_4, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_dot_prod_q7, 47, in_com1, in_com2, ref_dot_prod_4n1, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_dot_prod_q7, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); static void test_arm_abs_q7( @@ -263,10 +263,10 @@ static void test_arm_abs_q7( free(output); } -DEFINE_TEST_VARIANT3(arm_abs_q7, 15, in_com1, ref_abs, 15); -DEFINE_TEST_VARIANT3(arm_abs_q7, 32, in_com1, ref_abs, 32); -DEFINE_TEST_VARIANT3(arm_abs_q7, 47, in_com1, ref_abs, 47); -DEFINE_TEST_VARIANT3(arm_abs_q7, long, in_com1, ref_abs, ARRAY_SIZE(ref_abs)); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_abs_q7, 15, in_com1, ref_abs, 15); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_abs_q7, 32, in_com1, ref_abs, 32); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_abs_q7, 47, in_com1, ref_abs, 47); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_abs_q7, long, in_com1, ref_abs, ARRAY_SIZE(ref_abs)); static void test_arm_shift_q7( const q7_t *input1, const q7_t *ref, size_t length) @@ -293,9 +293,9 @@ static void test_arm_shift_q7( free(output); } -DEFINE_TEST_VARIANT3(arm_shift_q7, rand, in_rand, ref_shift, 33); -DEFINE_TEST_VARIANT3(arm_shift_q7, possat, in_maxpos, ref_shift_possat, 33); -DEFINE_TEST_VARIANT3(arm_shift_q7, negsat, in_maxneg, ref_shift_negsat, 33); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_shift_q7, rand, in_rand, ref_shift, 33); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_shift_q7, possat, in_maxpos, ref_shift_possat, 33); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_shift_q7, negsat, in_maxneg, ref_shift_negsat, 33); static void test_arm_and_u8( const uint8_t *input1, const uint8_t *input2, const uint8_t *ref, size_t length) @@ -318,9 +318,9 @@ static void test_arm_and_u8( free(output); } -DEFINE_TEST_VARIANT4(arm_and_u8, 15, in_bitwise1, in_bitwise2, ref_and, 15); -DEFINE_TEST_VARIANT4(arm_and_u8, 32, in_bitwise1, in_bitwise2, ref_and, 32); -DEFINE_TEST_VARIANT4(arm_and_u8, 47, in_bitwise1, in_bitwise2, ref_and, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_and_u8, 15, in_bitwise1, in_bitwise2, ref_and, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_and_u8, 32, in_bitwise1, in_bitwise2, ref_and, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_and_u8, 47, in_bitwise1, in_bitwise2, ref_and, 47); static void test_arm_or_u8( const uint8_t *input1, const uint8_t *input2, const uint8_t *ref, size_t length) @@ -343,9 +343,9 @@ static void test_arm_or_u8( free(output); } -DEFINE_TEST_VARIANT4(arm_or_u8, 15, in_bitwise1, in_bitwise2, ref_or, 15); -DEFINE_TEST_VARIANT4(arm_or_u8, 32, in_bitwise1, in_bitwise2, ref_or, 32); -DEFINE_TEST_VARIANT4(arm_or_u8, 47, in_bitwise1, in_bitwise2, ref_or, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_or_u8, 15, in_bitwise1, in_bitwise2, ref_or, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_or_u8, 32, in_bitwise1, in_bitwise2, ref_or, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_or_u8, 47, in_bitwise1, in_bitwise2, ref_or, 47); static void test_arm_not_u8( const uint8_t *input1, const uint8_t *ref, size_t length) @@ -368,9 +368,9 @@ static void test_arm_not_u8( free(output); } -DEFINE_TEST_VARIANT3(arm_not_u8, 15, in_bitwise1, ref_not, 15); -DEFINE_TEST_VARIANT3(arm_not_u8, 32, in_bitwise1, ref_not, 32); -DEFINE_TEST_VARIANT3(arm_not_u8, 47, in_bitwise1, ref_not, 47); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_not_u8, 15, in_bitwise1, ref_not, 15); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_not_u8, 32, in_bitwise1, ref_not, 32); +DEFINE_TEST_VARIANT3(basic_math_q7, arm_not_u8, 47, in_bitwise1, ref_not, 47); static void test_arm_xor_u8( const uint8_t *input1, const uint8_t *input2, const uint8_t *ref, size_t length) @@ -393,9 +393,9 @@ static void test_arm_xor_u8( free(output); } -DEFINE_TEST_VARIANT4(arm_xor_u8, 15, in_bitwise1, in_bitwise2, ref_xor, 15); -DEFINE_TEST_VARIANT4(arm_xor_u8, 32, in_bitwise1, in_bitwise2, ref_xor, 32); -DEFINE_TEST_VARIANT4(arm_xor_u8, 47, in_bitwise1, in_bitwise2, ref_xor, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_xor_u8, 15, in_bitwise1, in_bitwise2, ref_xor, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_xor_u8, 32, in_bitwise1, in_bitwise2, ref_xor, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, arm_xor_u8, 47, in_bitwise1, in_bitwise2, ref_xor, 47); static void test_arm_clip_q7( const q7_t *input, const q7_t *ref, q7_t min, q7_t max, size_t length) @@ -418,73 +418,6 @@ static void test_arm_clip_q7( free(output); } -DEFINE_TEST_VARIANT5(arm_clip_q7, c0_f3, in_clip, ref_clip1, 0xc0, 0xf3, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(arm_clip_q7, c0_40, in_clip, ref_clip2, 0xc0, 0x40, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(arm_clip_q7, 0d_40, in_clip, ref_clip3, 0x0d, 0x40, ARRAY_SIZE(ref_clip3)); - -void test_basicmath_q7(void) -{ - ztest_test_suite(basicmath_q7, - ztest_unit_test(test_arm_add_q7_15), - ztest_unit_test(test_arm_add_q7_32), - ztest_unit_test(test_arm_add_q7_47), - ztest_unit_test(test_arm_sub_q7_15), - ztest_unit_test(test_arm_sub_q7_32), - ztest_unit_test(test_arm_sub_q7_47), - ztest_unit_test(test_arm_mult_q7_15), - ztest_unit_test(test_arm_mult_q7_32), - ztest_unit_test(test_arm_mult_q7_47), - ztest_unit_test(test_arm_negate_q7_15), - ztest_unit_test(test_arm_negate_q7_32), - ztest_unit_test(test_arm_negate_q7_47), - ztest_unit_test(test_arm_offset_q7_0p5_15), - ztest_unit_test(test_arm_offset_q7_0p5_32), - ztest_unit_test(test_arm_offset_q7_0p5_47), - ztest_unit_test(test_arm_scale_q7_0p5_15), - ztest_unit_test(test_arm_scale_q7_0p5_32), - ztest_unit_test(test_arm_scale_q7_0p5_47), - ztest_unit_test(test_arm_dot_prod_q7_15), - ztest_unit_test(test_arm_dot_prod_q7_32), - ztest_unit_test(test_arm_dot_prod_q7_47), - ztest_unit_test(test_arm_abs_q7_15), - ztest_unit_test(test_arm_abs_q7_32), - ztest_unit_test(test_arm_abs_q7_47), - ztest_unit_test(test_arm_shift_q7_rand), - ztest_unit_test(test_arm_add_q7_possat), - ztest_unit_test(test_arm_add_q7_negsat), - ztest_unit_test(test_arm_sub_q7_possat), - ztest_unit_test(test_arm_sub_q7_negsat), - ztest_unit_test(test_arm_mult_q7_possat), - ztest_unit_test(test_arm_negate_q7_possat), - ztest_unit_test(test_arm_offset_q7_possat), - ztest_unit_test(test_arm_offset_q7_negsat), - ztest_unit_test(test_arm_scale_q7_possat), - ztest_unit_test(test_arm_shift_q7_possat), - ztest_unit_test(test_arm_shift_q7_negsat), - ztest_unit_test(test_arm_and_u8_15), - ztest_unit_test(test_arm_and_u8_32), - ztest_unit_test(test_arm_and_u8_47), - ztest_unit_test(test_arm_or_u8_15), - ztest_unit_test(test_arm_or_u8_32), - ztest_unit_test(test_arm_or_u8_47), - ztest_unit_test(test_arm_not_u8_15), - ztest_unit_test(test_arm_not_u8_32), - ztest_unit_test(test_arm_not_u8_47), - ztest_unit_test(test_arm_xor_u8_15), - ztest_unit_test(test_arm_xor_u8_32), - ztest_unit_test(test_arm_xor_u8_47), - ztest_unit_test(test_arm_add_q7_long), - ztest_unit_test(test_arm_sub_q7_long), - ztest_unit_test(test_arm_mult_q7_long), - ztest_unit_test(test_arm_negate_q7_long), - ztest_unit_test(test_arm_offset_q7_long), - ztest_unit_test(test_arm_scale_q7_long), - ztest_unit_test(test_arm_dot_prod_q7_long), - ztest_unit_test(test_arm_abs_q7_long), - ztest_unit_test(test_arm_clip_q7_c0_f3), - ztest_unit_test(test_arm_clip_q7_c0_40), - ztest_unit_test(test_arm_clip_q7_0d_40) - ); - - ztest_run_test_suite(basicmath_q7); -} +DEFINE_TEST_VARIANT5(basic_math_q7, arm_clip_q7, c0_f3, in_clip, ref_clip1, 0xc0, 0xf3, ARRAY_SIZE(ref_clip1)); +DEFINE_TEST_VARIANT5(basic_math_q7, arm_clip_q7, c0_40, in_clip, ref_clip2, 0xc0, 0x40, ARRAY_SIZE(ref_clip2)); +DEFINE_TEST_VARIANT5(basic_math_q7, arm_clip_q7, 0d_40, in_clip, ref_clip3, 0x0d, 0x40, ARRAY_SIZE(ref_clip3)); diff --git a/tests/lib/cmsis_dsp/bayes/CMakeLists.txt b/tests/lib/cmsis_dsp/bayes/CMakeLists.txt index 8c2947f2dd56..755c261be9e7 100644 --- a/tests/lib/cmsis_dsp/bayes/CMakeLists.txt +++ b/tests/lib/cmsis_dsp/bayes/CMakeLists.txt @@ -6,7 +6,6 @@ project(cmsis_dsp_bayes) target_sources(app PRIVATE src/f32.c - src/main.c ) target_sources_ifdef(CONFIG_CMSIS_DSP_FLOAT16 app PRIVATE src/f16.c) diff --git a/tests/lib/cmsis_dsp/bayes/src/f16.c b/tests/lib/cmsis_dsp/bayes/src/f16.c index f081a43dbb75..1534b6626a52 100644 --- a/tests/lib/cmsis_dsp/bayes/src/f16.c +++ b/tests/lib/cmsis_dsp/bayes/src/f16.c @@ -15,7 +15,11 @@ #define REL_ERROR_THRESH (3.0e-3) -void test_gaussian_naive_bayes_predict_f16(void) +/* Note: this source file is only built when CONFIG_CMSIS_DSP_FLOAT16 is enabled */ + +ZTEST_SUITE(bayes_f16, NULL, NULL, NULL, NULL, NULL); + +ZTEST(bayes_f16, test_gaussian_naive_bayes_predict_f16) { arm_gaussian_naive_bayes_instance_f16 inst; @@ -80,12 +84,3 @@ void test_gaussian_naive_bayes_predict_f16(void) free(output_probs_buf); free(output_preds_buf); } - -void test_bayes_f16(void) -{ - ztest_test_suite(bayes_f16, - ztest_unit_test(test_gaussian_naive_bayes_predict_f16) - ); - - ztest_run_test_suite(bayes_f16); -} diff --git a/tests/lib/cmsis_dsp/bayes/src/f32.c b/tests/lib/cmsis_dsp/bayes/src/f32.c index 57a3703267fc..9226d4523f9d 100644 --- a/tests/lib/cmsis_dsp/bayes/src/f32.c +++ b/tests/lib/cmsis_dsp/bayes/src/f32.c @@ -15,7 +15,9 @@ #define REL_ERROR_THRESH (5.0e-6) -void test_gaussian_naive_bayes_predict_f32(void) +ZTEST_SUITE(bayes_f32, NULL, NULL, NULL, NULL, NULL); + +ZTEST(bayes_f32, test_gaussian_naive_bayes_predict_f16) { arm_gaussian_naive_bayes_instance_f32 inst; @@ -80,12 +82,3 @@ void test_gaussian_naive_bayes_predict_f32(void) free(output_probs_buf); free(output_preds_buf); } - -void test_bayes_f32(void) -{ - ztest_test_suite(bayes_f32, - ztest_unit_test(test_gaussian_naive_bayes_predict_f32) - ); - - ztest_run_test_suite(bayes_f32); -} diff --git a/tests/lib/cmsis_dsp/bayes/src/main.c b/tests/lib/cmsis_dsp/bayes/src/main.c deleted file mode 100644 index 1427ee201f46..000000000000 --- a/tests/lib/cmsis_dsp/bayes/src/main.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2021 Stephanos Ioannidis - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -extern void test_bayes_f16(void); -extern void test_bayes_f32(void); - -void test_main(void) -{ -#ifdef CONFIG_CMSIS_DSP_FLOAT16 - test_bayes_f16(); -#endif - test_bayes_f32(); -} diff --git a/tests/lib/cmsis_dsp/common/test_common.h b/tests/lib/cmsis_dsp/common/test_common.h index b5649f8ad5d1..8296f247f3f6 100644 --- a/tests/lib/cmsis_dsp/common/test_common.h +++ b/tests/lib/cmsis_dsp/common/test_common.h @@ -26,46 +26,46 @@ #define ASSERT_MSG_ERROR_LIMIT_EXCEED "error limit exceeded" #define ASSERT_MSG_INCORRECT_COMP_RESULT "incorrect computation result" -#define DEFINE_TEST_VARIANT1(name, variant, a1) \ - static void test_##name##_##variant(void) \ - { \ - test_##name(a1); \ +#define DEFINE_TEST_VARIANT1(suite, name, variant, a1) \ + ZTEST(suite, test_##name##_##variant) \ + { \ + test_##name(a1); \ } -#define DEFINE_TEST_VARIANT2(name, variant, a1, a2) \ - static void test_##name##_##variant(void) \ - { \ - test_##name(a1, a2); \ +#define DEFINE_TEST_VARIANT2(suite, name, variant, a1, a2) \ + ZTEST(suite, test_##name##_##variant) \ + { \ + test_##name(a1, a2); \ } -#define DEFINE_TEST_VARIANT3(name, variant, a1, a2, a3) \ - static void test_##name##_##variant(void) \ - { \ - test_##name(a1, a2, a3); \ +#define DEFINE_TEST_VARIANT3(suite, name, variant, a1, a2, a3) \ + ZTEST(suite, test_##name##_##variant) \ + { \ + test_##name(a1, a2, a3); \ } -#define DEFINE_TEST_VARIANT4(name, variant, a1, a2, a3, a4) \ - static void test_##name##_##variant(void) \ - { \ - test_##name(a1, a2, a3, a4); \ +#define DEFINE_TEST_VARIANT4(suite, name, variant, a1, a2, a3, a4) \ + ZTEST(suite, test_##name##_##variant) \ + { \ + test_##name(a1, a2, a3, a4); \ } -#define DEFINE_TEST_VARIANT5(name, variant, a1, a2, a3, a4, a5) \ - static void test_##name##_##variant(void) \ - { \ - test_##name(a1, a2, a3, a4, a5); \ +#define DEFINE_TEST_VARIANT5(suite, name, variant, a1, a2, a3, a4, a5) \ + ZTEST(suite, test_##name##_##variant) \ + { \ + test_##name(a1, a2, a3, a4, a5); \ } -#define DEFINE_TEST_VARIANT6(name, variant, a1, a2, a3, a4, a5, a6) \ - static void test_##name##_##variant(void) \ - { \ - test_##name(a1, a2, a3, a4, a5, a6); \ +#define DEFINE_TEST_VARIANT6(suite, name, variant, a1, a2, a3, a4, a5, a6) \ + ZTEST(suite, test_##name##_##variant) \ + { \ + test_##name(a1, a2, a3, a4, a5, a6); \ } -#define DEFINE_TEST_VARIANT7(name, variant, a1, a2, a3, a4, a5, a6, a7) \ - static void test_##name##_##variant(void) \ - { \ - test_##name(a1, a2, a3, a4, a5, a6, a7); \ +#define DEFINE_TEST_VARIANT7(suite, name, variant, a1, a2, a3, a4, a5, a6, a7) \ + ZTEST(suite, test_##name##_##variant) \ + { \ + test_##name(a1, a2, a3, a4, a5, a6, a7); \ } #pragma GCC diagnostic push diff --git a/tests/lib/cmsis_dsp/complexmath/CMakeLists.txt b/tests/lib/cmsis_dsp/complexmath/CMakeLists.txt index 4c1d32712cf4..1773e082c388 100644 --- a/tests/lib/cmsis_dsp/complexmath/CMakeLists.txt +++ b/tests/lib/cmsis_dsp/complexmath/CMakeLists.txt @@ -8,7 +8,6 @@ target_sources(app PRIVATE src/q15.c src/q31.c src/f32.c - src/main.c ) target_sources_ifdef(CONFIG_CMSIS_DSP_FLOAT16 app PRIVATE src/f16.c) diff --git a/tests/lib/cmsis_dsp/complexmath/src/f16.c b/tests/lib/cmsis_dsp/complexmath/src/f16.c index 0ca582278c28..3af613c8c0a3 100644 --- a/tests/lib/cmsis_dsp/complexmath/src/f16.c +++ b/tests/lib/cmsis_dsp/complexmath/src/f16.c @@ -16,6 +16,8 @@ #define SNR_ERROR_THRESH ((float32_t)39) #define REL_ERROR_THRESH (6.0e-2) +ZTEST_SUITE(complexmath_f16, NULL, NULL, NULL, NULL, NULL); + static void test_arm_cmplx_conj_f16( const uint16_t *input1, const uint16_t *ref, size_t length) { @@ -47,9 +49,9 @@ static void test_arm_cmplx_conj_f16( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_conj_f16, 7, in_com1, ref_conj, 7); -DEFINE_TEST_VARIANT3(arm_cmplx_conj_f16, 16, in_com1, ref_conj, 16); -DEFINE_TEST_VARIANT3(arm_cmplx_conj_f16, 23, in_com1, ref_conj, 23); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_conj_f16, 7, in_com1, ref_conj, 7); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_conj_f16, 16, in_com1, ref_conj, 16); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_conj_f16, 23, in_com1, ref_conj, 23); static void test_arm_cmplx_dot_prod_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -81,9 +83,9 @@ static void test_arm_cmplx_dot_prod_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_f16, 7, in_com1, in_com2, ref_dot_prod_3, 7); -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_f16, 16, in_com1, in_com2, ref_dot_prod_4n, 16); -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_f16, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_dot_prod_f16, 7, in_com1, in_com2, ref_dot_prod_3, 7); +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_dot_prod_f16, 16, in_com1, in_com2, ref_dot_prod_4n, 16); +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_dot_prod_f16, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); static void test_arm_cmplx_mag_f16( const uint16_t *input1, const uint16_t *ref, size_t length) @@ -112,9 +114,9 @@ static void test_arm_cmplx_mag_f16( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_mag_f16, 7, in_com1, ref_mag, 7); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_f16, 16, in_com1, ref_mag, 16); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_f16, 23, in_com1, ref_mag, 23); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_mag_f16, 7, in_com1, ref_mag, 7); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_mag_f16, 16, in_com1, ref_mag, 16); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_mag_f16, 23, in_com1, ref_mag, 23); static void test_arm_cmplx_mag_squared_f16( const uint16_t *input1, const uint16_t *ref, size_t length) @@ -143,9 +145,9 @@ static void test_arm_cmplx_mag_squared_f16( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_f16, 7, in_com1, ref_mag_squared, 7); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_f16, 16, in_com1, ref_mag_squared, 16); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_f16, 23, in_com1, ref_mag_squared, 23); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_mag_squared_f16, 7, in_com1, ref_mag_squared, 7); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_mag_squared_f16, 16, in_com1, ref_mag_squared, 16); +DEFINE_TEST_VARIANT3(complexmath_f16, arm_cmplx_mag_squared_f16, 23, in_com1, ref_mag_squared, 23); static void test_arm_cmplx_mult_cmplx_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -180,9 +182,9 @@ static void test_arm_cmplx_mult_cmplx_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_f16, 7, in_com1, in_com2, ref_mult_cmplx, 7); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_f16, 16, in_com1, in_com2, ref_mult_cmplx, 16); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_f16, 23, in_com1, in_com2, ref_mult_cmplx, 23); +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_mult_cmplx_f16, 7, in_com1, in_com2, ref_mult_cmplx, 7); +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_mult_cmplx_f16, 16, in_com1, in_com2, ref_mult_cmplx, 16); +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_mult_cmplx_f16, 23, in_com1, in_com2, ref_mult_cmplx, 23); static void test_arm_cmplx_mult_real_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, @@ -219,32 +221,6 @@ static void test_arm_cmplx_mult_real_f16( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_f16, 7, in_com1, in_com3, ref_mult_real, 7); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_f16, 16, in_com1, in_com3, ref_mult_real, 16); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_f16, 23, in_com1, in_com3, ref_mult_real, 23); - -void test_complexmath_f16(void) -{ - ztest_test_suite(complexmath_f16, - ztest_unit_test(test_arm_cmplx_conj_f16_7), - ztest_unit_test(test_arm_cmplx_conj_f16_16), - ztest_unit_test(test_arm_cmplx_conj_f16_23), - ztest_unit_test(test_arm_cmplx_dot_prod_f16_7), - ztest_unit_test(test_arm_cmplx_dot_prod_f16_16), - ztest_unit_test(test_arm_cmplx_dot_prod_f16_23), - ztest_unit_test(test_arm_cmplx_mag_f16_7), - ztest_unit_test(test_arm_cmplx_mag_f16_16), - ztest_unit_test(test_arm_cmplx_mag_f16_23), - ztest_unit_test(test_arm_cmplx_mag_squared_f16_7), - ztest_unit_test(test_arm_cmplx_mag_squared_f16_16), - ztest_unit_test(test_arm_cmplx_mag_squared_f16_23), - ztest_unit_test(test_arm_cmplx_mult_cmplx_f16_7), - ztest_unit_test(test_arm_cmplx_mult_cmplx_f16_16), - ztest_unit_test(test_arm_cmplx_mult_cmplx_f16_23), - ztest_unit_test(test_arm_cmplx_mult_real_f16_7), - ztest_unit_test(test_arm_cmplx_mult_real_f16_16), - ztest_unit_test(test_arm_cmplx_mult_real_f16_23) - ); - - ztest_run_test_suite(complexmath_f16); -} +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_mult_real_f16, 7, in_com1, in_com3, ref_mult_real, 7); +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_mult_real_f16, 16, in_com1, in_com3, ref_mult_real, 16); +DEFINE_TEST_VARIANT4(complexmath_f16, arm_cmplx_mult_real_f16, 23, in_com1, in_com3, ref_mult_real, 23); diff --git a/tests/lib/cmsis_dsp/complexmath/src/f32.c b/tests/lib/cmsis_dsp/complexmath/src/f32.c index a2d4b2b4e38b..0f841cd7d5d9 100644 --- a/tests/lib/cmsis_dsp/complexmath/src/f32.c +++ b/tests/lib/cmsis_dsp/complexmath/src/f32.c @@ -16,6 +16,8 @@ #define SNR_ERROR_THRESH ((float32_t)120) #define REL_ERROR_THRESH (7.0e-6) +ZTEST_SUITE(complexmath_f32, NULL, NULL, NULL, NULL, NULL); + static void test_arm_cmplx_conj_f32( const uint32_t *input1, const uint32_t *ref, size_t length) { @@ -47,9 +49,9 @@ static void test_arm_cmplx_conj_f32( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_conj_f32, 3, in_com1, ref_conj, 3); -DEFINE_TEST_VARIANT3(arm_cmplx_conj_f32, 8, in_com1, ref_conj, 8); -DEFINE_TEST_VARIANT3(arm_cmplx_conj_f32, 11, in_com1, ref_conj, 11); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_conj_f32, 3, in_com1, ref_conj, 3); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_conj_f32, 8, in_com1, ref_conj, 8); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_conj_f32, 11, in_com1, ref_conj, 11); static void test_arm_cmplx_dot_prod_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, @@ -81,9 +83,9 @@ static void test_arm_cmplx_dot_prod_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_f32, 3, in_com1, in_com2, ref_dot_prod_3, 3); -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_f32, 8, in_com1, in_com2, ref_dot_prod_4n, 8); -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_f32, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_dot_prod_f32, 3, in_com1, in_com2, ref_dot_prod_3, 3); +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_dot_prod_f32, 8, in_com1, in_com2, ref_dot_prod_4n, 8); +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_dot_prod_f32, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); static void test_arm_cmplx_mag_f32( const uint32_t *input1, const uint32_t *ref, size_t length) @@ -112,9 +114,9 @@ static void test_arm_cmplx_mag_f32( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_mag_f32, 3, in_com1, ref_mag, 3); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_f32, 8, in_com1, ref_mag, 8); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_f32, 11, in_com1, ref_mag, 11); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_mag_f32, 3, in_com1, ref_mag, 3); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_mag_f32, 8, in_com1, ref_mag, 8); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_mag_f32, 11, in_com1, ref_mag, 11); static void test_arm_cmplx_mag_squared_f32( const uint32_t *input1, const uint32_t *ref, size_t length) @@ -143,9 +145,9 @@ static void test_arm_cmplx_mag_squared_f32( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_f32, 3, in_com1, ref_mag_squared, 3); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_f32, 8, in_com1, ref_mag_squared, 8); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_f32, 11, in_com1, ref_mag_squared, 11); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_mag_squared_f32, 3, in_com1, ref_mag_squared, 3); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_mag_squared_f32, 8, in_com1, ref_mag_squared, 8); +DEFINE_TEST_VARIANT3(complexmath_f32, arm_cmplx_mag_squared_f32, 11, in_com1, ref_mag_squared, 11); static void test_arm_cmplx_mult_cmplx_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, @@ -180,9 +182,9 @@ static void test_arm_cmplx_mult_cmplx_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_f32, 3, in_com1, in_com2, ref_mult_cmplx, 3); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_f32, 8, in_com1, in_com2, ref_mult_cmplx, 8); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_f32, 11, in_com1, in_com2, ref_mult_cmplx, 11); +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_mult_cmplx_f32, 3, in_com1, in_com2, ref_mult_cmplx, 3); +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_mult_cmplx_f32, 8, in_com1, in_com2, ref_mult_cmplx, 8); +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_mult_cmplx_f32, 11, in_com1, in_com2, ref_mult_cmplx, 11); static void test_arm_cmplx_mult_real_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, @@ -219,32 +221,6 @@ static void test_arm_cmplx_mult_real_f32( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_f32, 3, in_com1, in_com3, ref_mult_real, 3); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_f32, 8, in_com1, in_com3, ref_mult_real, 8); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_f32, 11, in_com1, in_com3, ref_mult_real, 11); - -void test_complexmath_f32(void) -{ - ztest_test_suite(complexmath_f32, - ztest_unit_test(test_arm_cmplx_conj_f32_3), - ztest_unit_test(test_arm_cmplx_conj_f32_8), - ztest_unit_test(test_arm_cmplx_conj_f32_11), - ztest_unit_test(test_arm_cmplx_dot_prod_f32_3), - ztest_unit_test(test_arm_cmplx_dot_prod_f32_8), - ztest_unit_test(test_arm_cmplx_dot_prod_f32_11), - ztest_unit_test(test_arm_cmplx_mag_f32_3), - ztest_unit_test(test_arm_cmplx_mag_f32_8), - ztest_unit_test(test_arm_cmplx_mag_f32_11), - ztest_unit_test(test_arm_cmplx_mag_squared_f32_3), - ztest_unit_test(test_arm_cmplx_mag_squared_f32_8), - ztest_unit_test(test_arm_cmplx_mag_squared_f32_11), - ztest_unit_test(test_arm_cmplx_mult_cmplx_f32_3), - ztest_unit_test(test_arm_cmplx_mult_cmplx_f32_8), - ztest_unit_test(test_arm_cmplx_mult_cmplx_f32_11), - ztest_unit_test(test_arm_cmplx_mult_real_f32_3), - ztest_unit_test(test_arm_cmplx_mult_real_f32_8), - ztest_unit_test(test_arm_cmplx_mult_real_f32_11) - ); - - ztest_run_test_suite(complexmath_f32); -} +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_mult_real_f32, 3, in_com1, in_com3, ref_mult_real, 3); +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_mult_real_f32, 8, in_com1, in_com3, ref_mult_real, 8); +DEFINE_TEST_VARIANT4(complexmath_f32, arm_cmplx_mult_real_f32, 11, in_com1, in_com3, ref_mult_real, 11); diff --git a/tests/lib/cmsis_dsp/complexmath/src/main.c b/tests/lib/cmsis_dsp/complexmath/src/main.c deleted file mode 100644 index 19ac5505c843..000000000000 --- a/tests/lib/cmsis_dsp/complexmath/src/main.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2021 Stephanos Ioannidis - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -extern void test_complexmath_q15(void); -extern void test_complexmath_q31(void); -extern void test_complexmath_f16(void); -extern void test_complexmath_f32(void); - -void test_main(void) -{ - test_complexmath_q15(); - test_complexmath_q31(); -#ifdef CONFIG_CMSIS_DSP_FLOAT16 - test_complexmath_f16(); -#endif - test_complexmath_f32(); -} diff --git a/tests/lib/cmsis_dsp/complexmath/src/q15.c b/tests/lib/cmsis_dsp/complexmath/src/q15.c index 61a8f4339229..22745c22a16d 100644 --- a/tests/lib/cmsis_dsp/complexmath/src/q15.c +++ b/tests/lib/cmsis_dsp/complexmath/src/q15.c @@ -18,6 +18,8 @@ #define ABS_ERROR_THRESH_Q15 ((q15_t)50) #define ABS_ERROR_THRESH_Q31 ((q31_t)(1 << 15)) +ZTEST_SUITE(complexmath_q15, NULL, NULL, NULL, NULL, NULL); + static void test_arm_cmplx_conj_q15( const q15_t *input1, const q15_t *ref, size_t length) { @@ -48,9 +50,9 @@ static void test_arm_cmplx_conj_q15( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_conj_q15, 7, in_com1, ref_conj, 7); -DEFINE_TEST_VARIANT3(arm_cmplx_conj_q15, 16, in_com1, ref_conj, 16); -DEFINE_TEST_VARIANT3(arm_cmplx_conj_q15, 23, in_com1, ref_conj, 23); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_conj_q15, 7, in_com1, ref_conj, 7); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_conj_q15, 16, in_com1, ref_conj, 16); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_conj_q15, 23, in_com1, ref_conj, 23); static void test_arm_cmplx_dot_prod_q15( const q15_t *input1, const q15_t *input2, const q31_t *ref, @@ -78,9 +80,9 @@ static void test_arm_cmplx_dot_prod_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_q15, 7, in_com1, in_com2, ref_dot_prod_3, 7); -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_q15, 16, in_com1, in_com2, ref_dot_prod_4n, 16); -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_q15, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_dot_prod_q15, 7, in_com1, in_com2, ref_dot_prod_3, 7); +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_dot_prod_q15, 16, in_com1, in_com2, ref_dot_prod_4n, 16); +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_dot_prod_q15, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); static void test_arm_cmplx_mag_q15( const q15_t *input1, const q15_t *ref, size_t length) @@ -107,9 +109,9 @@ static void test_arm_cmplx_mag_q15( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_mag_q15, 7, in_com1, ref_mag, 7); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_q15, 16, in_com1, ref_mag, 16); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_q15, 23, in_com1, ref_mag, 23); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_mag_q15, 7, in_com1, ref_mag, 7); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_mag_q15, 16, in_com1, ref_mag, 16); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_mag_q15, 23, in_com1, ref_mag, 23); static void test_arm_cmplx_mag_squared_q15( const q15_t *input1, const q15_t *ref, size_t length) @@ -136,9 +138,9 @@ static void test_arm_cmplx_mag_squared_q15( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_q15, 7, in_com1, ref_mag_squared, 7); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_q15, 16, in_com1, ref_mag_squared, 16); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_q15, 23, in_com1, ref_mag_squared, 23); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_mag_squared_q15, 7, in_com1, ref_mag_squared, 7); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_mag_squared_q15, 16, in_com1, ref_mag_squared, 16); +DEFINE_TEST_VARIANT3(complexmath_q15, arm_cmplx_mag_squared_q15, 23, in_com1, ref_mag_squared, 23); static void test_arm_cmplx_mult_cmplx_q15( const q15_t *input1, const q15_t *input2, const q15_t *ref, @@ -171,9 +173,9 @@ static void test_arm_cmplx_mult_cmplx_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_q15, 7, in_com1, in_com2, ref_mult_cmplx, 7); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_q15, 16, in_com1, in_com2, ref_mult_cmplx, 16); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_q15, 23, in_com1, in_com2, ref_mult_cmplx, 23); +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_mult_cmplx_q15, 7, in_com1, in_com2, ref_mult_cmplx, 7); +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_mult_cmplx_q15, 16, in_com1, in_com2, ref_mult_cmplx, 16); +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_mult_cmplx_q15, 23, in_com1, in_com2, ref_mult_cmplx, 23); static void test_arm_cmplx_mult_real_q15( const q15_t *input1, const q15_t *input2, const q15_t *ref, @@ -206,32 +208,6 @@ static void test_arm_cmplx_mult_real_q15( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_q15, 7, in_com1, in_com3, ref_mult_real, 7); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_q15, 16, in_com1, in_com3, ref_mult_real, 16); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_q15, 23, in_com1, in_com3, ref_mult_real, 23); - -void test_complexmath_q15(void) -{ - ztest_test_suite(complexmath_q15, - ztest_unit_test(test_arm_cmplx_conj_q15_7), - ztest_unit_test(test_arm_cmplx_conj_q15_16), - ztest_unit_test(test_arm_cmplx_conj_q15_23), - ztest_unit_test(test_arm_cmplx_dot_prod_q15_7), - ztest_unit_test(test_arm_cmplx_dot_prod_q15_16), - ztest_unit_test(test_arm_cmplx_dot_prod_q15_23), - ztest_unit_test(test_arm_cmplx_mag_q15_7), - ztest_unit_test(test_arm_cmplx_mag_q15_16), - ztest_unit_test(test_arm_cmplx_mag_q15_23), - ztest_unit_test(test_arm_cmplx_mag_squared_q15_7), - ztest_unit_test(test_arm_cmplx_mag_squared_q15_16), - ztest_unit_test(test_arm_cmplx_mag_squared_q15_23), - ztest_unit_test(test_arm_cmplx_mult_cmplx_q15_7), - ztest_unit_test(test_arm_cmplx_mult_cmplx_q15_16), - ztest_unit_test(test_arm_cmplx_mult_cmplx_q15_23), - ztest_unit_test(test_arm_cmplx_mult_real_q15_7), - ztest_unit_test(test_arm_cmplx_mult_real_q15_16), - ztest_unit_test(test_arm_cmplx_mult_real_q15_23) - ); - - ztest_run_test_suite(complexmath_q15); -} +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_mult_real_q15, 7, in_com1, in_com3, ref_mult_real, 7); +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_mult_real_q15, 16, in_com1, in_com3, ref_mult_real, 16); +DEFINE_TEST_VARIANT4(complexmath_q15, arm_cmplx_mult_real_q15, 23, in_com1, in_com3, ref_mult_real, 23); diff --git a/tests/lib/cmsis_dsp/complexmath/src/q31.c b/tests/lib/cmsis_dsp/complexmath/src/q31.c index 8a0ed8b5e8eb..9af504dbf6bf 100644 --- a/tests/lib/cmsis_dsp/complexmath/src/q31.c +++ b/tests/lib/cmsis_dsp/complexmath/src/q31.c @@ -17,6 +17,8 @@ #define ABS_ERROR_THRESH_Q31 ((q31_t)100) #define ABS_ERROR_THRESH_Q63 ((q63_t)(1 << 18)) +ZTEST_SUITE(complexmath_q31, NULL, NULL, NULL, NULL, NULL); + static void test_arm_cmplx_conj_q31( const q31_t *input1, const q31_t *ref, size_t length) { @@ -47,9 +49,9 @@ static void test_arm_cmplx_conj_q31( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_conj_q31, 3, in_com1, ref_conj, 3); -DEFINE_TEST_VARIANT3(arm_cmplx_conj_q31, 8, in_com1, ref_conj, 8); -DEFINE_TEST_VARIANT3(arm_cmplx_conj_q31, 11, in_com1, ref_conj, 11); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_conj_q31, 3, in_com1, ref_conj, 3); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_conj_q31, 8, in_com1, ref_conj, 8); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_conj_q31, 11, in_com1, ref_conj, 11); static void test_arm_cmplx_dot_prod_q31( const q31_t *input1, const q31_t *input2, const q63_t *ref, @@ -77,9 +79,9 @@ static void test_arm_cmplx_dot_prod_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_q31, 3, in_com1, in_com2, ref_dot_prod_3, 3); -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_q31, 8, in_com1, in_com2, ref_dot_prod_4n, 8); -DEFINE_TEST_VARIANT4(arm_cmplx_dot_prod_q31, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_dot_prod_q31, 3, in_com1, in_com2, ref_dot_prod_3, 3); +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_dot_prod_q31, 8, in_com1, in_com2, ref_dot_prod_4n, 8); +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_dot_prod_q31, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); static void test_arm_cmplx_mag_q31( const q31_t *input1, const q31_t *ref, size_t length) @@ -106,9 +108,9 @@ static void test_arm_cmplx_mag_q31( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_mag_q31, 3, in_com1, ref_mag, 3); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_q31, 8, in_com1, ref_mag, 8); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_q31, 11, in_com1, ref_mag, 11); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_mag_q31, 3, in_com1, ref_mag, 3); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_mag_q31, 8, in_com1, ref_mag, 8); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_mag_q31, 11, in_com1, ref_mag, 11); static void test_arm_cmplx_mag_squared_q31( const q31_t *input1, const q31_t *ref, size_t length) @@ -135,9 +137,9 @@ static void test_arm_cmplx_mag_squared_q31( free(output); } -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_q31, 3, in_com1, ref_mag_squared, 3); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_q31, 8, in_com1, ref_mag_squared, 8); -DEFINE_TEST_VARIANT3(arm_cmplx_mag_squared_q31, 11, in_com1, ref_mag_squared, 11); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_mag_squared_q31, 3, in_com1, ref_mag_squared, 3); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_mag_squared_q31, 8, in_com1, ref_mag_squared, 8); +DEFINE_TEST_VARIANT3(complexmath_q31, arm_cmplx_mag_squared_q31, 11, in_com1, ref_mag_squared, 11); static void test_arm_cmplx_mult_cmplx_q31( const q31_t *input1, const q31_t *input2, const q31_t *ref, @@ -170,9 +172,9 @@ static void test_arm_cmplx_mult_cmplx_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_q31, 3, in_com1, in_com2, ref_mult_cmplx, 3); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_q31, 8, in_com1, in_com2, ref_mult_cmplx, 8); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_cmplx_q31, 11, in_com1, in_com2, ref_mult_cmplx, 11); +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_mult_cmplx_q31, 3, in_com1, in_com2, ref_mult_cmplx, 3); +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_mult_cmplx_q31, 8, in_com1, in_com2, ref_mult_cmplx, 8); +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_mult_cmplx_q31, 11, in_com1, in_com2, ref_mult_cmplx, 11); static void test_arm_cmplx_mult_real_q31( const q31_t *input1, const q31_t *input2, const q31_t *ref, @@ -205,32 +207,6 @@ static void test_arm_cmplx_mult_real_q31( free(output); } -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_q31, 3, in_com1, in_com3, ref_mult_real, 3); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_q31, 8, in_com1, in_com3, ref_mult_real, 8); -DEFINE_TEST_VARIANT4(arm_cmplx_mult_real_q31, 11, in_com1, in_com3, ref_mult_real, 11); - -void test_complexmath_q31(void) -{ - ztest_test_suite(complexmath_q31, - ztest_unit_test(test_arm_cmplx_conj_q31_3), - ztest_unit_test(test_arm_cmplx_conj_q31_8), - ztest_unit_test(test_arm_cmplx_conj_q31_11), - ztest_unit_test(test_arm_cmplx_dot_prod_q31_3), - ztest_unit_test(test_arm_cmplx_dot_prod_q31_8), - ztest_unit_test(test_arm_cmplx_dot_prod_q31_11), - ztest_unit_test(test_arm_cmplx_mag_q31_3), - ztest_unit_test(test_arm_cmplx_mag_q31_8), - ztest_unit_test(test_arm_cmplx_mag_q31_11), - ztest_unit_test(test_arm_cmplx_mag_squared_q31_3), - ztest_unit_test(test_arm_cmplx_mag_squared_q31_8), - ztest_unit_test(test_arm_cmplx_mag_squared_q31_11), - ztest_unit_test(test_arm_cmplx_mult_cmplx_q31_3), - ztest_unit_test(test_arm_cmplx_mult_cmplx_q31_8), - ztest_unit_test(test_arm_cmplx_mult_cmplx_q31_11), - ztest_unit_test(test_arm_cmplx_mult_real_q31_3), - ztest_unit_test(test_arm_cmplx_mult_real_q31_8), - ztest_unit_test(test_arm_cmplx_mult_real_q31_11) - ); - - ztest_run_test_suite(complexmath_q31); -} +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_mult_real_q31, 3, in_com1, in_com3, ref_mult_real, 3); +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_mult_real_q31, 8, in_com1, in_com3, ref_mult_real, 8); +DEFINE_TEST_VARIANT4(complexmath_q31, arm_cmplx_mult_real_q31, 11, in_com1, in_com3, ref_mult_real, 11); diff --git a/tests/lib/cmsis_dsp/distance/CMakeLists.txt b/tests/lib/cmsis_dsp/distance/CMakeLists.txt index a07f94e8a31d..e2a990575b26 100644 --- a/tests/lib/cmsis_dsp/distance/CMakeLists.txt +++ b/tests/lib/cmsis_dsp/distance/CMakeLists.txt @@ -7,7 +7,6 @@ project(cmsis_dsp_distance) target_sources(app PRIVATE src/u32.c src/f32.c - src/main.c ) target_sources_ifdef(CONFIG_CMSIS_DSP_FLOAT16 app PRIVATE src/f16.c) diff --git a/tests/lib/cmsis_dsp/distance/src/f16.c b/tests/lib/cmsis_dsp/distance/src/f16.c index 9e84ec571c09..9c588e3a2f17 100644 --- a/tests/lib/cmsis_dsp/distance/src/f16.c +++ b/tests/lib/cmsis_dsp/distance/src/f16.c @@ -30,6 +30,8 @@ #define OP_JENSENSHANNON (7) #define OP_MINKOWSKI (8) +ZTEST_SUITE(distance_f16, NULL, NULL, NULL, NULL, NULL); + static void test_arm_distance(int op, bool scratchy, const uint16_t *dims, const uint16_t *dinput1, const uint16_t *dinput2, const uint16_t *ref) { @@ -132,39 +134,39 @@ static void test_arm_distance(int op, bool scratchy, const uint16_t *dims, free(tmp2); } -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f16, arm_distance, braycurtis, OP_BRAYCURTIS, false, in_dims, in_com1, in_com2, ref_braycurtis); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f16, arm_distance, canberra, OP_CANBERRA, false, in_dims, in_com1, in_com2, ref_canberra); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f16, arm_distance, chebyshev, OP_CHEBYSHEV, false, in_dims, in_com1, in_com2, ref_chebyshev); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f16, arm_distance, cityblock, OP_CITYBLOCK, false, in_dims, in_com1, in_com2, ref_cityblock); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f16, arm_distance, correlation, OP_CORRELATION, true, in_dims, in_com1, in_com2, ref_correlation); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f16, arm_distance, cosine, OP_COSINE, false, in_dims, in_com1, in_com2, ref_cosine); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f16, arm_distance, euclidean, OP_EUCLIDEAN, false, in_dims, in_com1, in_com2, ref_euclidean); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f16, arm_distance, jensenshannon, OP_JENSENSHANNON, false, in_dims, in_jen1, in_jen2, ref_jensenshannon); -static void test_arm_distance_minkowski(void) +ZTEST(distance_f16, test_arm_distance_minkowski) { size_t index; const size_t length = in_dims_minkowski[0]; @@ -199,20 +201,3 @@ static void test_arm_distance_minkowski(void) /* Free buffers */ free(output); } - -void test_distance_f16(void) -{ - ztest_test_suite(distance_f16, - ztest_unit_test(test_arm_distance_braycurtis), - ztest_unit_test(test_arm_distance_canberra), - ztest_unit_test(test_arm_distance_chebyshev), - ztest_unit_test(test_arm_distance_cityblock), - ztest_unit_test(test_arm_distance_correlation), - ztest_unit_test(test_arm_distance_cosine), - ztest_unit_test(test_arm_distance_euclidean), - ztest_unit_test(test_arm_distance_jensenshannon), - ztest_unit_test(test_arm_distance_minkowski) - ); - - ztest_run_test_suite(distance_f16); -} diff --git a/tests/lib/cmsis_dsp/distance/src/f32.c b/tests/lib/cmsis_dsp/distance/src/f32.c index 3fd83b42dbe7..bb95cbc8f844 100644 --- a/tests/lib/cmsis_dsp/distance/src/f32.c +++ b/tests/lib/cmsis_dsp/distance/src/f32.c @@ -28,6 +28,8 @@ #define OP_JENSENSHANNON (7) #define OP_MINKOWSKI (8) +ZTEST_SUITE(distance_f32, NULL, NULL, NULL, NULL, NULL); + static void test_arm_distance(int op, bool scratchy, const uint16_t *dims, const uint32_t *dinput1, const uint32_t *dinput2, const uint32_t *ref) { @@ -118,39 +120,39 @@ static void test_arm_distance(int op, bool scratchy, const uint16_t *dims, free(tmp2); } -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f32, arm_distance, braycurtis, OP_BRAYCURTIS, false, in_dims, in_com1, in_com2, ref_braycurtis); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f32, arm_distance, canberra, OP_CANBERRA, false, in_dims, in_com1, in_com2, ref_canberra); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f32, arm_distance, chebyshev, OP_CHEBYSHEV, false, in_dims, in_com1, in_com2, ref_chebyshev); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f32, arm_distance, cityblock, OP_CITYBLOCK, false, in_dims, in_com1, in_com2, ref_cityblock); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f32, arm_distance, correlation, OP_CORRELATION, true, in_dims, in_com1, in_com2, ref_correlation); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f32, arm_distance, cosine, OP_COSINE, false, in_dims, in_com1, in_com2, ref_cosine); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f32, arm_distance, euclidean, OP_EUCLIDEAN, false, in_dims, in_com1, in_com2, ref_euclidean); -DEFINE_TEST_VARIANT6( +DEFINE_TEST_VARIANT6(distance_f32, arm_distance, jensenshannon, OP_JENSENSHANNON, false, in_dims, in_jen1, in_jen2, ref_jensenshannon); -static void test_arm_distance_minkowski(void) +ZTEST(distance_f32, test_arm_distance_minkowski) { size_t index; const size_t length = in_dims_minkowski[0]; @@ -185,20 +187,3 @@ static void test_arm_distance_minkowski(void) /* Free buffers */ free(output); } - -void test_distance_f32(void) -{ - ztest_test_suite(distance_f32, - ztest_unit_test(test_arm_distance_braycurtis), - ztest_unit_test(test_arm_distance_canberra), - ztest_unit_test(test_arm_distance_chebyshev), - ztest_unit_test(test_arm_distance_cityblock), - ztest_unit_test(test_arm_distance_correlation), - ztest_unit_test(test_arm_distance_cosine), - ztest_unit_test(test_arm_distance_euclidean), - ztest_unit_test(test_arm_distance_jensenshannon), - ztest_unit_test(test_arm_distance_minkowski) - ); - - ztest_run_test_suite(distance_f32); -} diff --git a/tests/lib/cmsis_dsp/distance/src/main.c b/tests/lib/cmsis_dsp/distance/src/main.c deleted file mode 100644 index 9ce552068fec..000000000000 --- a/tests/lib/cmsis_dsp/distance/src/main.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2021 Stephanos Ioannidis - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -extern void test_distance_u32(void); -extern void test_distance_f16(void); -extern void test_distance_f32(void); - -void test_main(void) -{ - test_distance_u32(); -#ifdef CONFIG_CMSIS_DSP_FLOAT16 - test_distance_f16(); -#endif - test_distance_f32(); -} diff --git a/tests/lib/cmsis_dsp/distance/src/u32.c b/tests/lib/cmsis_dsp/distance/src/u32.c index 7abc6fe95c1c..e4a491920be8 100644 --- a/tests/lib/cmsis_dsp/distance/src/u32.c +++ b/tests/lib/cmsis_dsp/distance/src/u32.c @@ -29,6 +29,8 @@ #define OP_SOKALSNEATH (7) #define OP_YULE (8) +ZTEST_SUITE(distance_u32, NULL, NULL, NULL, NULL, NULL); + static void test_arm_distance(int op, const uint16_t *dims, const uint32_t *input1, const uint32_t *input2, const uint32_t *ref) { @@ -99,55 +101,38 @@ static void test_arm_distance(int op, const uint16_t *dims, free(output); } -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, dice, OP_DICE, in_dims, in_com1, in_com2, ref_dice); -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, hamming, OP_HAMMING, in_dims, in_com1, in_com2, ref_hamming); -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, jaccard, OP_JACCARD, in_dims, in_com1, in_com2, ref_jaccard); -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, kulsinski, OP_KULSINSKI, in_dims, in_com1, in_com2, ref_kulsinski); -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, rogerstanimoto, OP_ROGERSTANIMOTO, in_dims, in_com1, in_com2, ref_rogerstanimoto); -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, russellrao, OP_RUSSELLRAO, in_dims, in_com1, in_com2, ref_russellrao); -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, sokalmichener, OP_SOKALMICHENER, in_dims, in_com1, in_com2, ref_sokalmichener); -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, sokalsneath, OP_SOKALSNEATH, in_dims, in_com1, in_com2, ref_sokalsneath); -DEFINE_TEST_VARIANT5( +DEFINE_TEST_VARIANT5(distance_u32, arm_distance, yule, OP_YULE, in_dims, in_com1, in_com2, ref_yule); - -void test_distance_u32(void) -{ - ztest_test_suite(distance_u32, - ztest_unit_test(test_arm_distance_dice), - ztest_unit_test(test_arm_distance_hamming), - ztest_unit_test(test_arm_distance_jaccard), - ztest_unit_test(test_arm_distance_kulsinski), - ztest_unit_test(test_arm_distance_rogerstanimoto), - ztest_unit_test(test_arm_distance_russellrao), - ztest_unit_test(test_arm_distance_sokalmichener), - ztest_unit_test(test_arm_distance_sokalsneath), - ztest_unit_test(test_arm_distance_yule) - ); - - ztest_run_test_suite(distance_u32); -} diff --git a/tests/lib/cmsis_dsp/fastmath/CMakeLists.txt b/tests/lib/cmsis_dsp/fastmath/CMakeLists.txt index cfa70632b150..5a0c9fd95d79 100644 --- a/tests/lib/cmsis_dsp/fastmath/CMakeLists.txt +++ b/tests/lib/cmsis_dsp/fastmath/CMakeLists.txt @@ -8,7 +8,6 @@ target_sources(app PRIVATE src/q15.c src/q31.c src/f32.c - src/main.c ) target_sources_ifdef(CONFIG_CMSIS_DSP_FLOAT16 app PRIVATE src/f16.c) diff --git a/tests/lib/cmsis_dsp/fastmath/src/f16.c b/tests/lib/cmsis_dsp/fastmath/src/f16.c index 84b4925adef5..84ae6b058c14 100644 --- a/tests/lib/cmsis_dsp/fastmath/src/f16.c +++ b/tests/lib/cmsis_dsp/fastmath/src/f16.c @@ -86,7 +86,9 @@ static void test_arm_sin_f16(void) } #endif -static void test_arm_sqrt_f16(void) +ZTEST_SUITE(fastmath_f16, NULL, NULL, NULL, NULL, NULL); + +ZTEST(fastmath_f16, test_arm_sqrt_f16) { size_t index; size_t length = ARRAY_SIZE(in_sqrt); @@ -155,10 +157,10 @@ static void test_arm_vlog_f16( free(output); } -DEFINE_TEST_VARIANT3(arm_vlog_f16, all, in_log, ref_log, 25); -DEFINE_TEST_VARIANT3(arm_vlog_f16, 3, in_log, ref_log, 3); -DEFINE_TEST_VARIANT3(arm_vlog_f16, 8, in_log, ref_log, 8); -DEFINE_TEST_VARIANT3(arm_vlog_f16, 11, in_log, ref_log, 11); +DEFINE_TEST_VARIANT3(fastmath_f16, arm_vlog_f16, all, in_log, ref_log, 25); +DEFINE_TEST_VARIANT3(fastmath_f16, arm_vlog_f16, 3, in_log, ref_log, 3); +DEFINE_TEST_VARIANT3(fastmath_f16, arm_vlog_f16, 8, in_log, ref_log, 8); +DEFINE_TEST_VARIANT3(fastmath_f16, arm_vlog_f16, 11, in_log, ref_log, 11); static void test_arm_vexp_f16( const uint16_t *input1, const uint16_t *ref, size_t length) @@ -187,12 +189,12 @@ static void test_arm_vexp_f16( free(output); } -DEFINE_TEST_VARIANT3(arm_vexp_f16, all, in_exp, ref_exp, 52); -DEFINE_TEST_VARIANT3(arm_vexp_f16, 3, in_exp, ref_exp, 3); -DEFINE_TEST_VARIANT3(arm_vexp_f16, 8, in_exp, ref_exp, 8); -DEFINE_TEST_VARIANT3(arm_vexp_f16, 11, in_exp, ref_exp, 11); +DEFINE_TEST_VARIANT3(fastmath_f16, arm_vexp_f16, all, in_exp, ref_exp, 52); +DEFINE_TEST_VARIANT3(fastmath_f16, arm_vexp_f16, 3, in_exp, ref_exp, 3); +DEFINE_TEST_VARIANT3(fastmath_f16, arm_vexp_f16, 8, in_exp, ref_exp, 8); +DEFINE_TEST_VARIANT3(fastmath_f16, arm_vexp_f16, 11, in_exp, ref_exp, 11); -static void test_arm_vinverse_f16(void) +ZTEST(fastmath_f16, test_arm_vinverse_f16) { size_t length = ARRAY_SIZE(ref_vinverse); float16_t *output; @@ -219,25 +221,4 @@ static void test_arm_vinverse_f16(void) free(output); } -void test_fastmath_f16(void) -{ - ztest_test_suite(fastmath_f16, - /* NOTE: F16 sin and cos are not implemented for now */ - /* ztest_unit_test(test_arm_cos_f16), */ - /* ztest_unit_test(test_arm_sin_f16), */ - ztest_unit_test(test_arm_sqrt_f16), - ztest_unit_test(test_arm_vlog_f16_all), - ztest_unit_test(test_arm_vlog_f16_3), - ztest_unit_test(test_arm_vlog_f16_8), - ztest_unit_test(test_arm_vlog_f16_11), - ztest_unit_test(test_arm_vexp_f16_all), - ztest_unit_test(test_arm_vexp_f16_3), - ztest_unit_test(test_arm_vexp_f16_8), - ztest_unit_test(test_arm_vexp_f16_11), - ztest_unit_test(test_arm_vinverse_f16) - ); - - ztest_run_test_suite(fastmath_f16); -} - /* TODO: Add inverse test */ diff --git a/tests/lib/cmsis_dsp/fastmath/src/f32.c b/tests/lib/cmsis_dsp/fastmath/src/f32.c index 99cf8d31728a..d32d53211294 100644 --- a/tests/lib/cmsis_dsp/fastmath/src/f32.c +++ b/tests/lib/cmsis_dsp/fastmath/src/f32.c @@ -17,7 +17,9 @@ #define REL_ERROR_THRESH (1.0e-6) #define ABS_ERROR_THRESH (1.0e-5) -static void test_arm_cos_f32(void) +ZTEST_SUITE(fastmath_f32, NULL, NULL, NULL, NULL, NULL); + +ZTEST(fastmath_f32, test_arm_cos_f32) { size_t index; size_t length = ARRAY_SIZE(in_angles); @@ -47,7 +49,7 @@ static void test_arm_cos_f32(void) free(output); } -static void test_arm_sin_f32(void) +ZTEST(fastmath_f32, test_arm_sin_f32) { size_t index; size_t length = ARRAY_SIZE(in_angles); @@ -77,7 +79,7 @@ static void test_arm_sin_f32(void) free(output); } -static void test_arm_sqrt_f32(void) +ZTEST(fastmath_f32, test_arm_sqrt_f32) { size_t index; size_t length = ARRAY_SIZE(in_sqrt); @@ -146,10 +148,10 @@ static void test_arm_vlog_f32( free(output); } -DEFINE_TEST_VARIANT3(arm_vlog_f32, all, in_log, ref_log, 25); -DEFINE_TEST_VARIANT3(arm_vlog_f32, 3, in_log, ref_log, 3); -DEFINE_TEST_VARIANT3(arm_vlog_f32, 8, in_log, ref_log, 8); -DEFINE_TEST_VARIANT3(arm_vlog_f32, 11, in_log, ref_log, 11); +DEFINE_TEST_VARIANT3(fastmath_f32, arm_vlog_f32, all, in_log, ref_log, 25); +DEFINE_TEST_VARIANT3(fastmath_f32, arm_vlog_f32, 3, in_log, ref_log, 3); +DEFINE_TEST_VARIANT3(fastmath_f32, arm_vlog_f32, 8, in_log, ref_log, 8); +DEFINE_TEST_VARIANT3(fastmath_f32, arm_vlog_f32, 11, in_log, ref_log, 11); static void test_arm_vexp_f32( const uint32_t *input1, const uint32_t *ref, size_t length) @@ -178,26 +180,7 @@ static void test_arm_vexp_f32( free(output); } -DEFINE_TEST_VARIANT3(arm_vexp_f32, all, in_exp, ref_exp, 52); -DEFINE_TEST_VARIANT3(arm_vexp_f32, 3, in_exp, ref_exp, 3); -DEFINE_TEST_VARIANT3(arm_vexp_f32, 8, in_exp, ref_exp, 8); -DEFINE_TEST_VARIANT3(arm_vexp_f32, 11, in_exp, ref_exp, 11); - -void test_fastmath_f32(void) -{ - ztest_test_suite(fastmath_f32, - ztest_unit_test(test_arm_cos_f32), - ztest_unit_test(test_arm_sin_f32), - ztest_unit_test(test_arm_sqrt_f32), - ztest_unit_test(test_arm_vlog_f32_all), - ztest_unit_test(test_arm_vlog_f32_3), - ztest_unit_test(test_arm_vlog_f32_8), - ztest_unit_test(test_arm_vlog_f32_11), - ztest_unit_test(test_arm_vexp_f32_all), - ztest_unit_test(test_arm_vexp_f32_3), - ztest_unit_test(test_arm_vexp_f32_8), - ztest_unit_test(test_arm_vexp_f32_11) - ); - - ztest_run_test_suite(fastmath_f32); -} +DEFINE_TEST_VARIANT3(fastmath_f32, arm_vexp_f32, all, in_exp, ref_exp, 52); +DEFINE_TEST_VARIANT3(fastmath_f32, arm_vexp_f32, 3, in_exp, ref_exp, 3); +DEFINE_TEST_VARIANT3(fastmath_f32, arm_vexp_f32, 8, in_exp, ref_exp, 8); +DEFINE_TEST_VARIANT3(fastmath_f32, arm_vexp_f32, 11, in_exp, ref_exp, 11); diff --git a/tests/lib/cmsis_dsp/fastmath/src/main.c b/tests/lib/cmsis_dsp/fastmath/src/main.c deleted file mode 100644 index 3f7c051a9bfb..000000000000 --- a/tests/lib/cmsis_dsp/fastmath/src/main.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2021 Stephanos Ioannidis - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -extern void test_fastmath_q15(void); -extern void test_fastmath_q31(void); -extern void test_fastmath_f16(void); -extern void test_fastmath_f32(void); - -void test_main(void) -{ - test_fastmath_q15(); - test_fastmath_q31(); -#ifdef CONFIG_CMSIS_DSP_FLOAT16 - test_fastmath_f16(); -#endif - test_fastmath_f32(); -} diff --git a/tests/lib/cmsis_dsp/fastmath/src/q15.c b/tests/lib/cmsis_dsp/fastmath/src/q15.c index 07c9fe779d0f..929cf8415e20 100644 --- a/tests/lib/cmsis_dsp/fastmath/src/q15.c +++ b/tests/lib/cmsis_dsp/fastmath/src/q15.c @@ -16,7 +16,9 @@ #define SNR_ERROR_THRESH ((float32_t)70) #define ABS_ERROR_THRESH ((q15_t)10) -static void test_arm_cos_q15(void) +ZTEST_SUITE(fastmath_q15, NULL, NULL, NULL, NULL, NULL); + +ZTEST(fastmath_q15, test_arm_cos_q15) { size_t index; size_t length = ARRAY_SIZE(in_angles); @@ -44,7 +46,7 @@ static void test_arm_cos_q15(void) free(output); } -static void test_arm_sin_q15(void) +ZTEST(fastmath_q15, test_arm_sin_q15) { size_t index; size_t length = ARRAY_SIZE(in_angles); @@ -72,7 +74,7 @@ static void test_arm_sin_q15(void) free(output); } -static void test_arm_sqrt_q15(void) +ZTEST(fastmath_q15, test_arm_sqrt_q15) { size_t index; size_t length = ARRAY_SIZE(in_sqrt); @@ -112,7 +114,7 @@ static void test_arm_sqrt_q15(void) free(output); } -static void test_arm_divide_q15(void) +ZTEST(fastmath_q15, test_arm_divide_q15) { size_t index; size_t length = ARRAY_SIZE(ref_divide); @@ -153,15 +155,3 @@ static void test_arm_divide_q15(void) free(output); free(shift); } - -void test_fastmath_q15(void) -{ - ztest_test_suite(fastmath_q15, - ztest_unit_test(test_arm_cos_q15), - ztest_unit_test(test_arm_sin_q15), - ztest_unit_test(test_arm_sqrt_q15), - ztest_unit_test(test_arm_divide_q15) - ); - - ztest_run_test_suite(fastmath_q15); -} diff --git a/tests/lib/cmsis_dsp/fastmath/src/q31.c b/tests/lib/cmsis_dsp/fastmath/src/q31.c index 62b48090ced1..da7c7e48273b 100644 --- a/tests/lib/cmsis_dsp/fastmath/src/q31.c +++ b/tests/lib/cmsis_dsp/fastmath/src/q31.c @@ -16,7 +16,9 @@ #define SNR_ERROR_THRESH ((float32_t)100) #define ABS_ERROR_THRESH ((q31_t)2200) -static void test_arm_cos_q31(void) +ZTEST_SUITE(fastmath_q31, NULL, NULL, NULL, NULL, NULL); + +ZTEST(fastmath_q31, test_arm_cos_q31) { size_t index; size_t length = ARRAY_SIZE(in_angles); @@ -44,7 +46,7 @@ static void test_arm_cos_q31(void) free(output); } -static void test_arm_sin_q31(void) +ZTEST(fastmath_q31, test_arm_sin_q31) { size_t index; size_t length = ARRAY_SIZE(in_angles); @@ -72,7 +74,7 @@ static void test_arm_sin_q31(void) free(output); } -static void test_arm_sqrt_q31(void) +ZTEST(fastmath_q31, test_arm_sqrt_q31) { size_t index; size_t length = ARRAY_SIZE(in_sqrt); @@ -111,14 +113,3 @@ static void test_arm_sqrt_q31(void) /* Free output buffer */ free(output); } - -void test_fastmath_q31(void) -{ - ztest_test_suite(fastmath_q31, - ztest_unit_test(test_arm_cos_q31), - ztest_unit_test(test_arm_sin_q31), - ztest_unit_test(test_arm_sqrt_q31) - ); - - ztest_run_test_suite(fastmath_q31); -} diff --git a/tests/ztest/base/src/main.c b/tests/ztest/base/src/main.c index 7c2482051bd1..07fc9eb47474 100644 --- a/tests/ztest/base/src/main.c +++ b/tests/ztest/base/src/main.c @@ -6,11 +6,13 @@ #include -static void test_empty_test(void) +ZTEST_SUITE(framework_tests, NULL, NULL, NULL, NULL, NULL); + +ZTEST(framework_tests, test_empty_test) { } -static void test_assert_tests(void) +ZTEST(framework_tests, test_assert_tests) { zassert_true(1, NULL); zassert_false(0, NULL); @@ -20,7 +22,7 @@ static void test_assert_tests(void) zassert_equal_ptr(NULL, NULL, NULL); } -static void test_assert_mem_equal(void) +ZTEST(framework_tests, test_assert_mem_equal) { static const uint32_t expected[4] = { 0x1234, @@ -33,13 +35,94 @@ static void test_assert_mem_equal(void) zassert_mem_equal(actual, expected, sizeof(expected), NULL); } -void test_main(void) +/*************************************************************************************************** + * Sample fixture tests + **************************************************************************************************/ + +struct fixture_tests_fixture { +}; + +static struct fixture_tests_fixture test_fixture; + +static void *fixture_tests_setup(void) +{ + return &test_fixture; +} + +ZTEST_SUITE(fixture_tests, NULL, fixture_tests_setup, NULL, NULL, NULL); + +ZTEST_F(fixture_tests, test_fixture_pointer) +{ + zassert_equal_ptr(&test_fixture, this, "Test fixture should be at 0x%x but was at 0x%x", + &test_fixture, this); +} + +/*************************************************************************************************** + * Sample rule tests + **************************************************************************************************/ + +enum rule_state { + RULE_STATE_SETUP = 0, + RULE_STATE_BEFORE_EACH, + RULE_STATE_TEST, + RULE_STATE_AFTER_EACH, +}; + +struct rules_tests_fixture { + enum rule_state state; +}; + +static struct rules_tests_fixture rule_tests_fixture; + +static void rule_before_each(const struct ztest_unit_test *test, void *data) { - ztest_test_suite(framework_tests, - ztest_unit_test(test_empty_test), - ztest_unit_test(test_assert_tests), - ztest_unit_test(test_assert_mem_equal) - ); + if (strcmp(test->test_suite_name, "rules_tests") == 0 && + strcmp(test->name, "test_rules_before_after") == 0) { + struct rules_tests_fixture *fixture = data; - ztest_run_test_suite(framework_tests); + zassert_equal_ptr(&rule_tests_fixture, data, + "Data expected to point to rule_state"); + zassert_equal(fixture->state, RULE_STATE_SETUP, "Unexpected state"); + fixture->state = RULE_STATE_BEFORE_EACH; + } +} + +static void rule_after_each(const struct ztest_unit_test *test, void *data) +{ + if (strcmp(test->test_suite_name, "rules_tests") == 0 && + strcmp(test->name, "test_rules_before_after") == 0) { + struct rules_tests_fixture *fixture = data; + + zassert_equal_ptr(&rule_tests_fixture, data, + "Data expected to point to rule_state"); + zassert_equal(fixture->state, RULE_STATE_TEST, "Unexpected state"); + fixture->state = RULE_STATE_AFTER_EACH; + } +} + +static void *rule_test_setup(void) +{ + rule_tests_fixture.state = RULE_STATE_SETUP; + return &rule_tests_fixture; +} + +static void rule_test_teardown(void *data) +{ + struct rules_tests_fixture *fixture = data; + + /* + * Normally, we wouldn't assert here, but it's the only way to test that the rule's + * after_each function was called. + */ + zassert_equal(fixture->state, RULE_STATE_AFTER_EACH, "Unexpected state"); +} + +ZTEST_RULE(verify_before_after_rule, rule_before_each, rule_after_each); + +ZTEST_SUITE(rules_tests, NULL, rule_test_setup, NULL, NULL, rule_test_teardown); + +ZTEST_F(rules_tests, test_rules_before_after) +{ + zassert_equal(this->state, RULE_STATE_BEFORE_EACH, "Unexpected state"); + this->state = RULE_STATE_TEST; }