tests: mutex_api: run in user mode
Addresses coverage gaps. Some changes were made so that exited threads do not have k_thread_abort() called on them. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
b34db7fb71
commit
d87a90e4b9
4 changed files with 28 additions and 38 deletions
|
@ -1,4 +1,4 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_IRQ_OFFLOAD=y
|
||||
|
||||
CONFIG_TEST_USERSPACE=y
|
||||
CONFIG_SMP=n
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
extern void test_mutex_lock_unlock(void);
|
||||
extern void test_mutex_reent_lock_forever(void);
|
||||
extern void test_mutex_reent_lock_no_wait(void);
|
||||
extern void test_mutex_reent_lock_timeout_fail(void);
|
||||
extern void test_mutex_reent_lock_timeout_pass(void);
|
||||
|
||||
/*test case main entry*/
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(mutex_api,
|
||||
ztest_unit_test(test_mutex_lock_unlock),
|
||||
ztest_unit_test(test_mutex_reent_lock_forever),
|
||||
ztest_unit_test(test_mutex_reent_lock_no_wait),
|
||||
ztest_unit_test(test_mutex_reent_lock_timeout_fail),
|
||||
ztest_unit_test(test_mutex_reent_lock_timeout_pass)
|
||||
);
|
||||
ztest_run_test_suite(mutex_api);
|
||||
}
|
|
@ -45,17 +45,15 @@ static void tmutex_test_lock(struct k_mutex *pmutex,
|
|||
void (*entry_fn)(void *, void *, void *))
|
||||
{
|
||||
k_mutex_init(pmutex);
|
||||
k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE,
|
||||
entry_fn, pmutex, NULL, NULL,
|
||||
K_PRIO_PREEMPT(0), 0, 0);
|
||||
k_thread_create(&tdata, tstack, STACK_SIZE,
|
||||
entry_fn, pmutex, NULL, NULL,
|
||||
K_PRIO_PREEMPT(0),
|
||||
K_USER | K_INHERIT_PERMS, 0);
|
||||
k_mutex_lock(pmutex, K_FOREVER);
|
||||
TC_PRINT("access resource from main thread\n");
|
||||
|
||||
/* wait for spawn thread to take action */
|
||||
k_sleep(TIMEOUT);
|
||||
|
||||
/* teardown */
|
||||
k_thread_abort(tid);
|
||||
}
|
||||
|
||||
static void tmutex_test_lock_timeout(struct k_mutex *pmutex,
|
||||
|
@ -63,9 +61,10 @@ static void tmutex_test_lock_timeout(struct k_mutex *pmutex,
|
|||
{
|
||||
/**TESTPOINT: test k_mutex_init mutex*/
|
||||
k_mutex_init(pmutex);
|
||||
k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE,
|
||||
entry_fn, pmutex, NULL, NULL,
|
||||
K_PRIO_PREEMPT(0), 0, 0);
|
||||
k_thread_create(&tdata, tstack, STACK_SIZE,
|
||||
entry_fn, pmutex, NULL, NULL,
|
||||
K_PRIO_PREEMPT(0),
|
||||
K_USER | K_INHERIT_PERMS, 0);
|
||||
k_mutex_lock(pmutex, K_FOREVER);
|
||||
TC_PRINT("access resource from main thread\n");
|
||||
|
||||
|
@ -74,8 +73,6 @@ static void tmutex_test_lock_timeout(struct k_mutex *pmutex,
|
|||
k_mutex_unlock(pmutex);
|
||||
k_sleep(TIMEOUT);
|
||||
|
||||
/* teardown */
|
||||
k_thread_abort(tid);
|
||||
}
|
||||
|
||||
static void tmutex_test_lock_unlock(struct k_mutex *pmutex)
|
||||
|
@ -98,9 +95,11 @@ void test_mutex_reent_lock_forever(void)
|
|||
/**TESTPOINT: test k_mutex_init mutex*/
|
||||
k_mutex_init(&mutex);
|
||||
tmutex_test_lock(&mutex, tThread_entry_lock_forever);
|
||||
k_thread_abort(&tdata);
|
||||
|
||||
/**TESTPOINT: test K_MUTEX_DEFINE mutex*/
|
||||
tmutex_test_lock(&kmutex, tThread_entry_lock_forever);
|
||||
k_thread_abort(&tdata);
|
||||
}
|
||||
|
||||
void test_mutex_reent_lock_no_wait(void)
|
||||
|
@ -138,3 +137,19 @@ void test_mutex_lock_unlock(void)
|
|||
/**TESTPOINT: test K_MUTEX_DEFINE mutex*/
|
||||
tmutex_test_lock_unlock(&kmutex);
|
||||
}
|
||||
|
||||
/*test case main entry*/
|
||||
void test_main(void)
|
||||
{
|
||||
k_thread_access_grant(k_current_get(), &tdata, &tstack, &kmutex,
|
||||
&mutex);
|
||||
|
||||
ztest_test_suite(mutex_api,
|
||||
ztest_user_unit_test(test_mutex_lock_unlock),
|
||||
ztest_user_unit_test(test_mutex_reent_lock_forever),
|
||||
ztest_user_unit_test(test_mutex_reent_lock_no_wait),
|
||||
ztest_user_unit_test(test_mutex_reent_lock_timeout_fail),
|
||||
ztest_user_unit_test(test_mutex_reent_lock_timeout_pass)
|
||||
);
|
||||
ztest_run_test_suite(mutex_api);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
tests:
|
||||
kernel.mutex:
|
||||
tags: kernel
|
||||
tags: kernel userspace
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue