From 85cc902a0d95b26f8c682dcfb4be43f684ba52de Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 26 Apr 2022 18:07:21 -0400 Subject: [PATCH] Revert "ztest: migrate error_hook tests to new API" This reverts commit fa13d57f0186ed00925f9b3471247920a2c2e97b. Signed-off-by: Anas Nashif --- tests/ztest/error_hook/prj.conf | 1 - tests/ztest/error_hook/prj_no_userspace.conf | 1 - tests/ztest/error_hook/src/main.c | 33 +++++++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/ztest/error_hook/prj.conf b/tests/ztest/error_hook/prj.conf index 92b422165e8..476cfce144d 100644 --- a/tests/ztest/error_hook/prj.conf +++ b/tests/ztest/error_hook/prj.conf @@ -1,5 +1,4 @@ CONFIG_ZTEST=y -CONFIG_ZTEST_NEW_API=y CONFIG_TEST_USERSPACE=y CONFIG_IRQ_OFFLOAD=y CONFIG_ZTEST_FATAL_HOOK=y diff --git a/tests/ztest/error_hook/prj_no_userspace.conf b/tests/ztest/error_hook/prj_no_userspace.conf index 40586ee71ce..d94a147feb5 100644 --- a/tests/ztest/error_hook/prj_no_userspace.conf +++ b/tests/ztest/error_hook/prj_no_userspace.conf @@ -1,5 +1,4 @@ CONFIG_ZTEST=y -CONFIG_ZTEST_NEW_API=y CONFIG_IRQ_OFFLOAD=y CONFIG_ZTEST_FATAL_HOOK=y CONFIG_ZTEST_ASSERT_HOOK=y diff --git a/tests/ztest/error_hook/src/main.c b/tests/ztest/error_hook/src/main.c index 775ba02dcad..932d952f1e6 100644 --- a/tests/ztest/error_hook/src/main.c +++ b/tests/ztest/error_hook/src/main.c @@ -262,7 +262,7 @@ static int run_trigger_thread(int i) * If the fatal error happened and the program enter assert_post_handler, * that means fatal error triggered as expected. */ -ZTEST_USER(error_hook_tests, test_catch_fatal_error) +void test_catch_fatal_error(void) { #if defined(CONFIG_USERSPACE) run_trigger_thread(ZTEST_CATCH_FATAL_ACCESS); @@ -287,20 +287,15 @@ ZTEST_USER(error_hook_tests, test_catch_fatal_error) * fail happened and the program enter assert_post_handler, that means * assert works as expected. */ -ZTEST_USER(error_hook_tests, test_catch_assert_fail) +void test_catch_assert_fail(void) { case_type = ZTEST_CATCH_ASSERT_FAIL; - printk("1\n"); ztest_set_assert_valid(false); - printk("2\n"); ztest_set_assert_valid(true); - - printk("3\n"); trigger_assert_fail(NULL); - printk("4\n"); ztest_test_fail(); } @@ -318,7 +313,7 @@ static void tIsr_assert(const void *p) * fail happened and the program enter assert_post_handler, that means * assert works as expected. */ -ZTEST(error_hook_tests, test_catch_assert_in_isr) +void test_catch_assert_in_isr(void) { case_type = ZTEST_CATCH_ASSERT_IN_ISR; irq_offload(tIsr_assert, NULL); @@ -342,7 +337,7 @@ static void trigger_z_oops(void) * that means z_oops triggered as expected. This test only for * userspace. */ -ZTEST(error_hook_tests, test_catch_z_oops) +void test_catch_z_oops(void) { case_type = ZTEST_CATCH_USER_FATAL_Z_OOPS; @@ -352,11 +347,25 @@ ZTEST(error_hook_tests, test_catch_z_oops) #endif -static void *error_hook_tests_setup(void) +void test_main(void) { + #if defined(CONFIG_USERSPACE) k_thread_access_grant(k_current_get(), &tdata, &tstack); + + ztest_test_suite(error_hook_tests, + ztest_user_unit_test(test_catch_assert_fail), + ztest_user_unit_test(test_catch_fatal_error), + ztest_unit_test(test_catch_z_oops), + ztest_unit_test(test_catch_assert_in_isr) + ); + ztest_run_test_suite(error_hook_tests); +#else + ztest_test_suite(error_hook_tests, + ztest_unit_test(test_catch_fatal_error), + ztest_unit_test(test_catch_assert_fail), + ztest_unit_test(test_catch_assert_in_isr) + ); + ztest_run_test_suite(error_hook_tests); #endif - return NULL; } -ZTEST_SUITE(error_hook_tests, NULL, error_hook_tests_setup, NULL, NULL, NULL);