From 91bc0979550bc7786dc40fff4feaa64d680a5d08 Mon Sep 17 00:00:00 2001 From: Ioannis Glaropoulos Date: Wed, 26 Jun 2019 10:40:09 +0200 Subject: [PATCH] tests: kernel: add simple test for the ramfunc feature This commit contributes a simple test for the ARM RAMFUNC feature. Signed-off-by: Ioannis Glaropoulos --- tests/kernel/arm_ramfunc/CMakeLists.txt | 9 ++++ tests/kernel/arm_ramfunc/README.txt | 45 ++++++++++++++++++ tests/kernel/arm_ramfunc/prj.conf | 2 + tests/kernel/arm_ramfunc/src/arm_ramfunc.c | 54 ++++++++++++++++++++++ tests/kernel/arm_ramfunc/src/main.c | 20 ++++++++ tests/kernel/arm_ramfunc/testcase.yaml | 5 ++ 6 files changed, 135 insertions(+) create mode 100644 tests/kernel/arm_ramfunc/CMakeLists.txt create mode 100644 tests/kernel/arm_ramfunc/README.txt create mode 100644 tests/kernel/arm_ramfunc/prj.conf create mode 100644 tests/kernel/arm_ramfunc/src/arm_ramfunc.c create mode 100644 tests/kernel/arm_ramfunc/src/main.c create mode 100644 tests/kernel/arm_ramfunc/testcase.yaml diff --git a/tests/kernel/arm_ramfunc/CMakeLists.txt b/tests/kernel/arm_ramfunc/CMakeLists.txt new file mode 100644 index 0000000000000..1f22c1357608c --- /dev/null +++ b/tests/kernel/arm_ramfunc/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(arm_zero_latency_irqs) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/kernel/arm_ramfunc/README.txt b/tests/kernel/arm_ramfunc/README.txt new file mode 100644 index 0000000000000..e20a00c3c30e7 --- /dev/null +++ b/tests/kernel/arm_ramfunc/README.txt @@ -0,0 +1,45 @@ +Title: Test to verify code execution from SRAM for XIP images (ARM Only) + +Description: + +This test verifies that we can define functions in SRAM (and +sucessfully execute them from SRAM) in ARM XIP images. It +also verifies that the .ramfunc section is accessible by +nPRIV code when building with support for user mode +(CONFIG_USERSPACE=y). Only for ARM Cortex-M targets. + +--------------------------------------------------------------------------- + +Building and Running Project: + +This project outputs to the console. It can be built and executed on QEMU as +follows: + + ninja/make run + +--------------------------------------------------------------------------- + +Troubleshooting: + +Problems caused by out-dated project information can be addressed by +issuing one of the following commands then rebuilding the project: + + ninja/make clean # discard results of previous builds + # but keep existing configuration info +or + ninja/make pristine # discard results of previous builds + # and restore pre-defined configuration info + +--------------------------------------------------------------------------- + +Sample Output: + +***** Booting Zephyr OS build zephyr-v1.14.0-1726-gb95a71960622 ***** +Running test suite arm_ramfunc +=================================================================== +starting test - test_arm_ramfunc +PASS - test_arm_ramfunc +=================================================================== +Test suite arm_ramfunc succeeded +=================================================================== +PROJECT EXECUTION SUCCESSFUL diff --git a/tests/kernel/arm_ramfunc/prj.conf b/tests/kernel/arm_ramfunc/prj.conf new file mode 100644 index 0000000000000..75f9e1480783e --- /dev/null +++ b/tests/kernel/arm_ramfunc/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_USERSPACE=y diff --git a/tests/kernel/arm_ramfunc/src/arm_ramfunc.c b/tests/kernel/arm_ramfunc/src/arm_ramfunc.c new file mode 100644 index 0000000000000..2d7810481fdae --- /dev/null +++ b/tests/kernel/arm_ramfunc/src/arm_ramfunc.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 Nordic Semiconductor ASA. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +static volatile int test_flag; + +__ramfunc static void arm_ram_function(void) +{ + test_flag = 1; +} + +void test_arm_ramfunc(void) +{ + zassert_true(test_flag == 0, "Test flag not initialized to zero"); + + /* Verify that the .ramfunc section is not empty, it is located + * inside SRAM, and that arm_ram_function(.) is located inside + * the .ramfunc section. + */ + zassert_true((u32_t)&_ramfunc_ram_size != 0, + ".ramfunc linker section is empty"); + zassert_true(((u32_t)&_ramfunc_ram_start >= (u32_t)&_image_ram_start) + && ((u32_t)&_ramfunc_ram_end < (u32_t)&_image_ram_end), + ".ramfunc linker section not in RAM"); + zassert_true( + (((u32_t)&_ramfunc_ram_start) <= (u32_t)arm_ram_function) && + (((u32_t)&_ramfunc_ram_end) > (u32_t)arm_ram_function), + "arm_ram_function not loaded into .ramfunc"); + + /* If we build with User Mode support, verify that the + * arm_ram_function(.) is user (read) accessible. + */ +#if defined(CONFIG_USERSPACE) + zassert_true(z_arch_buffer_validate((void *)&_ramfunc_ram_start, + (size_t)&_ramfunc_ram_size, 0) == 0 /* Success */, + ".ramfunc section not user accessible"); +#endif /* CONFIG_USERSPACE */ + + /* Execute the function from SRAM. */ + arm_ram_function(); + + /* Verify that the function is executed successfully. */ + zassert_true(test_flag = 1, + "arm_ram_function() execution failed."); +} +/** + * @} + */ diff --git a/tests/kernel/arm_ramfunc/src/main.c b/tests/kernel/arm_ramfunc/src/main.c new file mode 100644 index 0000000000000..5b70c180f42cc --- /dev/null +++ b/tests/kernel/arm_ramfunc/src/main.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#if !defined(CONFIG_CPU_CORTEX_M) + #error test can only run on Cortex-M MCUs +#endif + +#include + +extern void test_arm_ramfunc(void); + +void test_main(void) +{ + ztest_test_suite(arm_ramfunc, + ztest_unit_test(test_arm_ramfunc)); + ztest_run_test_suite(arm_ramfunc); +} diff --git a/tests/kernel/arm_ramfunc/testcase.yaml b/tests/kernel/arm_ramfunc/testcase.yaml new file mode 100644 index 0000000000000..386283ab1fa71 --- /dev/null +++ b/tests/kernel/arm_ramfunc/testcase.yaml @@ -0,0 +1,5 @@ +tests: + arch.ramfunc: + filter: CONFIG_ARCH_HAS_RAMFUNC_SUPPORT + tags: arm userspace + arch_whitelist: arm