Skip to content

Commit

Permalink
tests: userspace: fix tests that don't hold on MMU
Browse files Browse the repository at this point in the history
MMU threads within the same memory domain have access to
each other's stacks.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information
Andrew Boie authored and nashif committed Nov 5, 2020
1 parent d943d14 commit eeab568
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions tests/kernel/mem_protect/userspace/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ static void test_start_kernel_thread(void)
zassert_unreachable("Create a kernel thread did not fault");
}

#ifndef CONFIG_MMU
static void uthread_read_body(void *p1, void *p2, void *p3)
{
unsigned int *vptr = p1;
Expand All @@ -404,6 +405,15 @@ static void uthread_read_body(void *p1, void *p2, void *p3)
zassert_unreachable("Read from other thread stack did not fault");
}

static void uthread_write_body(void *p1, void *p2, void *p3)
{
unsigned int *vptr = p1;

set_fault(K_ERR_CPU_EXCEPTION);
*vptr = 2U;
zassert_unreachable("Write to other thread stack did not fault");
}

/**
* @brief Test to read from another thread's stack
*
Expand All @@ -422,14 +432,6 @@ static void test_read_other_stack(void)
k_thread_join(&test_thread, K_FOREVER);
}

static void uthread_write_body(void *p1, void *p2, void *p3)
{
unsigned int *vptr = p1;

set_fault(K_ERR_CPU_EXCEPTION);
*vptr = 2U;
zassert_unreachable("Write to other thread stack did not fault");
}

/**
* @brief Test to write to other thread's stack
Expand All @@ -447,6 +449,17 @@ static void test_write_other_stack(void)
K_NO_WAIT);
k_thread_join(&test_thread, K_FOREVER);
}
#else
static void test_read_other_stack(void)
{
ztest_test_skip();
}

static void test_write_other_stack(void)
{
ztest_test_skip();
}
#endif /* CONFIG_MMU */

/**
* @brief Test to revoke access to kobject without permission
Expand Down

0 comments on commit eeab568

Please sign in to comment.