Skip to content

Commit d87a90e

Browse files
Andrew Boienashif
authored andcommitted
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 <[email protected]>
1 parent b34db7f commit d87a90e

File tree

4 files changed

+28
-38
lines changed

4 files changed

+28
-38
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CONFIG_ZTEST=y
22
CONFIG_IRQ_OFFLOAD=y
3-
3+
CONFIG_TEST_USERSPACE=y
44
CONFIG_SMP=n

tests/kernel/mutex/mutex_api/src/main.c

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/kernel/mutex/mutex_api/src/test_mutex_apis.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,26 @@ static void tmutex_test_lock(struct k_mutex *pmutex,
4545
void (*entry_fn)(void *, void *, void *))
4646
{
4747
k_mutex_init(pmutex);
48-
k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE,
49-
entry_fn, pmutex, NULL, NULL,
50-
K_PRIO_PREEMPT(0), 0, 0);
48+
k_thread_create(&tdata, tstack, STACK_SIZE,
49+
entry_fn, pmutex, NULL, NULL,
50+
K_PRIO_PREEMPT(0),
51+
K_USER | K_INHERIT_PERMS, 0);
5152
k_mutex_lock(pmutex, K_FOREVER);
5253
TC_PRINT("access resource from main thread\n");
5354

5455
/* wait for spawn thread to take action */
5556
k_sleep(TIMEOUT);
56-
57-
/* teardown */
58-
k_thread_abort(tid);
5957
}
6058

6159
static void tmutex_test_lock_timeout(struct k_mutex *pmutex,
6260
void (*entry_fn)(void *, void *, void *))
6361
{
6462
/**TESTPOINT: test k_mutex_init mutex*/
6563
k_mutex_init(pmutex);
66-
k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE,
67-
entry_fn, pmutex, NULL, NULL,
68-
K_PRIO_PREEMPT(0), 0, 0);
64+
k_thread_create(&tdata, tstack, STACK_SIZE,
65+
entry_fn, pmutex, NULL, NULL,
66+
K_PRIO_PREEMPT(0),
67+
K_USER | K_INHERIT_PERMS, 0);
6968
k_mutex_lock(pmutex, K_FOREVER);
7069
TC_PRINT("access resource from main thread\n");
7170

@@ -74,8 +73,6 @@ static void tmutex_test_lock_timeout(struct k_mutex *pmutex,
7473
k_mutex_unlock(pmutex);
7574
k_sleep(TIMEOUT);
7675

77-
/* teardown */
78-
k_thread_abort(tid);
7976
}
8077

8178
static void tmutex_test_lock_unlock(struct k_mutex *pmutex)
@@ -98,9 +95,11 @@ void test_mutex_reent_lock_forever(void)
9895
/**TESTPOINT: test k_mutex_init mutex*/
9996
k_mutex_init(&mutex);
10097
tmutex_test_lock(&mutex, tThread_entry_lock_forever);
98+
k_thread_abort(&tdata);
10199

102100
/**TESTPOINT: test K_MUTEX_DEFINE mutex*/
103101
tmutex_test_lock(&kmutex, tThread_entry_lock_forever);
102+
k_thread_abort(&tdata);
104103
}
105104

106105
void test_mutex_reent_lock_no_wait(void)
@@ -138,3 +137,19 @@ void test_mutex_lock_unlock(void)
138137
/**TESTPOINT: test K_MUTEX_DEFINE mutex*/
139138
tmutex_test_lock_unlock(&kmutex);
140139
}
140+
141+
/*test case main entry*/
142+
void test_main(void)
143+
{
144+
k_thread_access_grant(k_current_get(), &tdata, &tstack, &kmutex,
145+
&mutex);
146+
147+
ztest_test_suite(mutex_api,
148+
ztest_user_unit_test(test_mutex_lock_unlock),
149+
ztest_user_unit_test(test_mutex_reent_lock_forever),
150+
ztest_user_unit_test(test_mutex_reent_lock_no_wait),
151+
ztest_user_unit_test(test_mutex_reent_lock_timeout_fail),
152+
ztest_user_unit_test(test_mutex_reent_lock_timeout_pass)
153+
);
154+
ztest_run_test_suite(mutex_api);
155+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
tests:
22
kernel.mutex:
3-
tags: kernel
3+
tags: kernel userspace

0 commit comments

Comments
 (0)