Commit 9e4a403d authored by Michael Arnold's avatar Michael Arnold Committed by Carles Cufi
Browse files

tests: arch: Make ramfunc test generic and enable test for riscv arch



The ramfunc test can be reused for multiple architectures.

Signed-off-by: default avatarMichael Arnold <marnold@baumer.com>
parent f67c11cb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(arm_zero_latency_irqs)
project(zero_latency_irqs)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
+17 −9
Original line number Diff line number Diff line
Title: Test to verify code execution from SRAM for XIP images (ARM Only)
Title: Test to verify code execution from SRAM for XIP images (only on supported architectures with CONFIG_ARCH_HAS_RAMFUNC_SUPPORT=y)

Description:

This test verifies that we can define functions in SRAM (and
successfully execute them from SRAM) in ARM XIP images. It
successfully execute them from SRAM) in XIP images. It
also verifies that the .ramfunc section is accessible by
nPRIV code when building with support for user mode
(CONFIG_TEST_USERSPACE=y). Only for ARM Cortex-M targets.
user space code when building with support for user mode
(CONFIG_TEST_USERSPACE=y).

---------------------------------------------------------------------------

@@ -34,12 +34,20 @@ or

Sample Output:

***** Booting Zephyr OS build zephyr-v1.14.0-1726-gb95a71960622 *****
Running test suite arm_ramfunc
*** Booting Zephyr OS build zephyr-v3.4.0-4114-gadfd4017979f ***
Running TESTSUITE ramfunc
===================================================================
starting test - test_arm_ramfunc
PASS - test_arm_ramfunc
START - test_ramfunc
 PASS - test_ramfunc in 0.229 seconds
===================================================================
Test suite arm_ramfunc succeeded
TESTSUITE ramfunc succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [ramfunc]: pass = 1, fail = 0, skip = 0, total = 1 duration = 0.229 seconds
 - PASS - [ramfunc.test_ramfunc] duration = 0.229 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL
+5 −5
Original line number Diff line number Diff line
@@ -4,10 +4,10 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#if !defined(CONFIG_CPU_CORTEX_M)
  #error test can only run on Cortex-M MCUs
#endif

#include <zephyr/ztest.h>

ZTEST_SUITE(arm_ramfunc, NULL, NULL, NULL, NULL, NULL);
#if !defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT)
  #error test can only run on Cortex-M MCUs and RISC-V
#endif

ZTEST_SUITE(ramfunc, NULL, NULL, NULL, NULL, NULL);
+9 −9
Original line number Diff line number Diff line
@@ -10,12 +10,12 @@

static volatile int test_flag;

__ramfunc static void arm_ram_function(void)
__ramfunc static void ram_function(void)
{
	test_flag = 1;
}

ZTEST(arm_ramfunc, test_arm_ramfunc)
ZTEST(ramfunc, test_ramfunc)
{
	int init_flag, post_flag;

@@ -23,7 +23,7 @@ ZTEST(arm_ramfunc, test_arm_ramfunc)
	zassert_true(init_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
	 * inside SRAM, and that ram_function(.) is located inside
	 * the .ramfunc section.
	 */
	zassert_true((uint32_t)&__ramfunc_size != 0,
@@ -32,12 +32,12 @@ ZTEST(arm_ramfunc, test_arm_ramfunc)
			&& ((uint32_t)&__ramfunc_end < (uint32_t)&_image_ram_end),
			".ramfunc linker section not in RAM");
	zassert_true(
		(((uint32_t)&__ramfunc_start) <= (uint32_t)arm_ram_function) &&
		(((uint32_t)&__ramfunc_end) > (uint32_t)arm_ram_function),
		"arm_ram_function not loaded into .ramfunc");
		(((uint32_t)&__ramfunc_start) <= (uint32_t)ram_function) &&
		(((uint32_t)&__ramfunc_end) > (uint32_t)ram_function),
		"ram_function not loaded into .ramfunc");

	/* If we build with User Mode support, verify that the
	 * arm_ram_function(.) is user (read) accessible.
	 * ram_function(.) is user (read) accessible.
	 */
#if defined(CONFIG_USERSPACE)
	zassert_true(arch_buffer_validate((void *)&__ramfunc_start,
@@ -46,12 +46,12 @@ ZTEST(arm_ramfunc, test_arm_ramfunc)
#endif /* CONFIG_USERSPACE */

	/* Execute the function from SRAM. */
	arm_ram_function();
	ram_function();

	/* Verify that the function is executed successfully. */
	post_flag = test_flag;
	zassert_true(post_flag == 1,
		"arm_ram_function() execution failed.");
		"ram_function() execution failed.");
}
/**
 * @}
+5 −2
Original line number Diff line number Diff line
tests:
  arch.arm.ramfunc:
  arch.common.ramfunc:
    filter: CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
    tags:
      - arm
      - userspace
    arch_allow: arm
    arch_allow:
      - arm
      - riscv32
      - riscv64
    extra_configs:
      - CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=0