|
Zephyr Project API 3.7.2
A Scalable Open Source RTOS
|
Test complex mutex priority inversion. More...
#include <zephyr/tc_util.h>#include <zephyr/kernel.h>#include <zephyr/ztest.h>#include <zephyr/sys/mutex.h>Macros | |
| #define | STACKSIZE (512 + CONFIG_TEST_EXTRA_STACK_SIZE) |
| #define | PARTICIPANT_THREAD_OPTIONS (K_INHERIT_PERMS) |
| #define | DEFINE_PARTICIPANT_THREAD(id) |
| #define | CREATE_PARTICIPANT_THREAD(id, pri) |
| #define | START_PARTICIPANT_THREAD(id) k_thread_start(&(thread_##id##_thread_data)); |
| #define | JOIN_PARTICIPANT_THREAD(id) k_thread_join(&(thread_##id##_thread_data), K_FOREVER); |
| #define | WAIT_FOR_MAIN() |
| #define | ADVANCE_THREAD(id) |
| #define | SIGNAL_THREAD(id) k_sem_give(&thread_##id##_wait); |
| #define | WAIT_FOR_THREAD(id) zassert_ok(k_sem_take(&thread_##id##_done, K_MSEC(100))); |
Functions | |
| static | K_MUTEX_DEFINE (mutex_0) |
| static | K_MUTEX_DEFINE (mutex_1) |
| static void | thread_05 (struct k_sem *wait, struct k_sem *done) |
| thread_05 - | |
| static void | thread_06 (struct k_sem *wait, struct k_sem *done) |
| thread_06 - | |
| static void | thread_07 (struct k_sem *wait, struct k_sem *done) |
| thread_07 - | |
| static void | thread_08 (struct k_sem *wait, struct k_sem *done) |
| thread_08 - | |
| static | K_THREAD_STACK_DEFINE (thread_05_stack_area,(512+CONFIG_TEST_EXTRA_STACK_SIZE)) |
| static | K_SEM_DEFINE (thread_05_wait, 0, 1) |
| static | K_SEM_DEFINE (thread_05_done, 0, 1) |
| static | K_THREAD_STACK_DEFINE (thread_06_stack_area,(512+CONFIG_TEST_EXTRA_STACK_SIZE)) |
| static | K_SEM_DEFINE (thread_06_wait, 0, 1) |
| static | K_SEM_DEFINE (thread_06_done, 0, 1) |
| static | K_THREAD_STACK_DEFINE (thread_07_stack_area,(512+CONFIG_TEST_EXTRA_STACK_SIZE)) |
| static | K_SEM_DEFINE (thread_07_wait, 0, 1) |
| static | K_SEM_DEFINE (thread_07_done, 0, 1) |
| static | K_THREAD_STACK_DEFINE (thread_08_stack_area,(512+CONFIG_TEST_EXTRA_STACK_SIZE)) |
| static | K_SEM_DEFINE (thread_08_wait, 0, 1) |
| static | K_SEM_DEFINE (thread_08_done, 0, 1) |
| static void | create_participant_threads (void) |
| static void | start_participant_threads (void) |
| static void | join_participant_threads (void) |
| ZTEST (mutex_api, test_complex_inversion) | |
| Main thread to test mutex locking. | |
Variables | |
| static ZTEST_DMEM int | tc_rc = TC_PASS |
| static struct k_thread | thread_05_thread_data |
| static k_tid_t | thread_05_tid |
| static struct k_thread | thread_06_thread_data |
| static k_tid_t | thread_06_tid |
| static struct k_thread | thread_07_thread_data |
| static k_tid_t | thread_07_tid |
| static struct k_thread | thread_08_thread_data |
| static k_tid_t | thread_08_tid |
Test complex mutex priority inversion.
This module demonstrates the kernel's priority inheritance algorithm with two mutexes and four threads, ensuring that boosting priority of a thread waiting on another mutex does not break assumptions of the mutex's waitq, causing the incorrect thread to run or a crash.
Sequence for priority inheritance testing:
| #define ADVANCE_THREAD | ( | id | ) |
| #define CREATE_PARTICIPANT_THREAD | ( | id, | |
| pri | |||
| ) |
| #define DEFINE_PARTICIPANT_THREAD | ( | id | ) |
| #define JOIN_PARTICIPANT_THREAD | ( | id | ) | k_thread_join(&(thread_##id##_thread_data), K_FOREVER); |
| #define PARTICIPANT_THREAD_OPTIONS (K_INHERIT_PERMS) |
| #define SIGNAL_THREAD | ( | id | ) | k_sem_give(&thread_##id##_wait); |
| #define STACKSIZE (512 + CONFIG_TEST_EXTRA_STACK_SIZE) |
| #define START_PARTICIPANT_THREAD | ( | id | ) | k_thread_start(&(thread_##id##_thread_data)); |
| #define WAIT_FOR_MAIN | ( | ) |
| #define WAIT_FOR_THREAD | ( | id | ) | zassert_ok(k_sem_take(&thread_##id##_done, K_MSEC(100))); |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
thread_05 -
|
static |
thread_06 -
|
static |
thread_07 -
|
static |
thread_08 -
| ZTEST | ( | mutex_api | , |
| test_complex_inversion | |||
| ) |
Main thread to test mutex locking.
This thread orchestrates mutex locking on other threads and verifies that the correct thread is holding mutexes at any given step.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |