Test: stack: add a test case for code coverage

Add a testcase for stack_alloc_init API.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
This commit is contained in:
Lixin Guo 2021-10-08 09:40:40 +08:00 committed by Anas Nashif
commit d460a6361d
2 changed files with 20 additions and 0 deletions

View file

@ -80,6 +80,7 @@ extern void test_stack_pop_can_wait(void);
extern void test_stack_cleanup_error(void); extern void test_stack_cleanup_error(void);
extern void test_stack_push_full(void); extern void test_stack_push_full(void);
extern void test_stack_multithread_competition(void); extern void test_stack_multithread_competition(void);
extern void test_stack_alloc_null(void);
#ifdef CONFIG_USERSPACE #ifdef CONFIG_USERSPACE
extern void test_stack_user_thread2thread(void); extern void test_stack_user_thread2thread(void);
extern void test_stack_user_pop_fail(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_null),
ztest_user_unit_test(test_stack_user_pop_permission), ztest_user_unit_test(test_stack_user_pop_permission),
ztest_unit_test(test_stack_alloc_thread2thread), ztest_unit_test(test_stack_alloc_thread2thread),
ztest_unit_test(test_stack_alloc_null),
ztest_user_unit_test(test_single_stack_play), ztest_user_unit_test(test_single_stack_play),
ztest_1cpu_user_unit_test(test_dual_stack_play), ztest_1cpu_user_unit_test(test_dual_stack_play),
ztest_1cpu_unit_test(test_isr_stack_play), ztest_1cpu_unit_test(test_isr_stack_play),

View file

@ -279,6 +279,24 @@ void test_stack_multithread_competition(void)
k_thread_priority_set(k_current_get(), old_prio); 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");
}
/** /**
* @} * @}
*/ */