Zephyr Project API 3.7.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Threads

Thread Tests. More...

Functions

 ZTEST (thread_dynamic, test_dyn_thread_perms)
 Test object permission on dynamic user thread when index is reused.
 
 ZTEST (thread_dynamic, test_kernel_create_dyn_user_thread)
 Test creation of dynamic user thread under kernel thread.
 
 ZTEST_USER (thread_dynamic, test_user_create_dyn_user_thread)
 Test creation of dynamic user thread under user thread.
 
 ZTEST (threads_lifecycle, test_systhreads_main)
 Verify main thread.
 
 ZTEST (threads_lifecycle, test_systhreads_idle)
 Verify idle thread.
 
 ZTEST (threads_lifecycle_1cpu, test_customdata_get_set_coop)
 test thread custom data get/set from coop thread
 
 ZTEST (threads_lifecycle, test_thread_name_get_set)
 test thread name get/set from supervisor thread
 
 ZTEST_USER (threads_lifecycle, test_thread_name_user_get_set)
 test thread name get/set from user thread
 
 ZTEST_USER (threads_lifecycle_1cpu, test_customdata_get_set_preempt)
 test thread custom data get/set from preempt thread
 
static void enter_user_mode_entry (void *p1, void *p2, void *p3)
 Test k_thread_user_mode_enter() to cover when userspace is not supported/enabled.
 
 ZTEST (threads_lifecycle, test_essential_thread_operation)
 Test to validate essential flag set/clear.
 
 ZTEST (threads_lifecycle, test_essential_thread_abort)
 Abort an essential thread.
 
 ZTEST (threads_lifecycle_1cpu, test_k_thread_foreach)
 Test k_thread_foreach API.
 
 ZTEST (threads_lifecycle_1cpu, test_k_thread_foreach_unlocked)
 Test k_thread_foreach_unlock API.
 
 ZTEST (threads_lifecycle_1cpu, test_k_thread_foreach_null_cb)
 Test k_thread_foreach API with null callback.
 
 ZTEST (threads_lifecycle_1cpu, test_k_thread_foreach_unlocked_null_cb)
 Test k_thread_foreach_unlocked API with null callback.
 
 ZTEST (threads_lifecycle_1cpu, test_k_thread_state_str)
 Test k_thread_state_str API with null callback.
 
 ZTEST_USER (threads_lifecycle, test_threads_abort_self)
 Validate k_thread_abort() when called by current thread.
 
 ZTEST_USER (threads_lifecycle, test_threads_abort_others)
 Validate k_thread_abort() when called by other thread.
 
 ZTEST (threads_lifecycle_1cpu, test_threads_abort_repeat)
 Test abort on a terminated thread.
 
 ZTEST (threads_lifecycle_1cpu, test_delayed_thread_abort)
 Test abort on delayed thread before it has started execution.
 
 ZTEST (threads_lifecycle, test_abort_from_isr)
 Show that threads can be aborted from interrupt context by itself.
 
 ZTEST (threads_lifecycle, test_abort_from_isr_not_self)
 Show that threads can be aborted from interrupt context.
 
 ZTEST (threads_lifecycle, test_threads_priority_set)
 Test the k_thread_priority_set() API.
 
 ZTEST_USER (threads_lifecycle, test_threads_spawn_params)
 Check the parameters passed to thread entry function.
 
 ZTEST (threads_lifecycle, test_threads_spawn_priority)
 Spawn thread with higher priority.
 
 ZTEST_USER (threads_lifecycle, test_threads_spawn_delay)
 Spawn thread with a delay.
 
 ZTEST (threads_lifecycle, test_threads_spawn_forever)
 Spawn thread with forever delay and highest priority.
 
 ZTEST (threads_lifecycle, test_thread_start)
 Validate behavior of multiple calls to k_thread_start()
 
 ZTEST (threads_lifecycle_1cpu, test_threads_suspend_resume_cooperative)
 Check the suspend and resume functionality in a cooperative thread.
 
 ZTEST_USER (threads_lifecycle, test_threads_suspend_resume_preemptible)
 Check the suspend and resume functionality in preemptive thread.
 
 ZTEST (threads_lifecycle, test_threads_suspend)
 Check that k_thread_suspend() is a schedule point when called on the current thread.
 
 ZTEST (threads_lifecycle, test_threads_suspend_timeout)
 Check that k_thread_suspend() cancels a preexisting thread timeout.
 
 ZTEST (threads_lifecycle, test_resume_unsuspend_thread)
 Check resume an unsuspend thread.
 
 ZTEST_USER (thread_init, test_kdefine_preempt_thread)
 test preempt thread initialization via K_THREAD_DEFINE
 
 ZTEST_USER (thread_init, test_kdefine_coop_thread)
 test coop thread initialization via K_THREAD_DEFINE
 
 ZTEST_USER (thread_init, test_kinit_preempt_thread)
 test preempt thread initialization via k_thread_create
 
 ZTEST (thread_init, test_kinit_coop_thread)
 test coop thread initialization via k_thread_create
 

Detailed Description

Thread Tests.

Function Documentation

◆ enter_user_mode_entry()

static void enter_user_mode_entry ( void *  p1,
void *  p2,
void *  p3 
)
static

#include <tests/kernel/threads/thread_apis/src/main.c>

Test k_thread_user_mode_enter() to cover when userspace is not supported/enabled.

See also
k_thread_user_mode_enter()

◆ ZTEST() [1/26]

ZTEST ( thread_dynamic  ,
test_dyn_thread_perms   
)

#include <tests/kernel/threads/dynamic_thread/src/main.c>

Test object permission on dynamic user thread when index is reused.

This creates one dynamic thread with permissions to both semaphores so there is no fault. Then a new thread is created and will be re-using the thread index in first pass. Except the second thread does not have permission to one of the semaphore. If permissions are cleared correctly when thread is destroyed, the second should raise kernel oops.

◆ ZTEST() [2/26]

ZTEST ( thread_dynamic  ,
test_kernel_create_dyn_user_thread   
)

#include <tests/kernel/threads/dynamic_thread/src/main.c>

Test creation of dynamic user thread under kernel thread.

This is a simple test to create a user thread dynamically via k_object_alloc() under a kernel thread.

◆ ZTEST() [3/26]

ZTEST ( thread_init  ,
test_kinit_coop_thread   
)

#include <tests/kernel/threads/thread_init/src/main.c>

test coop thread initialization via k_thread_create

See also
k_thread_create()

◆ ZTEST() [4/26]

ZTEST ( threads_lifecycle  ,
test_abort_from_isr   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c>

Show that threads can be aborted from interrupt context by itself.

Spwan a thread, then enter ISR context in child thread and abort the child thread. Check if ISR completed and target thread was aborted.

See also
k_thread_abort()

◆ ZTEST() [5/26]

ZTEST ( threads_lifecycle  ,
test_abort_from_isr_not_self   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c>

Show that threads can be aborted from interrupt context.

Spwan a thread, then enter ISR context in main thread and abort the child thread. Check if ISR completed and target thread was aborted.

See also
k_thread_abort()

◆ ZTEST() [6/26]

ZTEST ( threads_lifecycle  ,
test_essential_thread_abort   
)

#include <tests/kernel/threads/thread_apis/src/test_essential_thread.c>

Abort an essential thread.

The kernel shall raise a fatal system error if an essential thread aborts, implement k_sys_fatal_error_handler to handle this error.

See also
K_ESSENTIAL(x)

◆ ZTEST() [7/26]

ZTEST ( threads_lifecycle  ,
test_essential_thread_operation   
)

#include <tests/kernel/threads/thread_apis/src/test_essential_thread.c>

Test to validate essential flag set/clear.

See also
K_ESSENTIAL(x)

◆ ZTEST() [8/26]

ZTEST ( threads_lifecycle  ,
test_resume_unsuspend_thread   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_suspend_resume.c>

Check resume an unsuspend thread.

Use k_thread_state_str() to get thread state. Resume an unsuspend thread will not change the thread state.

◆ ZTEST() [9/26]

ZTEST ( threads_lifecycle  ,
test_systhreads_idle   
)

#include <tests/kernel/threads/thread_apis/src/main.c>

Verify idle thread.

TESTPOINT: check working thread priority should

◆ ZTEST() [10/26]

ZTEST ( threads_lifecycle  ,
test_systhreads_main   
)

#include <tests/kernel/threads/thread_apis/src/main.c>

Verify main thread.

◆ ZTEST() [11/26]

ZTEST ( threads_lifecycle  ,
test_thread_name_get_set   
)

#include <tests/kernel/threads/thread_apis/src/main.c>

test thread name get/set from supervisor thread

See also
k_thread_name_get(), k_thread_name_copy(), k_thread_name_set()

◆ ZTEST() [12/26]

ZTEST ( threads_lifecycle  ,
test_thread_start   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_spawn.c>

Validate behavior of multiple calls to k_thread_start()

Call k_thread_start() on an already terminated thread

See also
k_thread_start()

◆ ZTEST() [13/26]

ZTEST ( threads_lifecycle  ,
test_threads_priority_set   
)

◆ ZTEST() [14/26]

ZTEST ( threads_lifecycle  ,
test_threads_spawn_forever   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_spawn.c>

Spawn thread with forever delay and highest priority.

Create an user thread with forever delay and yield the current thread. Even though the current thread has yielded, the thread will not be put in ready queue since it has forever delay, the thread is explicitly started using k_thread_start() and checked if thread has started executing.

See also
k_thread_create()

◆ ZTEST() [15/26]

ZTEST ( threads_lifecycle  ,
test_threads_spawn_priority   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_spawn.c>

Spawn thread with higher priority.

Create an user thread with priority greater than current thread and check its behavior.

See also
k_thread_create()

◆ ZTEST() [16/26]

ZTEST ( threads_lifecycle  ,
test_threads_suspend   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_suspend_resume.c>

Check that k_thread_suspend() is a schedule point when called on the current thread.

◆ ZTEST() [17/26]

ZTEST ( threads_lifecycle  ,
test_threads_suspend_timeout   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_suspend_resume.c>

Check that k_thread_suspend() cancels a preexisting thread timeout.

Suspended threads should not wake up unexpectedly if they happened to have been sleeping when suspended.

◆ ZTEST() [18/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_customdata_get_set_coop   
)

#include <tests/kernel/threads/thread_apis/src/main.c>

test thread custom data get/set from coop thread

See also
k_thread_custom_data_get(), k_thread_custom_data_set()

◆ ZTEST() [19/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_delayed_thread_abort   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c>

Test abort on delayed thread before it has started execution.

See also
k_thread_abort()

◆ ZTEST() [20/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_k_thread_foreach   
)

#include <tests/kernel/threads/thread_apis/src/test_kthread_for_each.c>

Test k_thread_foreach API.

Call k_thread_foreach() at the beginning of the test and call it again after creating a thread, See k_thread_foreach() iterates over the newly created thread and calls the user passed callback function.

See also
k_thread_foreach()

◆ ZTEST() [21/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_k_thread_foreach_null_cb   
)

#include <tests/kernel/threads/thread_apis/src/test_kthread_for_each.c>

Test k_thread_foreach API with null callback.

Call k_thread_foreach() with null callback will trigger __ASSERT() and this test thread will be aborted by z_fatal_error()

See also
k_thread_foreach()

◆ ZTEST() [22/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_k_thread_foreach_unlocked   
)

#include <tests/kernel/threads/thread_apis/src/test_kthread_for_each.c>

Test k_thread_foreach_unlock API.

Call k_thread_foreach_unlocked() at the beginning of the test and call it again after creating a thread, See k_thread_foreach_unlocked() iterates over the newly created thread and calls the user passed callback function. In contrast to k_thread_foreach(), k_thread_foreach_unlocked() allow callback function created or abort threads

See also
k_thread_foreach_unlocked()

◆ ZTEST() [23/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_k_thread_foreach_unlocked_null_cb   
)

#include <tests/kernel/threads/thread_apis/src/test_kthread_for_each.c>

Test k_thread_foreach_unlocked API with null callback.

Call k_thread_foreach_unlocked() with null callback will trigger __ASSERT() and this test thread will be aborted by z_fatal_error()

See also
k_thread_foreach_unlocked()

◆ ZTEST() [24/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_k_thread_state_str   
)

#include <tests/kernel/threads/thread_apis/src/test_kthread_for_each.c>

Test k_thread_state_str API with null callback.

It's impossible to sched a thread step by step manually to experience each state from _THREAD_PRESTART to _THREAD_DEAD. To cover each line of function k_thread_state_str(), set thread_state of tdata1 and check the string this function returns

See also
k_thread_state_str()

◆ ZTEST() [25/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_threads_abort_repeat   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c>

Test abort on a terminated thread.

See also
k_thread_abort()

◆ ZTEST() [26/26]

ZTEST ( threads_lifecycle_1cpu  ,
test_threads_suspend_resume_cooperative   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_suspend_resume.c>

Check the suspend and resume functionality in a cooperative thread.

Create a thread with the priority lower than the current thread which is cooperative and suspend it, make sure it doesn't gets scheduled, and resume and check if the entry function is executed.

See also
k_thread_suspend(), k_thread_resume()

◆ ZTEST_USER() [1/11]

ZTEST_USER ( thread_dynamic  ,
test_user_create_dyn_user_thread   
)

#include <tests/kernel/threads/dynamic_thread/src/main.c>

Test creation of dynamic user thread under user thread.

This is a simple test to create a user thread dynamically via k_object_alloc() under a user thread.

◆ ZTEST_USER() [2/11]

ZTEST_USER ( thread_init  ,
test_kdefine_coop_thread   
)

#include <tests/kernel/threads/thread_init/src/main.c>

test coop thread initialization via K_THREAD_DEFINE

See also
K_THREAD_DEFINE(x)

◆ ZTEST_USER() [3/11]

ZTEST_USER ( thread_init  ,
test_kdefine_preempt_thread   
)

#include <tests/kernel/threads/thread_init/src/main.c>

test preempt thread initialization via K_THREAD_DEFINE

See also
K_THREAD_DEFINE(x)

◆ ZTEST_USER() [4/11]

ZTEST_USER ( thread_init  ,
test_kinit_preempt_thread   
)

#include <tests/kernel/threads/thread_init/src/main.c>

test preempt thread initialization via k_thread_create

See also
k_thread_create()

◆ ZTEST_USER() [5/11]

ZTEST_USER ( threads_lifecycle  ,
test_thread_name_user_get_set   
)

#include <tests/kernel/threads/thread_apis/src/main.c>

test thread name get/set from user thread

See also
k_thread_name_copy(), k_thread_name_set()

◆ ZTEST_USER() [6/11]

ZTEST_USER ( threads_lifecycle  ,
test_threads_abort_others   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c>

Validate k_thread_abort() when called by other thread.

Create a user thread and abort the thread before its execution. Create a another user thread and abort the thread after it has started.

See also
k_thread_abort()

TESTPOINT: check not-started thread is aborted

TESTPOINT: check running thread is aborted

◆ ZTEST_USER() [7/11]

ZTEST_USER ( threads_lifecycle  ,
test_threads_abort_self   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c>

Validate k_thread_abort() when called by current thread.

Create a user thread and let the thread execute. Then call k_thread_abort() and check if the thread is terminated. Here the main thread is also a user thread.

See also
k_thread_abort()

TESTPOINT: spawned thread executed but abort itself

◆ ZTEST_USER() [8/11]

ZTEST_USER ( threads_lifecycle  ,
test_threads_spawn_delay   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_spawn.c>

Spawn thread with a delay.

Create a user thread with delay and check if the thread entry function is executed only after the timeout occurs.

See also
k_thread_create()

◆ ZTEST_USER() [9/11]

ZTEST_USER ( threads_lifecycle  ,
test_threads_spawn_params   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_spawn.c>

Check the parameters passed to thread entry function.

Create an user thread and pass 2 variables and a semaphore to a thread entry function. Check for the correctness of the parameters passed.

See also
k_thread_create()

◆ ZTEST_USER() [10/11]

ZTEST_USER ( threads_lifecycle  ,
test_threads_suspend_resume_preemptible   
)

#include <tests/kernel/threads/thread_apis/src/test_threads_suspend_resume.c>

Check the suspend and resume functionality in preemptive thread.

Create a thread with the priority lower than the current thread which is preemptive and suspend it, make sure it doesn't gets scheduled, and resume and check if the entry function is executed.

See also
k_thread_suspend(), k_thread_resume()

◆ ZTEST_USER() [11/11]

ZTEST_USER ( threads_lifecycle_1cpu  ,
test_customdata_get_set_preempt   
)

#include <tests/kernel/threads/thread_apis/src/main.c>

test thread custom data get/set from preempt thread

See also
k_thread_custom_data_get(), k_thread_custom_data_set()

TESTPOINT: custom data of preempt thread