Skip to content
Permalink
Browse files

tests: schedule_api: test syscalls from usermode

We didn't have any coverage of the system call handlers for
k_wakeup() and k_is_preempt().

Increase RAM requirements due to stack alignment constraints
on MPU platforms when user mode is enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information...
andrewboie authored and nashif committed Jun 11, 2019
1 parent b5d3ba4 commit 03f22773c5d218b41d29be5fb5229891582fa8b1
@@ -4,5 +4,5 @@ CONFIG_NUM_PREEMPT_PRIORITIES=30
CONFIG_SCHED_SCALABLE=y
CONFIG_QEMU_TICKLESS_WORKAROUND=y
CONFIG_MAX_THREAD_BYTES=4

CONFIG_TEST_USERSPACE=y
CONFIG_SMP=n
@@ -1,5 +1,6 @@
CONFIG_ZTEST=y
CONFIG_IRQ_OFFLOAD=y
CONFIG_TEST_USERSPACE=y
CONFIG_SCHED_MULTIQ=y
CONFIG_MAX_THREAD_BYTES=4
CONFIG_SMP=n
@@ -10,6 +10,9 @@
K_THREAD_STACK_DEFINE(tstack, STACK_SIZE);
K_THREAD_STACK_ARRAY_DEFINE(tstacks, MAX_NUM_THREAD, STACK_SIZE);

/* Not in header file intentionally, see #16760 */
K_THREAD_STACK_EXTERN(ustack);

void spin_for_ms(int ms)
{
#if defined(CONFIG_X86_64) && defined(CONFIG_QEMU_TARGET)
@@ -45,6 +48,11 @@ void spin_for_ms(int ms)
/*test case main entry*/
void test_main(void)
{
#ifdef CONFIG_USERSPACE
k_thread_access_grant(k_current_get(), &user_thread, &user_sem,
&ustack);
#endif /* CONFIG_USERSPACE */

ztest_test_suite(threads_scheduling,
ztest_unit_test(test_priority_cooperative),
ztest_unit_test(test_priority_preemptible),
@@ -60,7 +68,9 @@ void test_main(void)
ztest_unit_test(test_slice_reset),
ztest_unit_test(test_slice_scheduling),
ztest_unit_test(test_priority_scheduling),
ztest_unit_test(test_wakeup_expired_timer_thread)
ztest_unit_test(test_wakeup_expired_timer_thread),
ztest_user_unit_test(test_user_k_wakeup),
ztest_user_unit_test(test_user_k_is_preempt)
);
ztest_run_test_suite(threads_scheduling);
}
@@ -15,6 +15,8 @@

K_THREAD_STACK_EXTERN(tstack);
extern K_THREAD_STACK_ARRAY_DEFINE(tstacks, MAX_NUM_THREAD, STACK_SIZE);
extern struct k_thread user_thread;
extern struct k_sem user_sem;

struct thread_data {
k_tid_t tid;
@@ -39,5 +41,7 @@ void test_slice_reset(void);
void test_slice_scheduling(void);
void test_priority_scheduling(void);
void test_wakeup_expired_timer_thread(void);
void test_user_k_wakeup(void);
void test_user_k_is_preempt(void);

#endif /* __TEST_SCHED_H__ */
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "test_sched.h"

struct k_thread user_thread;
K_SEM_DEFINE(user_sem, 0, 1);

ZTEST_BMEM volatile bool thread_was_preempt;

K_THREAD_STACK_DEFINE(ustack, STACK_SIZE);

static void sleepy_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p1);
ARG_UNUSED(p2);
ARG_UNUSED(p3);

k_sleep(K_FOREVER);
k_sem_give(&user_sem);
}

void test_user_k_wakeup(void)
{
k_thread_create(&user_thread, ustack, STACK_SIZE, sleepy_thread,
NULL, NULL, NULL,
k_thread_priority_get(k_current_get()),
K_USER | K_INHERIT_PERMS, 0);

k_yield(); /* Let thread run and start sleeping forever */
k_wakeup(&user_thread);
k_sem_take(&user_sem, K_FOREVER);
}

static void preempt_test_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p1);
ARG_UNUSED(p2);
ARG_UNUSED(p3);

thread_was_preempt = k_is_preempt_thread();
k_sem_give(&user_sem);
}

void test_user_k_is_preempt(void)
{
k_thread_create(&user_thread, ustack, STACK_SIZE, preempt_test_thread,
NULL, NULL, NULL,
k_thread_priority_get(k_current_get()),
K_USER | K_INHERIT_PERMS, 0);

k_sem_take(&user_sem, K_FOREVER);
zassert_false(thread_was_preempt, "unexpected return value");

k_thread_create(&user_thread, ustack, STACK_SIZE, preempt_test_thread,
NULL, NULL, NULL,
K_PRIO_PREEMPT(1),
K_USER | K_INHERIT_PERMS, 0);

k_sem_take(&user_sem, K_FOREVER);
zassert_true(thread_was_preempt, "unexpected return value");

}

@@ -2,22 +2,22 @@ tests:
kernel.sched:
extra_configs:
- CONFIG_TIMESLICING=y
min_ram: 32
tags: kernel threads sched
min_ram: 40
tags: kernel threads sched userspace
kernel.sched_no_timeslicing:
extra_configs:
- CONFIG_TIMESLICING=n
min_ram: 32
tags: kernel threads sched
min_ram: 40
tags: kernel threads sched userspace
kernel.sched.multiq:
extra_args: CONF_FILE=prj_multiq.conf
extra_configs:
- CONFIG_TIMESLICING=y
min_ram: 32
tags: kernel threads sched
min_ram: 40
tags: kernel threads sched userspace
kernel.sched.multiq_no_timeslicing:
extra_args: CONF_FILE=prj_multiq.conf
extra_configs:
- CONFIG_TIMESLICING=n
min_ram: 32
tags: kernel threads sched
min_ram: 40
tags: kernel threads sched userspace

0 comments on commit 03f2277

Please sign in to comment.
You can’t perform that action at this time.