Skip to content

Commit f11bddb

Browse files
JordanYateskartben
authored andcommitted
tests: kernel: k_heap_api: test k_heap_array_get
Add a basic test for the behaviour of `k_heap_array_get`. Signed-off-by: Jordan Yates <[email protected]>
1 parent 117b452 commit f11bddb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/kernel/mem_heap/k_heap_api/src/test_kheap_api.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,31 @@ ZTEST(k_heap_api, test_k_heap_calloc)
291291

292292
k_heap_free(&k_heap_test, p);
293293
}
294+
295+
/**
296+
* @brief Test to demonstrate k_heap_array_get()
297+
*
298+
* @ingroup kernel_kheap_api_tests
299+
*
300+
* @details The test ensures that valid values are returned
301+
*
302+
* @see k_heap_array_get()
303+
*/
304+
ZTEST(k_heap_api, test_k_heap_array_get)
305+
{
306+
struct k_heap *ha = NULL;
307+
bool test_heap_found = false;
308+
int n;
309+
310+
n = k_heap_array_get(&ha);
311+
zassert_not_equal(0, n, "No heaps returned");
312+
zassert_not_null(ha, "Heap array pointer not populated");
313+
314+
/* Ensure that k_heap_test exists in the array */
315+
for (int i = 0; i < n; i++) {
316+
if (&k_heap_test == &ha[i]) {
317+
test_heap_found = true;
318+
}
319+
}
320+
zassert_true(test_heap_found);
321+
}

0 commit comments

Comments
 (0)