Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
|
Test memory slab APIs. More...
Functions | |
void | test_mheap_threadsafe (void) |
Verify alloc from multiple equal priority threads. More... | |
void | test_mslab (void) |
Main task to test memory slab interfaces. More... | |
void | test_mslab_kinit (void) |
Initialize the memory slab using k_mem_slab_init() and allocates/frees blocks. More... | |
void | test_mslab_kdefine (void) |
Verify K_MEM_SLAB_DEFINE() with allocates/frees blocks. More... | |
void | test_mslab_alloc_free_thread (void) |
Verify alloc and free of blocks from mem_slab. More... | |
void | test_mslab_alloc_align (void) |
Allocate memory blocks and check for alignment of 8 bytes. More... | |
void | test_mslab_alloc_timeout (void) |
Verify allocation of memory blocks with timeouts. More... | |
void | test_mslab_used_get (void) |
Verify count of allocated blocks. More... | |
void | test_mslab_kdefine_extern (void) |
Test mem_slab access outside the module. More... | |
void | test_mslab_alloc_wait_prio (void) |
Verify alloc with multiple threads. More... | |
void | test_mslab_threadsafe (void) |
Verify alloc and free from multiple equal priority threads. More... | |
Test memory slab APIs.
This module tests the following memory slab routines:
k_mem_slab_alloc k_mem_slab_free k_mem_slab_num_used_get
#include <tests/kernel/mem_heap/mheap_api_concept/src/test_mheap_concept.c>
Verify alloc from multiple equal priority threads.
Test creates three preemptive threads of equal priority. In each child thread , call k_malloc() to alloc a block of memory. Check These four threads can share the same heap space without interfering with each other.
#include <tests/kernel/mem_slab/mslab/src/main.c>
Main task to test memory slab interfaces.
Verify that system allows for the definitions of boot-time memory regions. This routine calls test_slab_get_all_blocks() to get all memory blocks from the map and calls test_slab_free_all_blocks() to free all memory blocks. It also tries to wait (with and without timeout) for a memory block.
#include <tests/kernel/mem_slab/mslab_api/src/test_mslab_api.c>
Allocate memory blocks and check for alignment of 8 bytes.
Allocate 3 blocks of memory from 2 memory slabs respectively and check if all blocks are aligned to 8 bytes and free them.
#include <tests/kernel/mem_slab/mslab_api/src/test_mslab_api.c>
Verify alloc and free of blocks from mem_slab.
#include <tests/kernel/mem_slab/mslab_api/src/test_mslab_api.c>
Verify allocation of memory blocks with timeouts.
Allocate 3 memory blocks from memory slab. Check allocation of another memory block with NO_WAIT set, since there are no blocks left to allocate in the memory slab, the allocation fails with return value -ENOMEM. Then the system up time is obtained, memory block allocation is tried with timeout of 2000 ms. Now the allocation API returns -EAGAIN as the waiting period is timeout. The test case also checks if timeout has really happened by checking delta period between the allocation request was made and return of -EAGAIN.
#include <tests/kernel/mem_slab/mslab_concept/src/test_mslab_alloc_wait.c>
Verify alloc with multiple threads.
The test allocates all blocks of memory slab and then spawns 3 threads with lowest priority and 2 more with same priority higher than first thread with delay 10ms and 20ms. Checks the behavior of alloc when requested by multiple threads
TESTPOINT: Any number of threads may wait on an empty memory slab simultaneously; when a memory block becomes available, it is given to the highest-priority thread that has waited the longest.
TESTPOINT: If all the blocks are currently in use, a thread can optionally wait for one to become available.
#include <tests/kernel/mem_slab/mslab_api/src/test_mslab_api.c>
Verify K_MEM_SLAB_DEFINE() with allocates/frees blocks.
Initialize 3 memory blocks of block size 8 bytes using
#include <tests/kernel/mem_slab/mslab_api/src/test_mslab_extern.c>
Test mem_slab access outside the module.
The memory slab can be accessed outside the module where it is defined using:
#include <tests/kernel/mem_slab/mslab_api/src/test_mslab_api.c>
Initialize the memory slab using k_mem_slab_init() and allocates/frees blocks.
Initialize 3 memory blocks of block size 8 bytes using
#include <tests/kernel/mem_slab/mslab_threadsafe/src/test_mslab_threadsafe.c>
Verify alloc and free from multiple equal priority threads.
Test creates 4 preemptive threads of equal priority. Then validates the synchronization of threads by allocating and freeing up the memory blocks in memory slab.
#include <tests/kernel/mem_slab/mslab_api/src/test_mslab_api.c>
Verify count of allocated blocks.
The test case allocates 3 blocks one after the other by checking for used block and free blocks in the memory slab - mslab. Once all 3 blocks are allocated, one more block is tried to allocates, which fails with return value -ENOMEM. It also checks the allocation with timeout. Again checks for used block and free blocks number using