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

Heap tests. More...

Functions

void test_kheap_alloc_in_isr_nowait (void)
 Validate allocation and free heap memory in isr context. More...
 
void test_k_heap_alloc_pending (void)
 Validate the k_heap support wait between different threads. More...
 
void test_mheap_malloc_free (void)
 Test to demonstrate k_malloc() and k_free() API usage. More...
 
void test_mheap_calloc (void)
 Test to demonstrate k_calloc() API functionality. More...
 
void test_sys_heap_mem_pool_assign (void)
 Validate allocation and free from system heap memory pool. More...
 
void test_malloc_in_isr (void)
 Validate allocation and free from system heap memory pool in isr context. More...
 
void test_malloc_in_thread (void)
 Validate allocation and free failure when thread's resource pool is not assigned. More...
 
void test_mheap_malloc_align4 (void)
 The test validates k_calloc() API. More...
 

Detailed Description

Heap tests.

Function Documentation

◆ test_k_heap_alloc_pending()

void test_k_heap_alloc_pending ( void  )

#include <tests/kernel/mem_heap/k_heap_api/src/test_kheap_api.c>

Validate the k_heap support wait between different threads.

In main thread alloc a buffer from the heap, then run the child thread. If there isn't enough space in the heap, the child thread will wait timeout long until main thread free the buffer to heap.

◆ test_kheap_alloc_in_isr_nowait()

void test_kheap_alloc_in_isr_nowait ( void  )

#include <tests/kernel/mem_heap/k_heap_api/src/test_kheap_api.c>

Validate allocation and free heap memory in isr context.

The test validates k_heap_alloc() in isr context, the timeout param should be K_NO_WAIT, because this situation isn't allow to wait.

◆ test_malloc_in_isr()

void test_malloc_in_isr ( void  )

#include <tests/kernel/mem_heap/mheap_api_concept/src/test_mheap_api.c>

Validate allocation and free from system heap memory pool in isr context.

When in isr context, the kernel will successfully alloc a block of memory because in this situation, the kernel will assign the heap memory as resource pool.

See also
z_thread_malloc(), k_free()

◆ test_malloc_in_thread()

void test_malloc_in_thread ( void  )

#include <tests/kernel/mem_heap/mheap_api_concept/src/test_mheap_api.c>

Validate allocation and free failure when thread's resource pool is not assigned.

When a thread's resource pool is not assigned, alloc memory will fail.

See also
z_thread_malloc()

◆ test_mheap_calloc()

void test_mheap_calloc ( void  )

#include <tests/kernel/mem_heap/mheap_api_concept/src/test_mheap_api.c>

Test to demonstrate k_calloc() API functionality.

The test validates k_calloc() API. When requesting a huge size of space or a space larger than heap memory, the API will return NULL. The 8 blocks of memory of size 16 bytes are allocated by k_calloc() API. When allocated using k_calloc() the memory buffers have to be zeroed. Check is done, if the blocks are memset to 0 and read/write is allowed. The test is then teared up by freeing all the blocks allocated.

See also
k_calloc()

◆ test_mheap_malloc_align4()

void test_mheap_malloc_align4 ( void  )

#include <tests/kernel/mem_heap/mheap_api_concept/src/test_mheap_concept.c>

The test validates k_calloc() API.

The 8 blocks of memory of size 16 bytes are allocated by k_calloc() API. When allocated using k_calloc() the memory buffers have to be zeroed. Check is done, if the blocks are memset to 0 and read/write is allowed. The test is then teared up by freeing all the blocks allocated.

See also
k_malloc(), k_free()

TESTPOINT: The address of the allocated chunk is guaranteed to be aligned on a word boundary (4 or 8 bytes).

◆ test_mheap_malloc_free()

void test_mheap_malloc_free ( void  )

#include <tests/kernel/mem_heap/mheap_api_concept/src/test_mheap_api.c>

Test to demonstrate k_malloc() and k_free() API usage.

The test allocates 4 blocks from heap memory pool using k_malloc() API. It also tries to allocate a block of size 64 bytes which fails as all the memory is allocated up. It then validates k_free() API by freeing up all the blocks which were allocated from the heap memory.

See also
k_malloc()

TESTPOINT: This routine provides traditional malloc() semantics. Memory is allocated from the heap memory pool.

TESTPOINT: Return NULL if fail.

TESTPOINT: This routine provides traditional free() semantics. The memory being returned must have been allocated from the heap memory pool.

TESTPOINT: If ptr is NULL, no operation is performed.

TESTPOINT: Return NULL if fail.

◆ test_sys_heap_mem_pool_assign()

void test_sys_heap_mem_pool_assign ( void  )

#include <tests/kernel/mem_heap/mheap_api_concept/src/test_mheap_api.c>

Validate allocation and free from system heap memory pool.

Set heap memory as resource pool. It will success when alloc a block of memory smaller than the pool and will fail when alloc a block of memory larger than the pool.

See also
k_thread_system_pool_assign(), z_thread_malloc(), k_free()