Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Common Tests

Macros

#define FAIL_ALLOC_MSG_FMT   "sys_bitarray_alloc with region size %i allocated incorrectly"
 
#define FAIL_ALLOC_RET_MSG_FMT   "sys_bitarray_alloc with region size %i returned incorrect result"
 
#define FAIL_ALLOC_OFFSET_MSG_FMT   "sys_bitarray_alloc with region size %i gave incorrect offset"
 
#define FAIL_FREE_MSG_FMT   "sys_bitarray_free with region size %i and offset %i failed"
 
#define FREE   0U
 

Functions

void test_atomic (void)
 Verify atomic functionalities. More...
 
void atomic_handler (void *p1, void *p2, void *p3)
 
void test_threads_access_atomic (void)
 Verify atomic operation with threads. More...
 
static bool cmp_u32_arrays (uint32_t *a1, uint32_t *a2, size_t sz)
 
void validate_bitarray_define (sys_bitarray_t *ba, size_t num_bits)
 
void test_bitarray_declare (void)
 Test defining of bitarrays. More...
 
bool bitarray_bundles_is_zero (sys_bitarray_t *ba)
 
void test_bitarray_set_clear (void)
 Test bitarrays set and clear. More...
 
void alloc_and_free_predefined (void)
 
static size_t count_bits (uint32_t val)
 
size_t get_bitarray_popcnt (sys_bitarray_t *ba)
 
void alloc_and_free_loop (int divisor)
 
void alloc_and_free_interval (void)
 
void test_bitarray_alloc_free (void)
 Test bitarrays allocation and free. More...
 
void test_bitarray_region_set_clear (void)
 
void test_ffs (void)
 Test find MSB and LSB operations. More...
 
void test_bitfield (void)
 Test bitfield operations. More...
 
void test_byteorder_memcpy_swap (void)
 Test swapping for memory contents. More...
 
void test_byteorder_mem_swap (void)
 Test sys_mem_swap() functionality. More...
 
void test_sys_get_be64 (void)
 Test sys_get_be64() functionality. More...
 
void test_sys_put_be64 (void)
 Test sys_put_be64() functionality. More...
 
void test_sys_get_be48 (void)
 Test sys_get_be48() functionality. More...
 
void test_sys_put_be48 (void)
 Test sys_put_be48() functionality. More...
 
void test_sys_get_be32 (void)
 Test sys_get_be32() functionality. More...
 
void test_sys_put_be32 (void)
 Test sys_put_be32() functionality. More...
 
void test_sys_get_be24 (void)
 Test sys_get_be24() functionality. More...
 
void test_sys_put_be24 (void)
 Test sys_put_be24() functionality. More...
 
void test_sys_get_be16 (void)
 Test sys_get_be16() functionality. More...
 
void test_sys_put_be16 (void)
 Test sys_put_be16() functionality. More...
 
void test_sys_get_le16 (void)
 Test sys_get_le16() functionality. More...
 
void test_sys_put_le16 (void)
 Test sys_put_le16() functionality. More...
 
void test_sys_get_le24 (void)
 Test sys_get_le24() functionality. More...
 
void test_sys_put_le24 (void)
 Test sys_put_le24() functionality. More...
 
void test_sys_get_le32 (void)
 Test sys_get_le32() functionality. More...
 
void test_sys_put_le32 (void)
 Test sys_put_le32() functionality. More...
 
void test_sys_get_le48 (void)
 Test sys_get_le48() functionality. More...
 
void test_sys_put_le48 (void)
 Test sys_put_le48() functionality. More...
 
void test_sys_get_le64 (void)
 Test sys_get_le64() functionality. More...
 
void test_sys_put_le64 (void)
 Test sys_put_le64() functionality. More...
 
void test_clock_uptime (void)
 Test clock uptime APIs functionality. More...
 
void test_clock_cycle (void)
 Test clock cycle functionality. More...
 
static void duration_expire (struct k_timer *timer)
 
static void stop_expire (struct k_timer *timer)
 
static void init_data_count (void)
 
void test_ms_time_duration (void)
 Test millisecond time duration. More...
 
__no_optimization void test_nop (void)
 Test the arch_nop() by invoking and measure it. More...
 
static void test_version (void)
 Test sys_kernel_version_get() functionality. More...
 
void test_multilib (void)
 Test if correct multilib is selected. More...
 
void test_printk (void)
 Test printk() functionality. More...
 
void test_timeout_order (void)
 Test timeout ordering. More...
 
void test_fatal (void)
 Test the kernel fatal error handling works correctly. More...
 
void test_fatal_on_smp (void)
 Test fatal error can be triggered on different core. More...
 
void test_workq_on_smp (void)
 Test system workq run on different core. More...
 

Detailed Description

Macro Definition Documentation

◆ FAIL_ALLOC_MSG_FMT

#define FAIL_ALLOC_MSG_FMT   "sys_bitarray_alloc with region size %i allocated incorrectly"

◆ FAIL_ALLOC_OFFSET_MSG_FMT

#define FAIL_ALLOC_OFFSET_MSG_FMT   "sys_bitarray_alloc with region size %i gave incorrect offset"

◆ FAIL_ALLOC_RET_MSG_FMT

#define FAIL_ALLOC_RET_MSG_FMT   "sys_bitarray_alloc with region size %i returned incorrect result"

◆ FAIL_FREE_MSG_FMT

#define FAIL_FREE_MSG_FMT   "sys_bitarray_free with region size %i and offset %i failed"

◆ FREE

#define FREE   0U

Function Documentation

◆ alloc_and_free_interval()

void alloc_and_free_interval ( void  )

◆ alloc_and_free_loop()

void alloc_and_free_loop ( int  divisor)

◆ alloc_and_free_predefined()

void alloc_and_free_predefined ( void  )

◆ atomic_handler()

void atomic_handler ( void p1,
void p2,
void p3 
)

◆ bitarray_bundles_is_zero()

bool bitarray_bundles_is_zero ( sys_bitarray_t ba)

◆ cmp_u32_arrays()

static bool cmp_u32_arrays ( uint32_t a1,
uint32_t a2,
size_t  sz 
)
static

◆ count_bits()

static size_t count_bits ( uint32_t  val)
inlinestatic

◆ duration_expire()

static void duration_expire ( struct k_timer *  timer)
static

◆ get_bitarray_popcnt()

size_t get_bitarray_popcnt ( sys_bitarray_t ba)

◆ init_data_count()

static void init_data_count ( void  )
static

◆ stop_expire()

static void stop_expire ( struct k_timer *  timer)
static

◆ test_atomic()

void test_atomic ( void  )

#include <tests/kernel/common/src/atomic.c>

Verify atomic functionalities.

Test Objective:

  • Test the function of the atomic operation API is correct.

Test techniques:

  • Dynamic analysis and testing
  • Functional and black box testing
  • Interface testing

Prerequisite Conditions:

  • N/A

Input Specifications:

  • N/A

Test Procedure:

  1. Call the API interface of the following atomic operations in turn, judge the change of function return value and target operands.

Expected Test Result:

  • The change of function return value and target operands is correct.

Pass/Fail Criteria:

  • Successful if check points in test procedure are all passed, otherwise failure.

Assumptions and Constraints:

  • N/A
See also
atomic_cas(), atomic_add(), atomic_sub(), atomic_inc(), atomic_dec(), atomic_get(), atomic_set(), atomic_clear(), atomic_or(), atomic_and(), atomic_xor(), atomic_nand(), atomic_test_bit(), atomic_test_and_clear_bit(), atomic_test_and_set_bit(), atomic_clear_bit(), atomic_set_bit(), ATOMIC_DEFINE

◆ test_bitarray_alloc_free()

void test_bitarray_alloc_free ( void  )

#include <tests/kernel/common/src/bitarray.c>

Test bitarrays allocation and free.

See also
sys_bitarray_alloc()
sys_bitarray_free()

◆ test_bitarray_declare()

void test_bitarray_declare ( void  )

#include <tests/kernel/common/src/bitarray.c>

Test defining of bitarrays.

See also
SYS_BITARRAY_DEFINE()

◆ test_bitarray_region_set_clear()

void test_bitarray_region_set_clear ( void  )

◆ test_bitarray_set_clear()

◆ test_bitfield()

◆ test_byteorder_mem_swap()

void test_byteorder_mem_swap ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_mem_swap() functionality.

Test if sys_mem_swap() reverses the contents

See also
sys_mem_swap()

◆ test_byteorder_memcpy_swap()

void test_byteorder_memcpy_swap ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test swapping for memory contents.

Verify the functionality provided by sys_memcpy_swap()

See also
sys_memcpy_swap()

◆ test_clock_cycle()

void test_clock_cycle ( void  )

#include <tests/kernel/common/src/clock.c>

Test clock cycle functionality.

Test Objectve:

Testing techniques

  • Functional and black box testing

Prerequisite Condition:

  • N/A

Input Specifications:

  • N/A

Expected Test Result:

  • The timer increases monotonically

Pass/Fail criteria:

  • Success if cycles increase monotonically, failure otherwise.

Test Procedure:

  1. At mili-second boundary, get cycles repeatedly by k_cycle_get_32() till cycles increased
  2. At mili-second boundary, get cycles repeatedly by k_uptime_get_32() till cycles increased
  3. Cross check cycles gotten by k_cycle_get_32() and k_uptime_get_32(), the delta cycle should be greater than 1 milli-second.

Assumptions and Constraints

  • N/A
See also
k_cycle_get_32(), k_uptime_get_32()

TESTPOINT: cycle elapse

TESTPOINT: cycle/uptime cross check

◆ test_clock_uptime()

void test_clock_uptime ( void  )

#include <tests/kernel/common/src/clock.c>

Test clock uptime APIs functionality.

See also
k_uptime_get(), k_uptime_get_32(), k_uptime_delta()

TESTPOINT: uptime elapse

TESTPOINT: uptime elapse lower 32-bit

TESTPOINT: uptime straddled ms boundary

TESTPOINT: uptime delta

◆ test_fatal()

void test_fatal ( void  )

#include <tests/kernel/fatal/exception/src/main.c>

Test the kernel fatal error handling works correctly.

Manually trigger the crash with various ways and check that the kernel is handling that properly or not. Also the crash reason should match. Check for stack sentinel feature by overflowing the thread's stack and check for the exception.

Manually trigger the crash with various ways and check that the kernel is handling that properly or not. Also the crash reason should match.

◆ test_fatal_on_smp()

void test_fatal_on_smp ( void  )

#include <tests/kernel/smp/src/main.c>

Test fatal error can be triggered on different core.

When CONFIG_SMP is enabled, on some multiprocessor platforms, exception can be triggered on different core at the same time.

◆ test_ffs()

void test_ffs ( void  )

#include <tests/kernel/common/src/bitarray.c>

Test find MSB and LSB operations.

Verify the functions that find out the most significiant bit and least significiant bit work as expected.

See also
find_msb_set(), find_lsb_set()

◆ test_ms_time_duration()

void test_ms_time_duration ( void  )

#include <tests/kernel/common/src/clock.c>

Test millisecond time duration.

initialize a timer, then providing time duration in millisecond, and check the duration time whether correct.

See also
k_timer_init(), k_timer_start(), k_timer_stop(), k_busy_wait()

TESTPOINT: waiting time less than duration and check the count

TESTPOINT: proving duration in millisecond

TESTPOINT: waiting time more than duration and check the count

cleanup environemtn

◆ test_multilib()

void test_multilib ( void  )

#include <tests/kernel/common/src/multilib.c>

Test if correct multilib is selected.

◆ test_nop()

__no_optimization void test_nop ( void  )

#include <tests/kernel/common/src/irq_offload.c>

Test the arch_nop() by invoking and measure it.

This test is mainly for coverage of the code. arch_nop() is a special implementation and it will behave differently on different platforms. By the way, this also measures how many cycles it spends for platforms that support it.

FYI: The potential uses of arch_nop() could be:

  • Code alignment: Although in this case it's much more likely the compiler doing so (or you're in an assembly file, in which case you're not calling arch_nop() anyway). And this would require that arch_nop() be ALWAYS_INLINE.
  • Giving you a guaranteed place to put a breakpoint / trace trigger / etc. when debugging. This is on main usage of arch_nop(); it inherently is generally debugging code removed before actually pushing.
  • Giving you a guaranteed place to put a patchpoint. E.g. ARMv7 allows nop (and a few other instructions) to be modified concurrently with execution, but not most other instructions.
  • Delaying a few instructions, e.g. for tight timing loops on M-cores.

Our test here mainly aims at the 4th scenario mentioned above but also potentially tests the 1st scenario. So no optimization here to prevent arch_nop() has optimized by the compiler is necessary.

See also
arch_nop()

◆ test_printk()

void test_printk ( void  )

#include <tests/kernel/common/src/printk.c>

Test printk() functionality.

See also
printk(), __printk_get_hook(), __printk_hook_install(), snprintk()

◆ test_sys_get_be16()

void test_sys_get_be16 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_be16() functionality.

Test if sys_get_be16() correctly handles endianness.

See also
sys_get_be16()

◆ test_sys_get_be24()

void test_sys_get_be24 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_be24() functionality.

Test if sys_get_be24() correctly handles endianness.

See also
sys_get_be24()

◆ test_sys_get_be32()

void test_sys_get_be32 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_be32() functionality.

Test if sys_get_be32() correctly handles endianness.

See also
sys_get_be32()

◆ test_sys_get_be48()

void test_sys_get_be48 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_be48() functionality.

Test if sys_get_be48() correctly handles endianness.

See also
sys_get_be48()

◆ test_sys_get_be64()

void test_sys_get_be64 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_be64() functionality.

Test if sys_get_be64() correctly handles endianness.

See also
sys_get_be64()

◆ test_sys_get_le16()

void test_sys_get_le16 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_le16() functionality.

Test if sys_get_le16() correctly handles endianness.

See also
sys_get_le16()

◆ test_sys_get_le24()

void test_sys_get_le24 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_le24() functionality.

Test if sys_get_le24() correctly handles endianness.

See also
sys_get_le24()

◆ test_sys_get_le32()

void test_sys_get_le32 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_le32() functionality.

Test if sys_get_le32() correctly handles endianness.

See also
sys_get_le32()

◆ test_sys_get_le48()

void test_sys_get_le48 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_le48() functionality.

Test if sys_get_le48() correctly handles endianness.

See also
sys_get_le48()

◆ test_sys_get_le64()

void test_sys_get_le64 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_get_le64() functionality.

Test if sys_get_le64() correctly handles endianness.

See also
sys_get_le64()

◆ test_sys_put_be16()

void test_sys_put_be16 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_be16() functionality.

Test if sys_put_be16() correctly handles endianness.

See also
sys_put_be16()

◆ test_sys_put_be24()

void test_sys_put_be24 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_be24() functionality.

Test if sys_put_be24() correctly handles endianness.

See also
sys_put_be24()

◆ test_sys_put_be32()

void test_sys_put_be32 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_be32() functionality.

Test if sys_put_be32() correctly handles endianness.

See also
sys_put_be32()

◆ test_sys_put_be48()

void test_sys_put_be48 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_be48() functionality.

Test if sys_put_be48() correctly handles endianness.

See also
sys_put_be48()

◆ test_sys_put_be64()

void test_sys_put_be64 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_be64() functionality.

Test if sys_put_be64() correctly handles endianness.

See also
sys_put_be64()

◆ test_sys_put_le16()

void test_sys_put_le16 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_le16() functionality.

Test if sys_put_le16() correctly handles endianness.

See also
sys_put_le16()

◆ test_sys_put_le24()

void test_sys_put_le24 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_le24() functionality.

Test if sys_put_le24() correctly handles endianness.

See also
sys_put_le24()

◆ test_sys_put_le32()

void test_sys_put_le32 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_le32() functionality.

Test if sys_put_le32() correctly handles endianness.

See also
sys_put_le32()

◆ test_sys_put_le48()

void test_sys_put_le48 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_le48() functionality.

Test if sys_put_le48() correctly handles endianness.

See also
sys_put_le48()

◆ test_sys_put_le64()

void test_sys_put_le64 ( void  )

#include <tests/kernel/common/src/byteorder.c>

Test sys_put_le64() functionality.

Test if sys_put_le64() correctly handles endianness.

See also
sys_put_le64()

◆ test_threads_access_atomic()

void test_threads_access_atomic ( void  )

#include <tests/kernel/common/src/atomic.c>

Verify atomic operation with threads.

Creat two preempt threads with equal priority to atomiclly access the same atomic value. Because these preempt threads are of equal priority, so enable time slice to make them scheduled. The thread will execute for some time. In this time, the two sub threads will be scheduled separately according to the time slice.

◆ test_timeout_order()

void test_timeout_order ( void  )

#include <tests/kernel/common/src/timeout_order.c>

Test timeout ordering.

Timeouts, when expiring on the same tick, should be handled in the same order they were queued.

See also
k_timer_start()

◆ test_version()

static void test_version ( void  )
static

◆ test_workq_on_smp()

void test_workq_on_smp ( void  )

#include <tests/kernel/smp/src/main.c>

Test system workq run on different core.

When macro CONFIG_SMP is enabled, workq can be run on different core.

◆ validate_bitarray_define()

void validate_bitarray_define ( sys_bitarray_t ba,
size_t  num_bits 
)