tests: add CONFIG_APPLICATION_MEMORY test
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
eeba84b5b5
commit
b60867fb32
4
tests/kernel/mem_protect/app_memory/Makefile
Normal file
4
tests/kernel/mem_protect/app_memory/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
BOARD ?= qemu_x86
|
||||
CONF_FILE = prj.conf
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.test
|
3
tests/kernel/mem_protect/app_memory/prj.conf
Normal file
3
tests/kernel/mem_protect/app_memory/prj.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
CONFIG_APPLICATION_MEMORY=y
|
||||
CONFIG_ZTEST=y
|
||||
|
3
tests/kernel/mem_protect/app_memory/src/Makefile
Normal file
3
tests/kernel/mem_protect/app_memory/src/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
include $(ZEPHYR_BASE)/tests/Makefile.test
|
||||
|
||||
obj-y += main.o
|
74
tests/kernel/mem_protect/app_memory/src/main.c
Normal file
74
tests/kernel/mem_protect/app_memory/src/main.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <tc_util.h>
|
||||
#include <linker/linker-defs.h>
|
||||
#include <ztest.h>
|
||||
|
||||
struct test_struct {
|
||||
int foo;
|
||||
int bar;
|
||||
char *baz;
|
||||
};
|
||||
|
||||
/* Check that the __kenrnel* macros work properly */
|
||||
struct test_struct __kernel kernel_data = {1, 2, NULL};
|
||||
struct test_struct __kernel_bss kernel_bss;
|
||||
struct test_struct __kernel_noinit kernel_noinit;
|
||||
|
||||
/* Real kernel variable, check it is in the right place */
|
||||
extern volatile u64_t _sys_clock_tick_count;
|
||||
|
||||
struct test_struct app_data = {3, 4, NULL};
|
||||
struct test_struct app_bss;
|
||||
struct test_struct __noinit app_noinit;
|
||||
|
||||
int data_loc(char *start, char *end, void *ptr)
|
||||
{
|
||||
if ((char *)ptr >= start && (char *)ptr < end) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
printk("Address %p outside range %p - %p\n", ptr, start, end);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_loc(void *ptr)
|
||||
{
|
||||
return data_loc(__app_ram_start, __app_ram_end, ptr);
|
||||
}
|
||||
|
||||
int kernel_loc(void *ptr)
|
||||
{
|
||||
return data_loc(__kernel_ram_start, __kernel_ram_end, ptr);
|
||||
}
|
||||
|
||||
void test_app_memory(void)
|
||||
{
|
||||
printk("Memory bounds:\n");
|
||||
printk("Application %p - %p\n", __app_ram_start, __app_ram_end);
|
||||
printk("Kernel %p - %p\n", __kernel_ram_start, __kernel_ram_end);
|
||||
|
||||
zassert_true(app_loc(&app_data), "not in app memory");
|
||||
zassert_true(app_loc(&app_bss), "not in app memory");
|
||||
zassert_true(app_loc(&app_noinit), "not in app memory");
|
||||
|
||||
zassert_true(kernel_loc(&kernel_data), "not in kernel memory");
|
||||
zassert_true(kernel_loc(&kernel_bss), "not in kernel memory");
|
||||
zassert_true(kernel_loc(&kernel_noinit), "not in kernel memory");
|
||||
|
||||
zassert_true(kernel_loc((void *)&_sys_clock_tick_count),
|
||||
"not in kernel memory");
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(app_memory,
|
||||
ztest_unit_test(test_app_memory));
|
||||
|
||||
ztest_run_test_suite(app_memory);
|
||||
}
|
4
tests/kernel/mem_protect/app_memory/testcase.yaml
Normal file
4
tests/kernel/mem_protect/app_memory/testcase.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
tests:
|
||||
- test:
|
||||
tags: core security
|
||||
arch_whitelist: x86 arm
|
Loading…
Reference in a new issue