Skip to content
Permalink
Browse files

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>
  • Loading branch information...
ioannisg authored and andrewboie committed Jun 26, 2019
1 parent 6631e7c commit 1dd2796b6f1d6242177e204a31a5124e7f799080
@@ -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})
@@ -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
@@ -0,0 +1,2 @@
CONFIG_ZTEST=y
CONFIG_USERSPACE=y
@@ -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.");
}
/**
* @}
*/
@@ -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);
}
@@ -0,0 +1,5 @@
tests:
arch.ramfunc:
filter: CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
tags: arm userspace
arch_whitelist: arm

0 comments on commit 1dd2796

Please sign in to comment.
You can’t perform that action at this time.