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

Functions

void test_mutex_recursive (void)
 Test recursive mutex.
 
void test_mutex_priority_inheritance (void)
 Test mutex's priority inheritance mechanism.
 
void test_mutex_timeout_race_during_priority_inversion (void)
 Test fix for subtle race during priority inversion.
 
void test_mutex_init_null (void)
 Test initializing mutex with a NULL pointer.
 
void test_mutex_init_invalid_obj (void)
 Test initialize mutex with a invalid kernel object.
 
void test_mutex_lock_null (void)
 Test locking mutex with a NULL pointer.
 
void test_mutex_lock_invalid_obj (void)
 Test locking mutex with a invalid kernel object.
 
void test_mutex_unlock_null (void)
 Test unlocking mutex with a NULL pointer.
 
void test_mutex_unlock_invalid_obj (void)
 Test unlocking mutex with a invalid kernel object.
 

Detailed Description

Function Documentation

◆ test_mutex_init_invalid_obj()

void test_mutex_init_invalid_obj ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_error_case/src/test_mutex_error.c>

Test initialize mutex with a invalid kernel object.

Pass a invalid kobject as parameter, then see if the expected error happens.

See also
k_mutex_init()

◆ test_mutex_init_null()

void test_mutex_init_null ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_error_case/src/test_mutex_error.c>

Test initializing mutex with a NULL pointer.

Pass a null pointer as parameter, then see if the expected error happens.

See also
k_mutex_init()

◆ test_mutex_lock_invalid_obj()

void test_mutex_lock_invalid_obj ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_error_case/src/test_mutex_error.c>

Test locking mutex with a invalid kernel object.

Pass a invalid kobject as parameter, then see if the expected error happens.

See also
k_mutex_lock()

◆ test_mutex_lock_null()

void test_mutex_lock_null ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_error_case/src/test_mutex_error.c>

Test locking mutex with a NULL pointer.

Pass a null pointer as parameter, then see if the expected error happens.

See also
k_mutex_lock()

◆ test_mutex_priority_inheritance()

void test_mutex_priority_inheritance ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_api/src/test_mutex_apis.c>

Test mutex's priority inheritance mechanism.

To verify mutex provide priority inheritance to prevent priority inversion, and there are 3 cases need to run. The thread T1 hold the mutex first and cases list as below:

  • case 1. When priority T2 > T1, priority inheritance happened.
  • case 2. When priority T1 > T2, priority inheritance won't happened.
  • case 3. When priority T2 > T3 > T1, priority inheritance happened but T2 wait for timeout and T3 got the mutex.

TESTPOINT: run test case 1, given priority T1 < T2

TESTPOINT: The current thread does not own the mutex.

TESTPOINT: run test case 2, given priority T1 > T2, this means priority inheritance won't happen.

TESTPOINT: run test case 3, given priority T1 < T3 < T2, but t2 do not get mutex due to timeout.

◆ test_mutex_recursive()

void test_mutex_recursive ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_api/src/test_mutex_apis.c>

Test recursive mutex.

To verify that getting a lock of a mutex already locked will succeed and waiters will be unblocked only when the number of locks reaches zero.

TESTPOINT: when mutex has no owner, we cannot unlock it

TESTPOINT: lock the mutex recursively

TESTPOINT: unlock the mutex recursively

TESTPOINT: waiter thread got the mutex

◆ test_mutex_timeout_race_during_priority_inversion()

void test_mutex_timeout_race_during_priority_inversion ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_api/src/test_mutex_apis.c>

Test fix for subtle race during priority inversion.

  • A low priority thread (Tlow) locks mutex A.
  • A high priority thread (Thigh) blocks on mutex A, boosting the priority of Tlow.
  • Thigh times out waiting for mutex A.
  • Before Thigh has a chance to execute, Tlow unlocks mutex A (which now has no owner) and drops its own priority.
  • Thigh now gets a chance to execute and finds that it timed out, and then enters the block of code to lower the priority of the thread that owns mutex A (now nobody).
  • Thigh tries to the dereference the owner of mutex A (which is nobody, and thus it is NULL). This leads to an exception.
See also
k_mutex_lock()

◆ test_mutex_unlock_invalid_obj()

void test_mutex_unlock_invalid_obj ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_error_case/src/test_mutex_error.c>

Test unlocking mutex with a invalid kernel object.

Pass a invalid kobject as parameter, then see if the expected error happens.

See also
k_mutex_unlock()

◆ test_mutex_unlock_null()

void test_mutex_unlock_null ( void )

#include </home/runner/work/safety-doc/zephyr/tests/kernel/mutex/mutex_error_case/src/test_mutex_error.c>

Test unlocking mutex with a NULL pointer.

Pass a null pointer as parameter, then see if the expected error happens.

See also
k_mutex_unlock()