Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
main.c File Reference
#include <ztest.h>
#include <irq_offload.h>
#include <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_STACKSIZE)
 
#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_STACKSIZE))
 
 K_THREAD_STACK_DEFINE (stack_2,(512+CONFIG_TEST_EXTRA_STACKSIZE))
 
 K_THREAD_STACK_DEFINE (stack_3,(512+CONFIG_TEST_EXTRA_STACKSIZE))
 
 K_THREAD_STACK_ARRAY_DEFINE (multiple_stack,(3),(512+CONFIG_TEST_EXTRA_STACKSIZE))
 
void isr_sem_give (const void *semaphore)
 
void isr_sem_take (const void *semaphore)
 
void sem_give_from_isr (void *semaphore)
 
void sem_take_from_isr (void *semaphore)
 
void sem_give_task (void *p1, void *p2, void *p3)
 
void sem_take_timeout_forever_helper (void *p1, void *p2, void *p3)
 
void sem_take_timeout_isr_helper (void *p1, void *p2, void *p3)
 
void sem_take_multiple_low_prio_helper (void *p1, void *p2, void *p3)
 
void sem_take_multiple_mid_prio_helper (void *p1, void *p2, void *p3)
 
void sem_take_multiple_high_prio_helper (void *p1, void *p2, void *p3)
 
void sem_multiple_threads_wait_helper (void *p1, void *p2, void *p3)
 
void test_main (void)
 
void test_basic_sem_test (void)
 
void test_simple_sem_from_isr (void)
 Test semaphore count when given by an ISR. More...
 
void test_simple_sem_from_task (void)
 Test semaphore count when given by thread. More...
 
void test_sem_take_no_wait (void)
 Test if sys_sem_take() decreases semaphore count. More...
 
void test_sem_take_no_wait_fails (void)
 Test sys_sem_take() when there is no semaphore to take. More...
 
void test_sem_take_timeout_fails (void)
 Test sys_sem_take() with timeout expiry. More...
 
void test_sem_take_timeout (void)
 Test sys_sem_take() with timeout. More...
 
void test_sem_take_timeout_forever (void)
 Test sys_sem_take() with forever timeout. More...
 
void test_sem_take_timeout_isr (void)
 Test sys_sem_take() with timeout in ISR context. More...
 
void test_sem_take_multiple (void)
 Test multiple semaphore take. More...
 
void test_sem_give_take_from_isr (void)
 Test semaphore give and take and its count from ISR. More...
 
void test_sem_give_limit (void)
 Test semaphore give limit count. More...
 
void test_sem_multiple_threads_wait (void)
 Test multiple semaphore take and give with wait. More...
 

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_STACKSIZE)

◆ TOTAL_THREADS_WAITING

#define TOTAL_THREADS_WAITING   (3)

Function Documentation

◆ isr_sem_give()

void isr_sem_give ( const void semaphore)

◆ isr_sem_take()

void isr_sem_take ( const void semaphore)

◆ K_THREAD_STACK_ARRAY_DEFINE()

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

◆ K_THREAD_STACK_DEFINE() [1/3]

K_THREAD_STACK_DEFINE ( stack_1  ,
(512+CONFIG_TEST_EXTRA_STACKSIZE)   
)

◆ K_THREAD_STACK_DEFINE() [2/3]

K_THREAD_STACK_DEFINE ( stack_2  ,
(512+CONFIG_TEST_EXTRA_STACKSIZE)   
)

◆ K_THREAD_STACK_DEFINE() [3/3]

K_THREAD_STACK_DEFINE ( stack_3  ,
(512+CONFIG_TEST_EXTRA_STACKSIZE)   
)

◆ sem_give_from_isr()

void sem_give_from_isr ( void semaphore)

◆ sem_give_task()

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

◆ sem_multiple_threads_wait_helper()

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

◆ sem_take_from_isr()

void sem_take_from_isr ( void semaphore)

◆ sem_take_multiple_high_prio_helper()

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

◆ sem_take_multiple_low_prio_helper()

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

◆ sem_take_multiple_mid_prio_helper()

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

◆ sem_take_timeout_forever_helper()

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

◆ sem_take_timeout_isr_helper()

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

◆ SYS_SEM_DEFINE()

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

◆ test_basic_sem_test()

void test_basic_sem_test ( void  )

◆ test_main()

void test_main ( void  )

test case main entry

◆ test_sem_give_limit()

void test_sem_give_limit ( void  )

Test semaphore give limit count.

◆ test_sem_give_take_from_isr()

void test_sem_give_take_from_isr ( void  )

Test semaphore give and take and its count from ISR.

◆ test_sem_multiple_threads_wait()

void test_sem_multiple_threads_wait ( void  )

Test multiple semaphore take and give with wait.

◆ test_sem_take_multiple()

void test_sem_take_multiple ( void  )

Test multiple semaphore take.

◆ test_sem_take_no_wait()

void test_sem_take_no_wait ( void  )

Test if sys_sem_take() decreases semaphore count.

◆ test_sem_take_no_wait_fails()

void test_sem_take_no_wait_fails ( void  )

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

◆ test_sem_take_timeout()

void test_sem_take_timeout ( void  )

Test sys_sem_take() with timeout.

◆ test_sem_take_timeout_fails()

void test_sem_take_timeout_fails ( void  )

Test sys_sem_take() with timeout expiry.

◆ test_sem_take_timeout_forever()

void test_sem_take_timeout_forever ( void  )

Test sys_sem_take() with forever timeout.

◆ test_sem_take_timeout_isr()

void test_sem_take_timeout_isr ( void  )

Test sys_sem_take() with timeout in ISR context.

◆ test_simple_sem_from_isr()

void test_simple_sem_from_isr ( void  )

Test semaphore count when given by an ISR.

◆ test_simple_sem_from_task()

void test_simple_sem_from_task ( void  )

Test semaphore count when given by thread.

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