Skip to content

Commit cc411ff

Browse files
andyrosskartben
authored andcommitted
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 <[email protected]>
1 parent f6239c5 commit cc411ff

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

tests/kernel/threads/thread_apis/src/test_essential_thread.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ void k_sys_fatal_error_handler(unsigned int reason,
6767
ARG_UNUSED(reason);
6868

6969
fatal_error_signaled = true;
70-
71-
z_thread_essential_clear(_current);
7270
}
7371

7472
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)
7775
ARG_UNUSED(p2);
7876
ARG_UNUSED(p3);
7977

80-
z_thread_essential_set(_current);
81-
8278
if (z_is_thread_essential(_current)) {
83-
k_busy_wait(100);
79+
k_msleep(200);
8480
} else {
8581
zassert_unreachable("The thread is not set as essential");
8682
}
8783

88-
k_sem_give(&sync_sem);
89-
k_sleep(K_FOREVER);
84+
zassert_true(false, "Should not reach this line");
85+
}
86+
87+
static void abort_thread_self(void *p1, void *p2, void *p3)
88+
{
89+
k_thread_abort(k_current_get());
90+
zassert_true(false, "Should not reach this line");
9091
}
9192

9293
/**
@@ -102,13 +103,22 @@ static void abort_thread_entry(void *p1, void *p2, void *p3)
102103

103104
ZTEST(threads_lifecycle, test_essential_thread_abort)
104105
{
105-
k_tid_t tid = k_thread_create(&kthread_thread1, kthread_stack, STACKSIZE,
106-
abort_thread_entry,
107-
NULL, NULL, NULL, K_PRIO_PREEMPT(0), 0,
108-
K_NO_WAIT);
106+
fatal_error_signaled = false;
107+
k_thread_create(&kthread_thread1, kthread_stack, STACKSIZE,
108+
abort_thread_entry,
109+
NULL, NULL, NULL, K_PRIO_PREEMPT(0), K_ESSENTIAL,
110+
K_NO_WAIT);
111+
112+
k_msleep(100);
113+
k_thread_abort(&kthread_thread1);
114+
zassert_true(fatal_error_signaled, "fatal error was not signaled");
109115

110-
k_sem_take(&sync_sem, K_FOREVER);
111-
k_thread_abort(tid);
116+
fatal_error_signaled = false;
117+
k_thread_create(&kthread_thread1, kthread_stack, STACKSIZE,
118+
abort_thread_self,
119+
NULL, NULL, NULL, K_PRIO_PREEMPT(0), K_ESSENTIAL,
120+
K_NO_WAIT);
112121

122+
k_msleep(100);
113123
zassert_true(fatal_error_signaled, "fatal error was not signaled");
114124
}

0 commit comments

Comments
 (0)