tests: userspace: Add description and doxygen links
Add description and doxygen links to userspace test cases Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
This commit is contained in:
parent
6910f15fcf
commit
234f48e1ef
1 changed files with 125 additions and 14 deletions
|
@ -102,6 +102,11 @@ void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf)
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to check if the thread is in user mode
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void is_usermode(void)
|
||||
{
|
||||
/* Confirm that we are in fact running in user mode. */
|
||||
|
@ -110,6 +115,11 @@ static void is_usermode(void)
|
|||
zassert_true(_is_user_context(), "thread left in kernel mode");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to write to a control register
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void write_control(void)
|
||||
{
|
||||
/* Try to write to a control register. */
|
||||
|
@ -134,9 +144,9 @@ static void write_control(void)
|
|||
"msr CONTROL, %0;\n\t"
|
||||
"mrs %0, CONTROL;\n\t"
|
||||
: "=r" (msr_value)::
|
||||
);
|
||||
);
|
||||
zassert_true((msr_value & 1),
|
||||
"Write to control register was successful");
|
||||
"Write to control register was successful");
|
||||
#elif defined(CONFIG_ARC)
|
||||
unsigned int er_status;
|
||||
|
||||
|
@ -144,16 +154,21 @@ static void write_control(void)
|
|||
expected_reason = REASON_HW_EXCEPTION;
|
||||
BARRIER();
|
||||
/* _ARC_V2_ERSTATUS is privilege aux reg */
|
||||
__asm__ volatile(
|
||||
__asm__ volatile (
|
||||
"lr %0, [0x402]\n"
|
||||
: "=r" (er_status)::
|
||||
);
|
||||
);
|
||||
#else
|
||||
#error "Not implemented for this architecture"
|
||||
zassert_unreachable("Write to control register did not fault");
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to disable memory protection
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void disable_mmu_mpu(void)
|
||||
{
|
||||
/* Try to disable memory protections. */
|
||||
|
@ -182,6 +197,11 @@ static void disable_mmu_mpu(void)
|
|||
zassert_unreachable("Disable MMU/MPU did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to read from kernel RAM
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void read_kernram(void)
|
||||
{
|
||||
/* Try to read from kernel RAM. */
|
||||
|
@ -195,6 +215,11 @@ static void read_kernram(void)
|
|||
zassert_unreachable("Read from kernel RAM did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to write to kernel RAM
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void write_kernram(void)
|
||||
{
|
||||
/* Try to write to kernel RAM. */
|
||||
|
@ -209,6 +234,11 @@ extern int _k_neg_eagain;
|
|||
|
||||
#include <linker/linker-defs.h>
|
||||
|
||||
/**
|
||||
* @brief Test to write kernel RO
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void write_kernro(void)
|
||||
{
|
||||
/* Try to write to kernel RO. */
|
||||
|
@ -224,6 +254,11 @@ static void write_kernro(void)
|
|||
zassert_unreachable("Write to kernel RO did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to write to kernel text section
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void write_kerntext(void)
|
||||
{
|
||||
/* Try to write to kernel text. */
|
||||
|
@ -236,6 +271,11 @@ static void write_kerntext(void)
|
|||
|
||||
__kernel static int kernel_data;
|
||||
|
||||
/**
|
||||
* @brief Testto read from kernel data section
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void read_kernel_data(void)
|
||||
{
|
||||
/* Try to read from embedded kernel data. */
|
||||
|
@ -249,6 +289,11 @@ static void read_kernel_data(void)
|
|||
zassert_unreachable("Read from __kernel data did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to write to kernel data section
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void write_kernel_data(void)
|
||||
{
|
||||
expect_fault = true;
|
||||
|
@ -270,9 +315,14 @@ _app_dmem(part0) volatile int *priv_stack_ptr;
|
|||
_app_dmem(part0) size_t size = MMU_PAGE_SIZE;
|
||||
#elif defined(CONFIG_ARC)
|
||||
_app_dmem(part0) s32_t size = (0 - CONFIG_PRIVILEGED_STACK_SIZE -
|
||||
STACK_GUARD_SIZE);
|
||||
STACK_GUARD_SIZE);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Test to read provileged stack
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void read_priv_stack(void)
|
||||
{
|
||||
/* Try to read from privileged stack. */
|
||||
|
@ -294,6 +344,11 @@ static void read_priv_stack(void)
|
|||
zassert_unreachable("Read from privileged stack did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to write to privilege stack
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void write_priv_stack(void)
|
||||
{
|
||||
/* Try to write to privileged stack. */
|
||||
|
@ -318,6 +373,11 @@ static void write_priv_stack(void)
|
|||
|
||||
_app_bmem(part0) static struct k_sem sem;
|
||||
|
||||
/**
|
||||
* @brief Test to pass a user object to system call
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void pass_user_object(void)
|
||||
{
|
||||
/* Try to pass a user object to a system call. */
|
||||
|
@ -330,6 +390,11 @@ static void pass_user_object(void)
|
|||
|
||||
__kernel static struct k_sem ksem;
|
||||
|
||||
/**
|
||||
* @brief Test to pass object to a system call without permissions
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void pass_noperms_object(void)
|
||||
{
|
||||
/* Try to pass a object to a system call w/o permissions. */
|
||||
|
@ -350,6 +415,11 @@ void thread_body(void)
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to start kernel thread from usermode
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void start_kernel_thread(void)
|
||||
{
|
||||
/* Try to start a kernel thread from a usermode thread */
|
||||
|
@ -376,10 +446,16 @@ static void uthread_body(void)
|
|||
k_sem_take(&uthread_end_sem, K_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to read from another thread's stack
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void read_other_stack(void)
|
||||
{
|
||||
/* Try to read from another thread's stack. */
|
||||
unsigned int *ptr;
|
||||
|
||||
k_thread_create(&uthread_thread, uthread_stack, STACKSIZE,
|
||||
(k_thread_entry_t)uthread_body, NULL, NULL, NULL,
|
||||
-1, K_USER | K_INHERIT_PERMS,
|
||||
|
@ -403,6 +479,11 @@ static void read_other_stack(void)
|
|||
zassert_unreachable("Read from other thread stack did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to write to other thread's stack
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void write_other_stack(void)
|
||||
{
|
||||
/* Try to write to another thread's stack. */
|
||||
|
@ -431,6 +512,11 @@ static void write_other_stack(void)
|
|||
zassert_unreachable("Write to other thread stack did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to revoke acess to kobject without permission
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void revoke_noperms_object(void)
|
||||
{
|
||||
/* Attempt to revoke access to kobject w/o permissions*/
|
||||
|
@ -440,9 +526,14 @@ static void revoke_noperms_object(void)
|
|||
k_object_release(&ksem);
|
||||
|
||||
zassert_unreachable("Revoke access to unauthorized object "
|
||||
"did not fault");
|
||||
"did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to access object after revoking access
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void access_after_revoke(void)
|
||||
{
|
||||
k_object_release(&test_revoke_sem);
|
||||
|
@ -458,7 +549,7 @@ static void access_after_revoke(void)
|
|||
|
||||
static void umode_enter_func(void)
|
||||
{
|
||||
if (_is_user_context()) {
|
||||
if (_is_user_context()) {
|
||||
/*
|
||||
* Have to explicitly call ztest_test_pass() because
|
||||
* k_thread_user_mode_enter() does not return. We have
|
||||
|
@ -471,18 +562,28 @@ static void umode_enter_func(void)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to check enter to usermode
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void user_mode_enter(void)
|
||||
{
|
||||
expect_fault = false;
|
||||
BARRIER();
|
||||
k_thread_user_mode_enter((k_thread_entry_t)umode_enter_func,
|
||||
NULL, NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* Define and initialize pipe. */
|
||||
K_PIPE_DEFINE(kpipe, PIPE_LEN, BYTES_TO_READ_WRITE);
|
||||
_app_bmem(part0) static size_t bytes_written_read;
|
||||
|
||||
/**
|
||||
* @brief Test to write to kobject using pipe
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void write_kobject_user_pipe(void)
|
||||
{
|
||||
/*
|
||||
|
@ -493,12 +594,17 @@ static void write_kobject_user_pipe(void)
|
|||
expected_reason = REASON_KERNEL_OOPS;
|
||||
BARRIER();
|
||||
k_pipe_get(&kpipe, &uthread_start_sem, BYTES_TO_READ_WRITE,
|
||||
&bytes_written_read, 1, K_NO_WAIT);
|
||||
&bytes_written_read, 1, K_NO_WAIT);
|
||||
|
||||
zassert_unreachable("System call memory write validation "
|
||||
"did not fault");
|
||||
"did not fault");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to read from kobject using pipe
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void read_kobject_user_pipe(void)
|
||||
{
|
||||
/*
|
||||
|
@ -509,10 +615,10 @@ static void read_kobject_user_pipe(void)
|
|||
expected_reason = REASON_KERNEL_OOPS;
|
||||
BARRIER();
|
||||
k_pipe_put(&kpipe, &uthread_start_sem, BYTES_TO_READ_WRITE,
|
||||
&bytes_written_read, 1, K_NO_WAIT);
|
||||
&bytes_written_read, 1, K_NO_WAIT);
|
||||
|
||||
zassert_unreachable("System call memory read validation "
|
||||
"did not fault");
|
||||
"did not fault");
|
||||
}
|
||||
|
||||
/* Removed test for access_non_app_memory
|
||||
|
@ -536,9 +642,14 @@ static void shared_mem_thread(void)
|
|||
BARRIER();
|
||||
thread_bool = false;
|
||||
zassert_unreachable("Thread accessed global in other "
|
||||
"memory domain\n");
|
||||
"memory domain\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test to access other memory domain
|
||||
*
|
||||
* @ingroup kernel_memprotect_tests
|
||||
*/
|
||||
static void access_other_memdomain(void)
|
||||
{
|
||||
/*
|
||||
|
@ -618,6 +729,6 @@ void test_main(void)
|
|||
ztest_user_unit_test(write_kobject_user_pipe),
|
||||
ztest_user_unit_test(read_kobject_user_pipe),
|
||||
ztest_unit_test(access_other_memdomain)
|
||||
);
|
||||
);
|
||||
ztest_run_test_suite(userspace);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue