From d460a6361d40e67ecbcb6e90b3b42d3bda46f978 Mon Sep 17 00:00:00 2001 From: Lixin Guo Date: Fri, 8 Oct 2021 09:40:40 +0800 Subject: [PATCH] Test: stack: add a test case for code coverage Add a testcase for stack_alloc_init API. Signed-off-by: Lixin Guo --- tests/kernel/stack/stack/src/main.c | 2 ++ .../stack/stack/src/test_stack_contexts.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/kernel/stack/stack/src/main.c b/tests/kernel/stack/stack/src/main.c index 4d14f24009c..ced49e7f39c 100644 --- a/tests/kernel/stack/stack/src/main.c +++ b/tests/kernel/stack/stack/src/main.c @@ -80,6 +80,7 @@ extern void test_stack_pop_can_wait(void); extern void test_stack_cleanup_error(void); extern void test_stack_push_full(void); extern void test_stack_multithread_competition(void); +extern void test_stack_alloc_null(void); #ifdef CONFIG_USERSPACE extern void test_stack_user_thread2thread(void); extern void test_stack_user_pop_fail(void); @@ -365,6 +366,7 @@ void test_main(void) ztest_user_unit_test(test_stack_user_pop_null), ztest_user_unit_test(test_stack_user_pop_permission), ztest_unit_test(test_stack_alloc_thread2thread), + ztest_unit_test(test_stack_alloc_null), ztest_user_unit_test(test_single_stack_play), ztest_1cpu_user_unit_test(test_dual_stack_play), ztest_1cpu_unit_test(test_isr_stack_play), diff --git a/tests/kernel/stack/stack/src/test_stack_contexts.c b/tests/kernel/stack/stack/src/test_stack_contexts.c index 88bd15e27bd..283ec7432b0 100644 --- a/tests/kernel/stack/stack/src/test_stack_contexts.c +++ b/tests/kernel/stack/stack/src/test_stack_contexts.c @@ -279,6 +279,24 @@ void test_stack_multithread_competition(void) k_thread_priority_set(k_current_get(), old_prio); } +/** + * @brief Test case of requesting a buffer larger than resource pool. + * + * @details Try to request a buffer larger than resource pool for stack, + * then see if returns an expected value. + * + * @ingroup kernel_stack_tests + */ +void test_stack_alloc_null(void) +{ + int ret; + + /* Requested buffer allocation from the test pool. */ + ret = k_stack_alloc_init(&kstack_test_alloc, (STACK_SIZE/2)+1); + zassert_true(ret == -ENOMEM, + "requested buffer is smaller than resource pool"); +} + /** * @} */