tests/kernel/threads: Correct essential thread abort test
Thread abort of essential threads had a buglet where the panic would be signaled but, if caught by k_sys_fatal_error_handler(), the thread would not actually be aborted. This test wasn't validating that the thread was actually dead (in fac, it RELIED on the thread to signal a semaphore after its "abort"!). Make sure it's dead and that the panic is caught. Also add a case for aborting _current which is a separate code path that needs coverage. Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
parent
f6239c52ae
commit
cc411ffe69
1 changed files with 23 additions and 13 deletions
|
@ -67,8 +67,6 @@ void k_sys_fatal_error_handler(unsigned int reason,
|
|||
ARG_UNUSED(reason);
|
||||
|
||||
fatal_error_signaled = true;
|
||||
|
||||
z_thread_essential_clear(_current);
|
||||
}
|
||||
|
||||
static void abort_thread_entry(void *p1, void *p2, void *p3)
|
||||
|
@ -77,16 +75,19 @@ static void abort_thread_entry(void *p1, void *p2, void *p3)
|
|||
ARG_UNUSED(p2);
|
||||
ARG_UNUSED(p3);
|
||||
|
||||
z_thread_essential_set(_current);
|
||||
|
||||
if (z_is_thread_essential(_current)) {
|
||||
k_busy_wait(100);
|
||||
k_msleep(200);
|
||||
} else {
|
||||
zassert_unreachable("The thread is not set as essential");
|
||||
}
|
||||
|
||||
k_sem_give(&sync_sem);
|
||||
k_sleep(K_FOREVER);
|
||||
zassert_true(false, "Should not reach this line");
|
||||
}
|
||||
|
||||
static void abort_thread_self(void *p1, void *p2, void *p3)
|
||||
{
|
||||
k_thread_abort(k_current_get());
|
||||
zassert_true(false, "Should not reach this line");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,13 +103,22 @@ static void abort_thread_entry(void *p1, void *p2, void *p3)
|
|||
|
||||
ZTEST(threads_lifecycle, test_essential_thread_abort)
|
||||
{
|
||||
k_tid_t tid = k_thread_create(&kthread_thread1, kthread_stack, STACKSIZE,
|
||||
abort_thread_entry,
|
||||
NULL, NULL, NULL, K_PRIO_PREEMPT(0), 0,
|
||||
K_NO_WAIT);
|
||||
fatal_error_signaled = false;
|
||||
k_thread_create(&kthread_thread1, kthread_stack, STACKSIZE,
|
||||
abort_thread_entry,
|
||||
NULL, NULL, NULL, K_PRIO_PREEMPT(0), K_ESSENTIAL,
|
||||
K_NO_WAIT);
|
||||
|
||||
k_sem_take(&sync_sem, K_FOREVER);
|
||||
k_thread_abort(tid);
|
||||
k_msleep(100);
|
||||
k_thread_abort(&kthread_thread1);
|
||||
zassert_true(fatal_error_signaled, "fatal error was not signaled");
|
||||
|
||||
fatal_error_signaled = false;
|
||||
k_thread_create(&kthread_thread1, kthread_stack, STACKSIZE,
|
||||
abort_thread_self,
|
||||
NULL, NULL, NULL, K_PRIO_PREEMPT(0), K_ESSENTIAL,
|
||||
K_NO_WAIT);
|
||||
|
||||
k_msleep(100);
|
||||
zassert_true(fatal_error_signaled, "fatal error was not signaled");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue