tests: mem_protect: add default mem domain checks

Ensure that both the main thread and any static threads are
properly assigned to the default memory domain.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2020-10-06 14:47:33 -07:00 committed by Andrew Boie
commit c3e285acea
4 changed files with 32 additions and 1 deletions

View file

@ -4,5 +4,10 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(mem_protect)
target_include_directories(app PRIVATE
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/${ARCH}/include
)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

View file

@ -69,7 +69,8 @@ void test_main(void)
ztest_unit_test(test_create_new_essential_thread_from_user),
ztest_unit_test(test_create_new_higher_prio_thread_from_user),
ztest_unit_test(test_inherit_resource_pool),
ztest_unit_test(test_create_new_invalid_prio_thread_from_user)
ztest_unit_test(test_create_new_invalid_prio_thread_from_user),
ztest_unit_test(test_mem_domain_boot_threads)
);
ztest_run_test_suite(memory_protection_test_suite);
}

View file

@ -6,6 +6,7 @@
#include "mem_protect.h"
#include <sys/mempool.h>
#include <kernel_internal.h> /* For z_main_thread */
#define ERROR_STR \
("Fault didn't occur when we accessed a unassigned memory domain.")
@ -781,3 +782,26 @@ void test_mem_part_assign_bss_vars_zero(void)
read_data = part2_bss_var;
zassert_true(read_data == 0, NULL);
}
static void zzz_entry(void *p1, void *p2, void *p3)
{
k_sleep(K_FOREVER);
}
K_THREAD_DEFINE(zzz_thread, 256 + CONFIG_TEST_EXTRA_STACKSIZE, zzz_entry,
NULL, NULL, NULL, 0, 0, 0);
void test_mem_domain_boot_threads(void)
{
/* Check that a static thread got put in the default memory domain */
zassert_true(zzz_thread->mem_domain_info.mem_domain ==
&k_mem_domain_default, "unexpected mem domain %p",
zzz_thread->mem_domain_info.mem_domain);
/* Check that the main thread is also a member of the default domain */
zassert_true(z_main_thread.mem_domain_info.mem_domain ==
&k_mem_domain_default, "unexpected mem domain %p",
z_main_thread.mem_domain_info.mem_domain);
k_thread_abort(zzz_thread);
}

View file

@ -51,6 +51,7 @@ extern void test_create_new_higher_prio_thread_from_user(void);
extern void test_create_new_invalid_prio_thread_from_user(void);
extern void test_inherit_resource_pool(void);
extern void test_mark_thread_exit_uninitialized(void);
extern void test_mem_domain_boot_threads(void);
/* Flag needed to figure out if the fault was expected or not. */
extern volatile bool valid_fault;