test: kheap: add testcase

Add testcase when use kheap api in isr context.

Signed-off-by: Ying ming <mingx.ying@intel.com>
This commit is contained in:
Ying ming 2021-01-05 15:19:51 +08:00 committed by Anas Nashif
commit 812914ff5d
3 changed files with 25 additions and 2 deletions

View file

@ -1 +1,2 @@
CONFIG_ZTEST=y
CONFIG_IRQ_OFFLOAD=y

View file

@ -8,6 +8,7 @@
extern void test_k_heap_alloc(void);
extern void test_k_heap_alloc_fail(void);
extern void test_k_heap_free(void);
extern void test_kheap_alloc_in_isr_nowait(void);
/**
* @brief k heap api tests
@ -24,6 +25,7 @@ void test_main(void)
ztest_test_suite(k_heap_api,
ztest_unit_test(test_k_heap_alloc),
ztest_unit_test(test_k_heap_alloc_fail),
ztest_unit_test(test_k_heap_free));
ztest_unit_test(test_k_heap_free),
ztest_unit_test(test_kheap_alloc_in_isr_nowait));
ztest_run_test_suite(k_heap_api);
}

View file

@ -5,6 +5,7 @@
*/
#include <ztest.h>
#include <irq_offload.h>
#include "test_kheap.h"
K_HEAP_DEFINE(k_heap_test, HEAP_SIZE);
@ -13,6 +14,16 @@ K_HEAP_DEFINE(k_heap_test, HEAP_SIZE);
#define ALLOC_SIZE_2 1536
#define ALLOC_SIZE_3 2049
static void tIsr_kheap_alloc_nowait(void *data)
{
ARG_UNUSED(data);
char *p = (char *)k_heap_alloc(&k_heap_test, ALLOC_SIZE_1, K_NO_WAIT);
zassert_not_null(p, "k_heap_alloc operation failed");
k_heap_free(&k_heap_test, p);
}
/*test cases*/
/**
@ -27,7 +38,6 @@ K_HEAP_DEFINE(k_heap_test, HEAP_SIZE);
*/
void test_k_heap_alloc(void)
{
k_timeout_t timeout = Z_TIMEOUT_US(TIMEOUT);
char *p = (char *)k_heap_alloc(&k_heap_test, ALLOC_SIZE_1, timeout);
@ -91,3 +101,13 @@ void test_k_heap_free(void)
}
k_heap_free(&k_heap_test, p);
}
/**
* @brief Validate allocation and free heap memory in isr context.
*
* @ingroup kernel_heap_tests
*/
void test_kheap_alloc_in_isr_nowait(void)
{
irq_offload((irq_offload_routine_t)tIsr_kheap_alloc_nowait, NULL);
}