Skip to content

Commit bdfa021

Browse files
spoorthikAnas Nashif
authored andcommitted
tests: kernel: Test for essential thread set/clear
The test verifies the API functionality of _thread_essential_clear(), _thread_essential_set() and _is_thread_essential() Signed-off-by: Spoorthi K <[email protected]>
1 parent 71ddd82 commit bdfa021

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

tests/kernel/threads/lifecycle/lifecycle_api/src/main.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern void test_threads_abort_self(void);
2626
extern void test_threads_abort_others(void);
2727
extern void test_threads_abort_repeat(void);
2828
extern void test_abort_handler(void);
29+
extern void test_essential_thread_operation(void);
2930

3031
__kernel struct k_thread tdata;
3132
#define STACK_SIZE (256 + CONFIG_TEST_EXTRA_STACKSIZE)
@@ -41,15 +42,18 @@ void test_main(void)
4142
ztest_unit_test(test_threads_spawn_priority),
4243
ztest_user_unit_test(test_threads_spawn_delay),
4344
ztest_unit_test(test_threads_spawn_forever),
44-
ztest_unit_test(test_threads_suspend_resume_cooperative),
45-
ztest_unit_test(test_threads_suspend_resume_preemptible),
45+
ztest_unit_test(
46+
test_threads_suspend_resume_cooperative),
47+
ztest_unit_test(
48+
test_threads_suspend_resume_preemptible),
4649
ztest_user_unit_test(test_threads_cancel_undelayed),
4750
ztest_user_unit_test(test_threads_cancel_delayed),
4851
ztest_user_unit_test(test_threads_cancel_started),
4952
ztest_user_unit_test(test_threads_abort_self),
5053
ztest_user_unit_test(test_threads_abort_others),
5154
ztest_unit_test(test_threads_abort_repeat),
52-
ztest_unit_test(test_abort_handler)
55+
ztest_unit_test(test_abort_handler),
56+
ztest_unit_test(test_essential_thread_operation)
5357
);
5458
ztest_run_test_suite(test_threads_lifecycle);
5559
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <ztest.h>
7+
#include <kernel.h>
8+
#include <kernel_structs.h>
9+
10+
__kernel struct k_thread kthread_thread;
11+
12+
#define STACKSIZE 1024
13+
K_THREAD_STACK_DEFINE(kthread_stack, STACKSIZE);
14+
K_SEM_DEFINE(sync_sem, 0, 1);
15+
16+
static void thread_entry(void *p1, void *p2, void *p3)
17+
{
18+
_thread_essential_set();
19+
20+
if (_is_thread_essential()) {
21+
k_busy_wait(100);
22+
} else {
23+
zassert_unreachable("The thread is not set as essential\n");
24+
}
25+
26+
_thread_essential_clear();
27+
zassert_false(_is_thread_essential(),
28+
"Essential flag of the thread is not cleared\n");
29+
30+
k_sem_give(&sync_sem);
31+
}
32+
33+
/* The test to validate essential flag set/clear */
34+
void test_essential_thread_operation(void)
35+
{
36+
k_tid_t tid = k_thread_create(&kthread_thread, kthread_stack,
37+
STACKSIZE, (k_thread_entry_t)thread_entry, NULL,
38+
NULL, NULL, K_PRIO_PREEMPT(0), 0, 0);
39+
40+
k_sem_take(&sync_sem, K_FOREVER);
41+
k_thread_abort(tid);
42+
}

0 commit comments

Comments
 (0)