Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
main.c File Reference
#include <zephyr/ztest.h>
#include <zephyr/irq_offload.h>
#include <zephyr/sys/sem.h>

Macros

#define SEM_INIT_VAL   (0U)
 
#define SEM_MAX_VAL   (10U)
 
#define SEM_TIMEOUT   (K_MSEC(100))
 
#define STACK_SIZE   (512 + CONFIG_TEST_EXTRA_STACK_SIZE)
 
#define TOTAL_THREADS_WAITING   (3)
 

Functions

ZTEST_DMEM SYS_SEM_DEFINE (multiple_thread_sem,(0U),(10U))
 
 K_THREAD_STACK_DEFINE (stack_1,(512+CONFIG_TEST_EXTRA_STACK_SIZE))
 
 K_THREAD_STACK_DEFINE (stack_2,(512+CONFIG_TEST_EXTRA_STACK_SIZE))
 
 K_THREAD_STACK_DEFINE (stack_3,(512+CONFIG_TEST_EXTRA_STACK_SIZE))
 
 K_THREAD_STACK_ARRAY_DEFINE (multiple_stack,(3),(512+CONFIG_TEST_EXTRA_STACK_SIZE))
 
static void isr_sem_give (const void *semaphore)
 
static void isr_sem_take (const void *semaphore)
 
static void sem_give_from_isr (void *semaphore)
 
static void sem_take_from_isr (void *semaphore)
 
static void sem_give_task (void *p1, void *p2, void *p3)
 
static void sem_take_timeout_forever_helper (void *p1, void *p2, void *p3)
 
static void sem_take_timeout_isr_helper (void *p1, void *p2, void *p3)
 
static void sem_take_multiple_low_prio_helper (void *p1, void *p2, void *p3)
 
static void sem_take_multiple_mid_prio_helper (void *p1, void *p2, void *p3)
 
static void sem_take_multiple_high_prio_helper (void *p1, void *p2, void *p3)
 
static void sem_multiple_threads_wait_helper (void *p1, void *p2, void *p3)
 
void k_sys_fatal_error_handler (unsigned int reason, const struct arch_esf *pEsf)
 Fatal error policy handler.
 
void * sys_sem_setup (void)
 
 ZTEST_SUITE (sys_sem, NULL, sys_sem_setup, NULL, NULL, NULL)
 
 ZTEST_SUITE (sys_sem_1cpu, NULL, sys_sem_setup, ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL)
 
 ZTEST (sys_sem, test_basic_sem_test)
 
 ZTEST (sys_sem, test_simple_sem_from_isr)
 Test semaphore count when given by an ISR.
 
 ZTEST_USER (sys_sem, test_simple_sem_from_task)
 Test semaphore count when given by thread.
 
 ZTEST_USER (sys_sem, test_sem_take_no_wait)
 Test if sys_sem_take() decreases semaphore count.
 
 ZTEST_USER (sys_sem, test_sem_take_no_wait_fails)
 Test sys_sem_take() when there is no semaphore to take.
 
 ZTEST_USER (sys_sem_1cpu, test_sem_take_timeout_fails)
 Test sys_sem_take() with timeout expiry.
 
 ZTEST_USER (sys_sem, test_sem_take_timeout)
 Test sys_sem_take() with timeout.
 
 ZTEST_USER (sys_sem_1cpu, test_sem_take_timeout_forever)
 Test sys_sem_take() with forever timeout.
 
 ZTEST (sys_sem_1cpu, test_sem_take_timeout_isr)
 Test sys_sem_take() with timeout in ISR context.
 
 ZTEST_USER (sys_sem_1cpu, test_sem_take_multiple)
 Test multiple semaphore take.
 
 ZTEST (sys_sem, test_sem_give_take_from_isr)
 Test semaphore give and take and its count from ISR.
 
 ZTEST_USER (sys_sem, test_sem_give_limit)
 Test semaphore give limit count.
 
 ZTEST_USER (sys_sem_1cpu, test_sem_multiple_threads_wait)
 Test multiple semaphore take and give with wait.
 

Variables

ZTEST_BMEM struct sys_sem simple_sem
 
ZTEST_BMEM struct sys_sem low_prio_sem
 
ZTEST_BMEM struct sys_sem mid_prio_sem
 
ZTEST_DMEM struct sys_sem high_prio_sem
 
struct k_thread sem_tid sem_tid_1 sem_tid_2
 
struct k_thread multiple_tid [(3)]
 

Macro Definition Documentation

◆ SEM_INIT_VAL

#define SEM_INIT_VAL   (0U)

◆ SEM_MAX_VAL

#define SEM_MAX_VAL   (10U)

◆ SEM_TIMEOUT

#define SEM_TIMEOUT   (K_MSEC(100))

◆ STACK_SIZE

#define STACK_SIZE   (512 + CONFIG_TEST_EXTRA_STACK_SIZE)

◆ TOTAL_THREADS_WAITING

#define TOTAL_THREADS_WAITING   (3)

Function Documentation

◆ isr_sem_give()

static void isr_sem_give ( const void *  semaphore)
static

◆ isr_sem_take()

static void isr_sem_take ( const void *  semaphore)
static

◆ K_THREAD_STACK_ARRAY_DEFINE()

K_THREAD_STACK_ARRAY_DEFINE ( multiple_stack  ,
(3)  ,
(512+CONFIG_TEST_EXTRA_STACK_SIZE)   
)

◆ K_THREAD_STACK_DEFINE() [1/3]

K_THREAD_STACK_DEFINE ( stack_1  ,
(512+CONFIG_TEST_EXTRA_STACK_SIZE)   
)

◆ K_THREAD_STACK_DEFINE() [2/3]

K_THREAD_STACK_DEFINE ( stack_2  ,
(512+CONFIG_TEST_EXTRA_STACK_SIZE)   
)

◆ K_THREAD_STACK_DEFINE() [3/3]

K_THREAD_STACK_DEFINE ( stack_3  ,
(512+CONFIG_TEST_EXTRA_STACK_SIZE)   
)

◆ sem_give_from_isr()

static void sem_give_from_isr ( void *  semaphore)
static

◆ sem_give_task()

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

◆ sem_multiple_threads_wait_helper()

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

◆ sem_take_from_isr()

static void sem_take_from_isr ( void *  semaphore)
static

◆ sem_take_multiple_high_prio_helper()

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

◆ sem_take_multiple_low_prio_helper()

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

◆ sem_take_multiple_mid_prio_helper()

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

◆ sem_take_timeout_forever_helper()

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

◆ sem_take_timeout_isr_helper()

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

◆ SYS_SEM_DEFINE()

ZTEST_DMEM SYS_SEM_DEFINE ( multiple_thread_sem  ,
(0U)  ,
(10U)   
)

◆ sys_sem_setup()

void * sys_sem_setup ( void  )

◆ ZTEST() [1/4]

ZTEST ( sys_sem  ,
test_basic_sem_test   
)

◆ ZTEST() [2/4]

ZTEST ( sys_sem  ,
test_sem_give_take_from_isr   
)

Test semaphore give and take and its count from ISR.

◆ ZTEST() [3/4]

ZTEST ( sys_sem  ,
test_simple_sem_from_isr   
)

Test semaphore count when given by an ISR.

◆ ZTEST() [4/4]

ZTEST ( sys_sem_1cpu  ,
test_sem_take_timeout_isr   
)

Test sys_sem_take() with timeout in ISR context.

◆ ZTEST_SUITE() [1/2]

ZTEST_SUITE ( sys_sem  ,
NULL  ,
sys_sem_setup  ,
NULL  ,
NULL  ,
NULL   
)

◆ ZTEST_SUITE() [2/2]

ZTEST_SUITE ( sys_sem_1cpu  ,
NULL  ,
sys_sem_setup  ,
ztest_simple_1cpu_before  ,
ztest_simple_1cpu_after  ,
NULL   
)

◆ ZTEST_USER() [1/9]

ZTEST_USER ( sys_sem  ,
test_sem_give_limit   
)

Test semaphore give limit count.

◆ ZTEST_USER() [2/9]

ZTEST_USER ( sys_sem  ,
test_sem_take_no_wait   
)

Test if sys_sem_take() decreases semaphore count.

◆ ZTEST_USER() [3/9]

ZTEST_USER ( sys_sem  ,
test_sem_take_no_wait_fails   
)

Test sys_sem_take() when there is no semaphore to take.

◆ ZTEST_USER() [4/9]

ZTEST_USER ( sys_sem  ,
test_sem_take_timeout   
)

Test sys_sem_take() with timeout.

◆ ZTEST_USER() [5/9]

ZTEST_USER ( sys_sem  ,
test_simple_sem_from_task   
)

Test semaphore count when given by thread.

◆ ZTEST_USER() [6/9]

ZTEST_USER ( sys_sem_1cpu  ,
test_sem_multiple_threads_wait   
)

Test multiple semaphore take and give with wait.

◆ ZTEST_USER() [7/9]

ZTEST_USER ( sys_sem_1cpu  ,
test_sem_take_multiple   
)

Test multiple semaphore take.

◆ ZTEST_USER() [8/9]

ZTEST_USER ( sys_sem_1cpu  ,
test_sem_take_timeout_fails   
)

Test sys_sem_take() with timeout expiry.

◆ ZTEST_USER() [9/9]

ZTEST_USER ( sys_sem_1cpu  ,
test_sem_take_timeout_forever   
)

Test sys_sem_take() with forever timeout.

Variable Documentation

◆ high_prio_sem

ZTEST_DMEM struct sys_sem high_prio_sem

◆ low_prio_sem

ZTEST_BMEM struct sys_sem low_prio_sem

◆ mid_prio_sem

ZTEST_BMEM struct sys_sem mid_prio_sem

◆ multiple_tid

struct k_thread multiple_tid[(3)]

◆ sem_tid_2

struct k_thread sem_tid sem_tid_1 sem_tid_2

◆ simple_sem

ZTEST_BMEM struct sys_sem simple_sem