zephyr/samples/mpu/mpu_stack_guard_test
Sebastian Bøe 55ee53ce91 cmake: Prepend 'cmake_minimum_required()' into 'app' build scripts
Prepend the text 'cmake_minimum_required(VERSION 3.8.2)' into the
application and test build scripts.

Modern versions of CMake will spam users with a deprecation warning
when the toplevel CMakeLists.txt does not specify a CMake
version. This is documented in bug #8355.

To resolve this we include a cmake_minimum_required() line into the
toplevel build scripts. Additionally, cmake_minimum_required is
invoked from within boilerplate.cmake. The highest version will be
enforced.

This patch allows us to afterwards change CMake policy CMP000 from OLD
to NEW which in turn finally rids us of the verbose warning.

The extra boilerplate is considered more acceptable than the verbosity
of the CMP0000 policy.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-08-15 04:06:50 -07:00
..
src kbuild: Removed KBuild 2017-11-08 20:00:22 -05:00
CMakeLists.txt cmake: Prepend 'cmake_minimum_required()' into 'app' build scripts 2018-08-15 04:06:50 -07:00
prj_stack_guard.conf mpu_stack_guard_test: add more thread for test 2017-08-09 13:36:09 -05:00
prj.conf samples: move all MPU samples into one directory 2017-06-19 21:23:11 -04:00
README.rst samples: mmu: Convert doc to CMake 2017-11-12 21:13:23 -05:00
sample.yaml mpu_stack_guard_test: Disable on xtensa 2018-02-16 10:44:29 -05:00

.. _mpu_stack_guard_test:

MPU Stack Guard Test
####################

Overview
********

This is a simple application that demonstrates basic thread stack guarding on
the supported platforms.
A thread spawned by the main task recursively calls a function that fills the
thread stack up to where it overwrites a preposed canary.
If the MPU is enabled and the Stack Guard feature is present the test succeeds
because an MEM Faults exception prevents the canary from being overwritten.
If the MPU is disabled the test fails because the canary is overwritten.

Building and Running
********************

This project outputs to the console.
To build the test with the MPU disabled:

.. zephyr-app-commands::
   :zephyr-app: samples/mpu/mpu_stack_guard_test
   :board: v2m_beetle
   :goals: build flash
   :compact:

To build the test with the MPU enabled and the stack guard feature present:

.. zephyr-app-commands::
   :zephyr-app: samples/mpu/mpu_stack_guard_test
   :board: v2m_beetle
   :conf: prj_stack_guard.conf
   :goals: build flash
   :compact:

Sample Output
=============

With the MPU enabled but the stack guard feature disabled:

.. code-block:: console

    ***** BOOTING ZEPHYR OS v1.8.99 - BUILD: Jun 15 2017 23:12:13 *****
    STACK_ALIGN 4
    MPU STACK GUARD Test
    Canary Initial Value = 0xf0cacc1a threads 0x20000b9c
    Canary = 0xfffffff5     Test not passed.
    ***** MPU FAULT *****
      Executing thread ID (thread): 0x20000b9c
      Faulting instruction address:  0x80025b0
      Data Access Violation
      Address: 0x8000edb
    Fatal fault in thread 0x20000b9c! Aborting.
    ***** HARD FAULT *****
      Fault escalation (see below)
    ***** MPU FAULT *****
      Executing thread ID (thread): 0x20000b9c
      Faulting instruction address:  0x8001db6
      Data Access Violation
      Address: 0x8000edb
    Fatal fault in ISR! Spinning...

With the MPU enabled and the stack guard feature enabled:

.. code-block:: console

    ***** BOOTING ZEPHYR OS v1.8.99 - BUILD: Jun 15 2017 23:05:56 *****
    STACK_ALIGN 20
    MPU STACK GUARD Test
    Canary Initial Value = 0xf0cacc1a threads 0x20000be0
    ***** MPU FAULT *****
      Executing thread ID (thread): 0x20000be0
      Faulting instruction address:  0x8001dc2
      Stacking error
    Fatal fault in thread 0x20000be0! Aborting.