Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Threads

Thread Tests . More...

Functions

void test_dyn_thread_perms (void)
 Test object permission on dynamic user thread when index is reused.
 
void test_kernel_create_dyn_user_thread (void)
 Test creation of dynamic user thread under kernel thread.
 
void test_user_create_dyn_user_thread (void)
 Test creation of dynamic user thread under user thread.
 
void test_systhreads_main (void)
 Verify main thread.
 
void test_systhreads_idle (void)
 Verify idle thread.
 
void test_customdata_get_set_coop (void)
 Test thread custom data get/set from coop thread.
 
void test_thread_name_get_set (void)
 Test thread name get/set from supervisor thread.
 
void test_thread_name_user_get_set (void)
 Test thread name get/set from user thread.
 
void test_customdata_get_set_preempt (void)
 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.
 
void test_thread_join (void)
 Test thread join.
 
void test_thread_join_isr (void)
 Test thread join from ISR.
 
void test_thread_join_deadlock (void)
 Test case for thread join deadlock scenarios.
 
void test_thread_timeout_remaining_expires (void)
 Test case for verifying thread timeout expiration and remaining time.
 
void test_thread_runtime_stats_get (void)
 Test case for thread runtime statistics retrieval in Zephyr kernel.
 
void test_k_busy_wait_user (void)
 Test the behavior of k_busy_wait with thread runtime statistics in user mode.
 
void test_k_thread_stack_space_get_user (void)
 Test k_thread_stack_sapce_get.
 
void test_essential_thread_operation (void)
 Test to validate essential flag set/clear.
 
void test_essential_thread_abort (void)
 Abort an essential thread.
 
void test_essential_thread_abort_self (void)
 Abort an essential thread from itself.
 
void test_k_thread_foreach (void)
 Test k_thread_foreach API.
 
void test_k_thread_foreach_unlocked (void)
 Test k_thread_foreach_unlock API.
 
void test_k_thread_foreach_null_cb (void)
 Test k_thread_foreach API with null callback.
 
void test_k_thread_foreach_unlocked_null_cb (void)
 Test k_thread_foreach_unlocked API with null callback.
 
void test_k_thread_state_str (void)
 Test k_thread_state_str API with null callback.
 
void test_threads_abort_self (void)
 Validate aborting a thread when called by current thread.
 
void test_threads_abort_others (void)
 Validate aborting a thread when called by other thread.
 
void test_threads_abort_repeat (void)
 Test abort on an already terminated thread.
 
void test_delayed_thread_abort (void)
 Test abort on delayed thread before it has started execution.
 
void test_abort_from_isr (void)
 Show that threads can be aborted from interrupt context by itself.
 
void test_abort_from_isr_not_self (void)
 Show that threads can be aborted from interrupt context.
 
void test_threads_cpu_mask (void)
 Test the CPU mask APIs for thread lifecycle management.
 
void test_threads_priority_set (void)
 Test setting and verifying thread priorities.
 
void test_isr_threads_priority_set_ (void)
 Test changing thread priorities from an ISR.
 
void test_threads_spawn_params (void)
 Check the parameters passed to thread entry function.
 
void test_threads_spawn_priority (void)
 Spawn thread with higher priority.
 
void test_threads_spawn_delay (void)
 Spawn thread with a delay.
 
void test_threads_spawn_forever (void)
 Spawn thread with forever delay and highest priority.
 
void test_thread_start (void)
 Validate behavior of multiple calls to k_thread_start.
 
void test_threads_suspend_resume_cooperative (void)
 Check the suspend and resume functionality in a cooperative thread.
 
void test_threads_suspend_resume_preemptible (void)
 Check the suspend and resume functionality in preemptive thread.
 
void test_threads_suspend (void)
 Check that suspending a thread is a schedule point when called on the current thread.
 
void test_threads_suspend_timeout (void)
 Check that suspending a thread cancels a preexisting thread timeout.
 
void test_resume_unsuspend_thread (void)
 Check resuming a thread that is not suspended.
 
void test_kdefine_preempt_thread (void)
 test preempt thread initialization via K_THREAD_DEFINE
 
void test_kdefine_coop_thread (void)
 test coop thread initialization via K_THREAD_DEFINE
 
void test_kinit_preempt_thread (void)
 test preempt thread initialization via k_thread_create
 
void test_kinit_coop_thread (void)
 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 </home/runner/work/safety-doc/zephyr/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()

◆ test_abort_from_isr()

void test_abort_from_isr ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_abort_from_isr_not_self()

void test_abort_from_isr_not_self ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_customdata_get_set_coop()

void test_customdata_get_set_coop ( void )

◆ test_customdata_get_set_preempt()

void test_customdata_get_set_preempt ( void )

#include </home/runner/work/safety-doc/zephyr/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

◆ test_delayed_thread_abort()

void test_delayed_thread_abort ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_dyn_thread_perms()

void test_dyn_thread_perms ( void )

#include </home/runner/work/safety-doc/zephyr/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.

◆ test_essential_thread_abort()

void test_essential_thread_abort ( void )

#include </home/runner/work/safety-doc/zephyr/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)

◆ test_essential_thread_abort_self()

void test_essential_thread_abort_self ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_essential_thread.c>

Abort an essential thread from itself.

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)

◆ test_essential_thread_operation()

void test_essential_thread_operation ( void )

◆ test_isr_threads_priority_set_()

void test_isr_threads_priority_set_ ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_threads_set_priority.c>

Test changing thread priorities from an ISR.

This test verifies that thread priorities can be changed correctly when invoked from an interrupt service routine (ISR).

See also
k_thread_priority_set(), k_thread_priority_get()

◆ test_k_busy_wait_user()

void test_k_busy_wait_user ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/main.c>

Test the behavior of k_busy_wait with thread runtime statistics in user mode.

◆ test_k_thread_foreach()

void test_k_thread_foreach ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_k_thread_foreach_null_cb()

void test_k_thread_foreach_null_cb ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_k_thread_foreach_unlocked()

void test_k_thread_foreach_unlocked ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_k_thread_foreach_unlocked_null_cb()

void test_k_thread_foreach_unlocked_null_cb ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_k_thread_stack_space_get_user()

void test_k_thread_stack_space_get_user ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/main.c>

Test k_thread_stack_sapce_get.

Test k_thread_stack_sapce_get unused stack space in large_stack_space() is smaller than that in small_stack() because the former function has a large local variable

◆ test_k_thread_state_str()

void test_k_thread_state_str ( void )

#include </home/runner/work/safety-doc/zephyr/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 initialization 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()

◆ test_kdefine_coop_thread()

void test_kdefine_coop_thread ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_init/src/main.c>

test coop thread initialization via K_THREAD_DEFINE

See also
K_THREAD_DEFINE(x)

◆ test_kdefine_preempt_thread()

void test_kdefine_preempt_thread ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_init/src/main.c>

test preempt thread initialization via K_THREAD_DEFINE

See also
K_THREAD_DEFINE(x)

◆ test_kernel_create_dyn_user_thread()

void test_kernel_create_dyn_user_thread ( void )

#include </home/runner/work/safety-doc/zephyr/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.

◆ test_kinit_coop_thread()

void test_kinit_coop_thread ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_init/src/main.c>

test coop thread initialization via k_thread_create

See also
k_thread_create()

◆ test_kinit_preempt_thread()

void test_kinit_preempt_thread ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_init/src/main.c>

test preempt thread initialization via k_thread_create

See also
k_thread_create()

◆ test_resume_unsuspend_thread()

void test_resume_unsuspend_thread ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_threads_suspend_resume.c>

Check resuming a thread that is not suspended.

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

Verifies requirement
ZEP-SRS-1-4

◆ test_systhreads_idle()

void test_systhreads_idle ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/main.c>

Verify idle thread.

TESTPOINT: check working thread priority should

◆ test_systhreads_main()

void test_systhreads_main ( void )

◆ test_thread_join()

void test_thread_join ( void )

◆ test_thread_join_deadlock()

void test_thread_join_deadlock ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/main.c>

Test case for thread join deadlock scenarios.

This test verifies the behavior of the k_thread_join API in scenarios that could lead to deadlocks. It includes the following checks:

  • Ensures that a thread cannot join itself, which would result in a self-deadlock. The API should return -EDEADLK in this case.
  • Creates two threads (deadlock1_thread and deadlock2_thread) and verifies that they can be joined successfully without causing a deadlock.

◆ test_thread_join_isr()

void test_thread_join_isr ( void )

◆ test_thread_name_get_set()

void test_thread_name_get_set ( void )

◆ test_thread_name_user_get_set()

void test_thread_name_user_get_set ( void )

◆ test_thread_runtime_stats_get()

void test_thread_runtime_stats_get ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/main.c>

Test case for thread runtime statistics retrieval in Zephyr kernel.

This case accumulates every thread's execution_cycles first, then get the total execution_cycles from a global k_thread_runtime_stats_t to see that all time is reflected in the total.

See also
k_thread_runtime_stats_get()

◆ test_thread_start()

void test_thread_start ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_thread_timeout_remaining_expires()

void test_thread_timeout_remaining_expires ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/main.c>

Test case for verifying thread timeout expiration and remaining time.

◆ test_threads_abort_others()

void test_threads_abort_others ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c>

Validate aborting a thread 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

◆ test_threads_abort_repeat()

void test_threads_abort_repeat ( void )

◆ test_threads_abort_self()

void test_threads_abort_self ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c>

Validate aborting a thread 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

◆ test_threads_cpu_mask()

void test_threads_cpu_mask ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_threads_cpu_mask.c>

Test the CPU mask APIs for thread lifecycle management.

This test verifies the behavior of the CPU mask APIs in the Zephyr kernel for thread lifecycle management. It ensures that the APIs behave as expected when operating on both running and non-running threads.

Note
This test is only executed if CONFIG_SCHED_CPU_MASK is enabled. Otherwise, the test is skipped.

◆ test_threads_priority_set()

void test_threads_priority_set ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_threads_set_priority.c>

Test setting and verifying thread priorities.

This test creates a thread with a lower priority than the current thread. It then sets the priority of the thread to a higher value, and checks that the priority has been set correctly.

See also
k_thread_priority_set(), k_thread_priority_get()
Verifies requirement
ZEP-SRS-1-2

◆ test_threads_spawn_delay()

void test_threads_spawn_delay ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_threads_spawn_forever()

void test_threads_spawn_forever ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_threads_spawn_params()

void test_threads_spawn_params ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_threads_spawn_priority()

void test_threads_spawn_priority ( void )

#include </home/runner/work/safety-doc/zephyr/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()

◆ test_threads_suspend()

void test_threads_suspend ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_threads_suspend_resume.c>

Check that suspending a thread is a schedule point when called on the current thread.

Verifies requirement
ZEP-SRS-1-3

◆ test_threads_suspend_resume_cooperative()

void test_threads_suspend_resume_cooperative ( void )

#include </home/runner/work/safety-doc/zephyr/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 get scheduled, and resume and check if the entry function is executed.

See also
k_thread_suspend(), k_thread_resume()
Verifies requirement

ZEP-SRS-1-3

ZEP-SRS-1-4

◆ test_threads_suspend_resume_preemptible()

void test_threads_suspend_resume_preemptible ( void )

#include </home/runner/work/safety-doc/zephyr/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 get scheduled, and resume and check if the entry function is executed.

See also
k_thread_suspend(), k_thread_resume()

◆ test_threads_suspend_timeout()

void test_threads_suspend_timeout ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/threads/thread_apis/src/test_threads_suspend_resume.c>

Check that suspending a thread cancels a preexisting thread timeout.

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

Verifies requirement
ZEP-SRS-1-3

◆ test_user_create_dyn_user_thread()

void test_user_create_dyn_user_thread ( void )

#include </home/runner/work/safety-doc/zephyr/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.