Skip to content

Commit

Permalink
tests: ztest: remove the testcase that catches an assertion in ISR
Browse files Browse the repository at this point in the history
This testcase shows triggering an assertion in ISR intentionally, for
verifying the assertion works in our code. But currently, the ztest
error hook doesn't have a mechanism to fully recover from ISR context
for different platforms. It needs to recover the resource being hold
and exit ISR context, otherwise, the program will not stable enough to
execute the following testcases. We already submitted a workaround
PR#34846 for it by putting these kinds of testcases executing last.

Anyway, we recommend not to use it this way unless our ztest error
hook mechanism can be refined to handle this recovery completely.
So we tend to remove this testcase at this moment.

Fixes zephyrproject-rtos#34844

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
  • Loading branch information
Enjia Mai committed May 17, 2021
1 parent 878043a commit f0ff8d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 52 deletions.
17 changes: 3 additions & 14 deletions tests/ztest/error_hook/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ test_catch_fatal_error
- start a thread to call k_oops() then catch the (expected) fatal error.
- start a thread to call k_panel() then catch the (expected) fatal error.

test_catch_assert_in_isr
- start a thread to enter ISR context by calling irq_offload(), then trigger
an assert fail then catch it.

test_catch_z_oops
- Pass illegal address by syscall, then inside the syscall handler, the
Z_OOPS macro will trigger a fatal error that will get caught (as expected).
Expand All @@ -87,9 +83,9 @@ test_catch_z_oops
Limitation of this usage
========================

Trigger a fatal error in ISR context, that will cause problem due to
the interrupt stack is already abnormal when we want to continue other
test case, we do not recover it so far.
Trigger a fatal error or catch an assert failure in ISR context, that will cause
problem due to the interrupt stack is already abnormal when we want to continue
other test case, we do not recover it so far.


---------------------------------------------------------------------------
Expand Down Expand Up @@ -171,13 +167,6 @@ Caught system error -- reason 3 1
Fatal error expected as part of test case.
PASS - test_catch_fatal_error
===================================================================
START - test_catch_assert_in_isr
ASSERTION FAIL [a != ((void *)0)] @ WEST_TOPDIR/zephyr/tests/ztest/error_hook/src/main.c:41
parameter a should not be NULL!
Caught assert failed
Assert error expected as part of test case.
PASS - test_catch_assert_in_isr
===================================================================
START - test_catch_z_oops
E: EAX: 0x00000000, EBX: 0x00000000, ECX: 0x00000000, EDX: 0x00000000
E: ESI: 0x00000000, EDI: 0x00000000, EBP: 0x00000000, ESP: 0x00000000
Expand Down
47 changes: 9 additions & 38 deletions tests/ztest/error_hook/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ static struct k_thread tdata;

static ZTEST_BMEM int case_type;

/* A semaphore using inside irq_offload */
extern struct k_sem offload_sem;

/* test case type */
enum {
ZTEST_CATCH_FATAL_ACCESS,
Expand Down Expand Up @@ -127,14 +124,6 @@ static void trigger_fault_panic(void)
k_panic();
}

static void release_offload_sem(void)
{
/* Semaphore used inside irq_offload needs to be
* released after an assert or a fault has happened.
*/
k_sem_give(&offload_sem);
}

/* This is the fatal error hook that allows you to do actions after
* the fatal error has occurred. This is optional; you can choose
* to define the hook yourself. If not, the program will use the
Expand Down Expand Up @@ -176,9 +165,14 @@ void ztest_post_assert_fail_hook(void)
case ZTEST_CATCH_ASSERT_FAIL:
ztest_test_pass();
break;

/* Unfortunately, like the ZTEST_CATCH_FATAL_IN_ISR case,
* try to capture an failed assert inside ISR context, is
* also cannot be fully recovered by our framework, so
* please don't use it this way.
*/
case ZTEST_CATCH_ASSERT_IN_ISR:
release_offload_sem();
ztest_test_pass();
zassert_true(false, NULL);
break;

default:
Expand Down Expand Up @@ -284,27 +278,6 @@ void test_catch_assert_fail(void)
ztest_test_fail();
}

/* a handler using by irq_offload */
static void tIsr_assert(const void *p)
{
ztest_set_assert_valid(true);
trigger_assert_fail(NULL);
}

/**
* @brief Test if an assert fail works in ISR context
*
* @details Valid the assert in ISR context works or not. If the assert
* fail happened and the program enter assert_post_handler, that means
* assert works as expected.
*/
void test_catch_assert_in_isr(void)
{
case_type = ZTEST_CATCH_ASSERT_IN_ISR;
irq_offload(tIsr_assert, NULL);
}


#if defined(CONFIG_USERSPACE)
static void trigger_z_oops(void)
{
Expand Down Expand Up @@ -341,15 +314,13 @@ void test_main(void)
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_unit_test(test_catch_z_oops)
);
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_unit_test(test_catch_assert_fail)
);
ztest_run_test_suite(error_hook_tests);
#endif
Expand Down

0 comments on commit f0ff8d1

Please sign in to comment.