Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/kernel/arm_ramfunc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
45 changes: 45 additions & 0 deletions tests/kernel/arm_ramfunc/README.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/kernel/arm_ramfunc/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_ZTEST=y
CONFIG_USERSPACE=y
54 changes: 54 additions & 0 deletions tests/kernel/arm_ramfunc/src/arm_ramfunc.c
Original file line number Diff line number Diff line change
@@ -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.");
}
/**
* @}
*/
20 changes: 20 additions & 0 deletions tests/kernel/arm_ramfunc/src/main.c
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions tests/kernel/arm_ramfunc/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests:
arch.ramfunc:
filter: CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
tags: arm userspace
arch_whitelist: arm