Skip to content

Commit

Permalink
tests: arm: adding a new test-suite for HardFault validation
Browse files Browse the repository at this point in the history
Adding a new test-suite for HardFault validation,
for Cortex-M Mainline architecture.

Signed-off-by: Ioannis Glaropoulos <[email protected]>
  • Loading branch information
ioannisg authored and cfriedt committed Jul 29, 2021
1 parent f795672 commit 453ce7b
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/arch/arm/arm_hardfault_validation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(arm_hardfault_validation)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
64 changes: 64 additions & 0 deletions tests/arch/arm/arm_hardfault_validation/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Title: Test to verify the behavior of HardFault (ARM Only)

Description:

This test verifies the Cortex-M HardFault escalation. 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:

make run

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

Troubleshooting:

Problems caused by out-dated project information can be addressed by
issuing one of the following commands then rebuilding the project:

make clean # discard results of previous builds
# but keep existing configuration info
or
make pristine # discard results of previous builds
# and restore pre-defined configuration info

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

Sample Output:

*** Booting Zephyr OS build zephyr-v2.6.0-482-g9daa69b212cd ***
Running test suite arm_hardfault_validation
===================================================================
START - test_arm_hardfault
E: r0/a1: 0x00000004 r1/a2: 0x00000000 r2/a3: 0x00000004
E: r3/a4: 0x20000000 r12/ip: 0x00000000 r14/lr: 0x000029fb
E: xpsr: 0x41000000
E: Faulting instruction address (r15/pc): 0x0000079e
E: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
E: Current thread: 0x20000070 (test_arm_hardfault)
Caught system error -- reason 4
ASSERTION FAIL [0] @ ../src/arm_hardfault.c:42
Assert occurring inside kernel panic
E: ***** HARD FAULT *****
E: Fault escalation (see below)
E: ARCH_EXCEPT with reason 4

E: r0/a1: 0x00000004 r1/a2: 0x0000002a r2/a3: 0x00000001
E: r3/a4: 0x000016f9 r12/ip: 0xa0000000 r14/lr: 0x0000075f
E: xpsr: 0x4100000b
E: Faulting instruction address (r15/pc): 0x00005d1e
E: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
E: Fault during interrupt handling

E: Current thread: 0x20000070 (test_arm_hardfault)
Caught system error -- reason 4
PASS - test_arm_hardfault in 0.79 seconds
===================================================================
Test suite arm_hardfault_validation succeeded
===================================================================
PROJECT EXECUTION SUCCESSFUL
1 change: 1 addition & 0 deletions tests/arch/arm/arm_hardfault_validation/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_ZTEST=y
53 changes: 53 additions & 0 deletions tests/arch/arm/arm_hardfault_validation/src/arm_hardfault.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <sys/printk.h>
#include <sys/reboot.h>
#include <arch/arm/aarch32/cortex_m/cmsis.h>
#include <ztest.h>
#include <tc_util.h>

static volatile int expected_reason = -1;

void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf)
{
static bool triggered_synchronous_svc;

TC_PRINT("Caught system error -- reason %d\n", reason);

if (expected_reason == -1) {
printk("Was not expecting a crash\n");
k_fatal_halt(reason);
}

if (reason != expected_reason) {
printk("Wrong crash type got %d expected %d\n", reason,
expected_reason);
k_fatal_halt(reason);
}

/* Fault validation succeeded */

if (triggered_synchronous_svc == false) {
triggered_synchronous_svc = true;

/* Trigger a new CPU runtime error from
* inside the current runtime error
*/
expected_reason = K_ERR_KERNEL_PANIC;
__ASSERT(0,
"Assert occurring inside kernel panic");
}

expected_reason = -1;
}
void test_arm_hardfault(void)
{
expected_reason = K_ERR_KERNEL_PANIC;

k_panic();
}
16 changes: 16 additions & 0 deletions tests/arch/arm/arm_hardfault_validation/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <ztest.h>
extern void test_arm_hardfault(void);

/**test case main entry*/
void test_main(void)
{
ztest_test_suite(arm_hardfault_validation,
ztest_unit_test(test_arm_hardfault));
ztest_run_test_suite(arm_hardfault_validation);
}
5 changes: 5 additions & 0 deletions tests/arch/arm/arm_hardfault_validation/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests:
arch.interrupt.arm.hardfault_validation:
filter: not CONFIG_TRUSTED_EXECUTION_NONSECURE and CONFIG_ARMV7_M_ARMV8_M_MAINLINE
arch_allow: arm
tags: arm

0 comments on commit 453ce7b

Please sign in to comment.