tests: test k_sem_init()
Add tests for k_sem_init. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
756d8b03e2
commit
2711c4e03f
1 changed files with 41 additions and 4 deletions
|
@ -151,8 +151,11 @@ void sem_take_multiple_high_prio_helper(void *p1, void *p2, void *p3)
|
||||||
*/
|
*/
|
||||||
void test_sema_thread2thread(void)
|
void test_sema_thread2thread(void)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
/**TESTPOINT: test k_sem_init sema*/
|
/**TESTPOINT: test k_sem_init sema*/
|
||||||
k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
ret = k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
||||||
|
|
||||||
|
zassert_equal(ret, 0, NULL);
|
||||||
|
|
||||||
tsema_thread_thread(&sema);
|
tsema_thread_thread(&sema);
|
||||||
|
|
||||||
|
@ -166,21 +169,50 @@ void test_sema_thread2thread(void)
|
||||||
*/
|
*/
|
||||||
void test_sema_thread2isr(void)
|
void test_sema_thread2isr(void)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
/**TESTPOINT: test k_sem_init sema*/
|
/**TESTPOINT: test k_sem_init sema*/
|
||||||
k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
ret = k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
||||||
|
|
||||||
|
zassert_equal(ret, 0, NULL);
|
||||||
tsema_thread_isr(&sema);
|
tsema_thread_isr(&sema);
|
||||||
|
|
||||||
/**TESTPOINT: test K_SEM_DEFINE sema*/
|
/**TESTPOINT: test K_SEM_DEFINE sema*/
|
||||||
tsema_thread_isr(&ksema);
|
tsema_thread_isr(&ksema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Test k_sem_init() API
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void test_k_sema_init(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
||||||
|
zassert_equal(ret, 0, NULL);
|
||||||
|
|
||||||
|
k_sem_reset(&sema);
|
||||||
|
|
||||||
|
ret = k_sem_init(&sema, SEM_INIT_VAL, 0);
|
||||||
|
zassert_equal(ret, -EINVAL, NULL);
|
||||||
|
|
||||||
|
ret = k_sem_init(&sema, SEM_MAX_VAL + 1, SEM_MAX_VAL);
|
||||||
|
zassert_equal(ret, -EINVAL, NULL);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Test k_sem_reset() API
|
* @brief Test k_sem_reset() API
|
||||||
* @see k_sem_reset()
|
* @see k_sem_reset()
|
||||||
*/
|
*/
|
||||||
void test_sema_reset(void)
|
void test_sema_reset(void)
|
||||||
{
|
{
|
||||||
k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
int ret;
|
||||||
|
|
||||||
|
ret = k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
||||||
|
zassert_equal(ret, 0, NULL);
|
||||||
|
|
||||||
k_sem_give(&sema);
|
k_sem_give(&sema);
|
||||||
k_sem_reset(&sema);
|
k_sem_reset(&sema);
|
||||||
zassert_false(k_sem_count_get(&sema), NULL);
|
zassert_false(k_sem_count_get(&sema), NULL);
|
||||||
|
@ -198,7 +230,11 @@ void test_sema_reset(void)
|
||||||
*/
|
*/
|
||||||
void test_sema_count_get(void)
|
void test_sema_count_get(void)
|
||||||
{
|
{
|
||||||
k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
int ret;
|
||||||
|
|
||||||
|
ret = k_sem_init(&sema, SEM_INIT_VAL, SEM_MAX_VAL);
|
||||||
|
zassert_equal(ret, 0, NULL);
|
||||||
|
|
||||||
/**TESTPOINT: sem count get upon init*/
|
/**TESTPOINT: sem count get upon init*/
|
||||||
zassert_equal(k_sem_count_get(&sema), SEM_INIT_VAL, NULL);
|
zassert_equal(k_sem_count_get(&sema), SEM_INIT_VAL, NULL);
|
||||||
k_sem_give(&sema);
|
k_sem_give(&sema);
|
||||||
|
@ -861,6 +897,7 @@ void test_main(void)
|
||||||
&tstack, &tdata);
|
&tstack, &tdata);
|
||||||
|
|
||||||
ztest_test_suite(test_semaphore,
|
ztest_test_suite(test_semaphore,
|
||||||
|
ztest_user_unit_test(test_k_sema_init),
|
||||||
ztest_user_unit_test(test_sema_thread2thread),
|
ztest_user_unit_test(test_sema_thread2thread),
|
||||||
ztest_unit_test(test_sema_thread2isr),
|
ztest_unit_test(test_sema_thread2isr),
|
||||||
ztest_user_unit_test(test_sema_reset),
|
ztest_user_unit_test(test_sema_reset),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue