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 <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2019-06-26 10:40:09 +02:00 committed by Andrew Boie
commit 1dd2796b6f
6 changed files with 135 additions and 0 deletions

View file

@ -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})

View file

@ -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

View file

@ -0,0 +1,2 @@
CONFIG_ZTEST=y
CONFIG_USERSPACE=y

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ztest.h>
#include <linker/linker-defs.h>
#include <syscall_handler.h>
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.");
}
/**
* @}
*/

View file

@ -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 <ztest.h>
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);
}

View file

@ -0,0 +1,5 @@
tests:
arch.ramfunc:
filter: CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
tags: arm userspace
arch_whitelist: arm