Zephyr Project API  3.3.0
A Scalable Open Source RTOS
Heap Memory Tests

Heap tests. More...

Functions

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

Detailed Description

Heap tests.

Function Documentation

◆ ZTEST() [1/9]

ZTEST ( k_heap_api  ,
test_k_heap_alloc_pending   
)

#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.

◆ ZTEST() [2/9]

ZTEST ( k_heap_api  ,
test_k_heap_alloc_pending_null   
)

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

Validate the k_heap alloc_pending_null support.

In main thread alloc two buffer from the heap, then run the child thread which alloc a buffer larger than remaining space. The child thread will wait timeout long until main thread free one of the buffer to heap, space in the heap is still not enough and then return null after timeout.

◆ ZTEST() [3/9]

ZTEST ( k_heap_api  ,
test_kheap_alloc_in_isr_nowait   
)

#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.

◆ ZTEST() [4/9]

ZTEST ( mheap_api  ,
test_malloc_in_isr   
)

#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()

◆ ZTEST() [5/9]

ZTEST ( mheap_api  ,
test_malloc_in_thread   
)

#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()

◆ ZTEST() [6/9]

ZTEST ( mheap_api  ,
test_mheap_calloc   
)

#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()

◆ ZTEST() [7/9]

ZTEST ( mheap_api  ,
test_mheap_malloc_align4   
)

#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).

◆ ZTEST() [8/9]

ZTEST ( mheap_api  ,
test_mheap_malloc_free   
)

#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.

◆ ZTEST() [9/9]

ZTEST ( mheap_api  ,
test_sys_heap_mem_pool_assign   
)

#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()