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

Functions

void test_sem_multiple_threads_wait (void)
 Test multiple semaphore take and give with wait.
 
void test_sem_measure_timeouts (void)
 Test semaphore timeout period.
 
void test_sem_measure_timeout_from_thread (void)
 Test timeout of semaphore from thread.
 
void test_sem_multiple_take_and_timeouts (void)
 Test multiple semaphore take with timeouts.
 
void test_sem_multi_take_timeout_diff_sem (void)
 Test sequence of multiple semaphore timeouts.
 
void test_sem_queue_mutual_exclusion (void)
 Test thread mutual exclusion by semaphore.
 
void test_sem_give_null (void)
 Test k_sem_give() API.
 
void test_sem_init_null (void)
 Test k_sem_init() API.
 
void test_sem_take_null (void)
 Test k_sem_take() API.
 
void test_sem_reset_null (void)
 Test k_sem_reset() API.
 
void test_sem_count_get_null (void)
 Test k_sem_count_get() API.
 
void test_multiple_thread_sem_usage (void)
 Test semaphore usage with multiple thread.
 
void test_multi_thread_sem_limit (void)
 Test max semaphore can be give and take with multiple thread.
 
void test_basic_sem_test (void)
 
void test_simple_sem_from_isr (void)
 Test semaphore count when given by an ISR.
 
void test_simple_sem_from_task (void)
 Test semaphore count when given by thread.
 
void test_sem_take_no_wait (void)
 Test if sys_sem_take() decreases semaphore count.
 
void test_sem_take_no_wait_fails (void)
 Test sys_sem_take() when there is no semaphore to take.
 
void test_sem_take_timeout_isr (void)
 Test sys_sem_take() with timeout in ISR context.
 
void test_sem_give_take_from_isr (void)
 Test semaphore give and take and its count from ISR.
 
void test_sem_give_limit (void)
 Test semaphore give limit count.
 
void test_k_sem_define (void)
 Test semaphore defined at compile time.
 
void test_k_sem_init (void)
 Test semaphore initialization at runtime.
 
void test_sem_give_from_isr (void)
 Test whether a semaphore can be given by an ISR.
 
void test_sem_give_from_thread (void)
 Test semaphore count when given by thread.
 
void test_sem_take_timeout_fails (void)
 Test a semaphore take operation with an unavailable semaphore.
 
void test_sem_take_timeout (void)
 Test the semaphore take operation with specified timeout.
 
void test_sem_take_timeout_forever (void)
 Test the semaphore take operation with forever wait.
 
void test_sem_take_multiple (void)
 Test semaphore take operation by multiple threads.
 
void test_k_sem_correct_count_limit (void)
 Test the max value a semaphore can be given and taken.
 
void test_sem_thread2thread (void)
 Test synchronization of threads with semaphore.
 
void test_sem_thread2isr (void)
 Test synchronization between thread and irq.
 
void test_sem_reset (void)
 Test k_sem_reset() API.
 
void test_sem_reset_waiting (void)
 
void test_sem_count_get (void)
 Test k_sem_count_get() API.
 

Detailed Description

Function Documentation

◆ test_basic_sem_test()

◆ test_k_sem_correct_count_limit()

void test_k_sem_correct_count_limit ( void )

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

Test the max value a semaphore can be given and taken.

  • Reset an initialized semaphore's count to zero.
  • Give the semaphore by a thread and verify the semaphore's count is as expected.
  • Verify the max count a semaphore can reach.
  • Take the semaphore by a thread and verify the semaphore's count is as expected.
  • Verify the max times a semaphore can be taken.
See also
k_sem_count_get(), k_sem_give()

◆ test_k_sem_define()

void test_k_sem_define ( void )

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

Test semaphore defined at compile time.

  • Get the semaphore count.
  • Verify the semaphore count equals to initialized value.
See also
k_sem_count_get()

◆ test_k_sem_init()

void test_k_sem_init ( void )

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

Test semaphore initialization at runtime.

  • Initialize a semaphore with valid count and max limit.
  • Initialize a semaphore with invalid max limit.
  • Initialize a semaphore with invalid count.

◆ test_multi_thread_sem_limit()

void test_multi_thread_sem_limit ( void )

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

Test max semaphore can be give and take with multiple thread.

  • Define and initialize semaphore and thread.
  • Give sem by multiple threads.
  • Verify more than max count about semaphore can reach.
  • Take sem by multiple threads and verify if sem count is correct.

◆ test_multiple_thread_sem_usage()

void test_multiple_thread_sem_usage ( void )

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

Test semaphore usage with multiple thread.

Using semaphore with some situations

  • Use a uninitialized semaphore
  • Use semaphore normally
  • Use semaphore with different priority threads

◆ test_sem_count_get()

void test_sem_count_get ( void )

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

Test k_sem_count_get() API.

See also
k_sem_count_get()

TESTPOINT: semaphore count get upon init

TESTPOINT: sem count get after give

TESTPOINT: sem count get after take

TESTPOINT: semaphore give above limit

◆ test_sem_count_get_null()

void test_sem_count_get_null ( void )

◆ test_sem_give_from_isr()

void test_sem_give_from_isr ( void )

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

Test whether a semaphore can be given by an ISR.

  • Reset an initialized semaphore's count to zero
  • Create a loop, in each loop, do follow steps
  • Give the semaphore from an ISR
  • Get the semaphore's count
  • Verify whether the semaphore's count as expected
See also
k_sem_give()

◆ test_sem_give_from_thread()

void test_sem_give_from_thread ( void )

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

Test semaphore count when given by thread.

  • Reset an initialized semaphore's count to zero
  • Create a loop, in each loop, do follow steps
  • Give the semaphore from a thread
  • Get the semaphore's count
  • Verify whether the semaphore's count as expected
See also
k_sem_give()

◆ test_sem_give_limit()

void test_sem_give_limit ( void )

◆ test_sem_give_null()

void test_sem_give_null ( void )

◆ test_sem_give_take_from_isr()

void test_sem_give_take_from_isr ( void )

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

Test semaphore give and take and its count from ISR.

◆ test_sem_init_null()

void test_sem_init_null ( void )

◆ test_sem_measure_timeout_from_thread()

void test_sem_measure_timeout_from_thread ( void )

◆ test_sem_measure_timeouts()

void test_sem_measure_timeouts ( void )

◆ test_sem_multi_take_timeout_diff_sem()

void test_sem_multi_take_timeout_diff_sem ( void )

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

Test sequence of multiple semaphore timeouts.

See also
k_sem_take(), k_sem_reset()

◆ test_sem_multiple_take_and_timeouts()

void test_sem_multiple_take_and_timeouts ( void )

◆ test_sem_multiple_threads_wait()

void test_sem_multiple_threads_wait ( void )

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

Test multiple semaphore take and give with wait.

See also
k_sem_take(), k_sem_give()

◆ test_sem_queue_mutual_exclusion()

void test_sem_queue_mutual_exclusion ( void )

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

Test thread mutual exclusion by semaphore.

Test is using to see how mutual exclusion is made by semaphore Made two threads, with two functions which use common variable. That variable is a critical section and can't be changed by two threads at the same time.

◆ test_sem_reset()

void test_sem_reset ( void )

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

Test k_sem_reset() API.

See also
k_sem_reset()

TESTPOINT: semaphore take return -EBUSY

TESTPOINT: semaphore take return -EAGAIN

◆ test_sem_reset_null()

void test_sem_reset_null ( void )

◆ test_sem_reset_waiting()

◆ test_sem_take_multiple()

void test_sem_take_multiple ( void )

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

Test semaphore take operation by multiple threads.

See also
k_sem_take()

◆ test_sem_take_no_wait()

void test_sem_take_no_wait ( void )

◆ test_sem_take_no_wait_fails()

void test_sem_take_no_wait_fails ( void )

◆ test_sem_take_null()

void test_sem_take_null ( void )

◆ test_sem_take_timeout()

void test_sem_take_timeout ( void )

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

Test the semaphore take operation with specified timeout.

  • Create a new thread, it will give semaphore.
  • Reset the semaphore's count to zero.
  • Take semaphore and wait it given by other threads in specified timeout.
See also
k_sem_take()

◆ test_sem_take_timeout_fails()

void test_sem_take_timeout_fails ( void )

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

Test a semaphore take operation with an unavailable semaphore.

  • Reset the semaphore's count to zero, let it unavailable.
  • Take an unavailable semaphore and wait it until timeout.
See also
k_sem_take()

◆ test_sem_take_timeout_forever()

void test_sem_take_timeout_forever ( void )

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

Test the semaphore take operation with forever wait.

  • Create a new thread, it will give semaphore.
  • Reset the semaphore's count to zero.
  • Take semaphore, wait it given by other thread forever until it's available.
See also
k_sem_take()

◆ test_sem_take_timeout_isr()

void test_sem_take_timeout_isr ( void )

◆ test_sem_thread2isr()

void test_sem_thread2isr ( void )

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

Test synchronization between thread and irq.

See also
k_sem_init(), K_SEM_DEFINE(x)

TESTPOINT: test k_sem_init sema

TESTPOINT: test K_SEM_DEFINE sema

◆ test_sem_thread2thread()

void test_sem_thread2thread ( void )

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

Test synchronization of threads with semaphore.

See also
k_sem_init(), K_SEM_DEFINE(x)

TESTPOINT: test k_sem_init sema

TESTPOINT: test K_SEM_DEFINE sema

◆ test_simple_sem_from_isr()

void test_simple_sem_from_isr ( void )

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

Test semaphore count when given by an ISR.

◆ test_simple_sem_from_task()

void test_simple_sem_from_task ( void )

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

Test semaphore count when given by thread.