
2 changed files with 119 additions and 0 deletions
@ -0,0 +1,41 @@
|
||||
APPLICATION = mpu_stack_guard
|
||||
include ../Makefile.tests_common |
||||
|
||||
BOARD_WHITELIST += arduino-due # cortex-m3
|
||||
BOARD_WHITELIST += arduino-zero # cortex-m0plus
|
||||
BOARD_WHITELIST += cc2538dk # cortex-m3
|
||||
BOARD_WHITELIST += cc2650stk # cortex-m3
|
||||
BOARD_WHITELIST += ek-lm4f120xl # cortex-m4f
|
||||
BOARD_WHITELIST += f4vi1 # cortex-m4f
|
||||
BOARD_WHITELIST += fox # cortex-m3
|
||||
BOARD_WHITELIST += frdm-k64f # cortex-m4
|
||||
BOARD_WHITELIST += iotlab-common # cortex-m3
|
||||
BOARD_WHITELIST += limifrog-v1 # cortex-m3
|
||||
BOARD_WHITELIST += mbed_lpc1768 # cortex-m3
|
||||
BOARD_WHITELIST += msbiot # cortex-m4f
|
||||
BOARD_WHITELIST += mulle # cortex-m4
|
||||
BOARD_WHITELIST += nrf52dk # cortex-m4f
|
||||
BOARD_WHITELIST += nucleo-f103 # cortex-m3
|
||||
BOARD_WHITELIST += nucleo-f207 # cortex-m3
|
||||
BOARD_WHITELIST += nucleo-f303 # cortex-m4f
|
||||
BOARD_WHITELIST += nucleo-f334 # cortex-m4f
|
||||
BOARD_WHITELIST += nucleo-f401 # cortex-m4f
|
||||
BOARD_WHITELIST += nucleo-f446 # cortex-m4f
|
||||
BOARD_WHITELIST += nucleo-l1 # cortex-m3
|
||||
BOARD_WHITELIST += openmote-cc2538 # cortex-m3
|
||||
BOARD_WHITELIST += pba-d-01-kw2x # cortex-m4
|
||||
BOARD_WHITELIST += remote # cortex-m3
|
||||
BOARD_WHITELIST += saml21-xpro # cortex-m0plus
|
||||
BOARD_WHITELIST += samr21-xpro # cortex-m0plus
|
||||
BOARD_WHITELIST += slwstk6220a # cortex-m4f
|
||||
BOARD_WHITELIST += sodaq-autonomo # cortex-m0plus
|
||||
BOARD_WHITELIST += spark-core # cortex-m3
|
||||
BOARD_WHITELIST += stm32f3discovery # cortex-m4f
|
||||
BOARD_WHITELIST += stm32f4discovery # cortex-m4f
|
||||
BOARD_WHITELIST += udoo # cortex-m3
|
||||
|
||||
CFLAGS += -DDEVELHELP
|
||||
|
||||
USEMODULE += mpu_stack_guard
|
||||
|
||||
include $(RIOTBASE)/Makefile.include |
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Loci Controls Inc. |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @ingroup tests |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief Test application for the mpu_stack_guard pseudo-module |
||||
* |
||||
* @author Ian Martin <ian@locicontrols.com> |
||||
* |
||||
* @} |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
|
||||
#include "cpu.h" |
||||
#include "thread.h" |
||||
|
||||
#define CANARY_VALUE 0xdeadbeef |
||||
|
||||
static struct { |
||||
unsigned int canary; |
||||
char stack[THREAD_STACKSIZE_MAIN]; |
||||
} buf; |
||||
|
||||
static int recurse(int counter) |
||||
{ |
||||
printf("counter =%4d, SP = 0x%08x, canary = 0x%08x\n", counter, (unsigned int)__get_PSP(), buf.canary); |
||||
|
||||
if (buf.canary != CANARY_VALUE) { |
||||
printf("canary = 0x%08x\nTest failed.\n", buf.canary); |
||||
|
||||
for (;;) { |
||||
thread_sleep(); |
||||
} |
||||
} |
||||
|
||||
counter++; |
||||
|
||||
/* Recursing twice here prevents the compiler from optimizing-out the recursion. */ |
||||
return recurse(counter) + recurse(counter); |
||||
} |
||||
|
||||
static void *thread(void *arg) |
||||
{ |
||||
(void) arg; |
||||
|
||||
recurse(0); |
||||
|
||||
return NULL; |
||||
} |
||||
|
||||
int main(void) |
||||
{ |
||||
puts("\nMPU Stack Guard Test\n"); |
||||
|
||||
puts("If the test fails, the canary value will change unexpectedly"); |
||||
puts("after ~150 iterations. If the test succeeds, the MEM MANAGE HANDLER"); |
||||
puts("will trigger a RIOT kernel panic before the canary value changes.\n"); |
||||
|
||||
#ifdef MODULE_MPU_STACK_GUARD |
||||
puts("The mpu_stack_guard module is present. Expect the test to succeed.\n"); |
||||
#else |
||||
puts("The mpu_stack_guard module is missing! Expect the test to fail.\n"); |
||||
#endif |
||||
|
||||
buf.canary = CANARY_VALUE; |
||||
thread_create(buf.stack, sizeof(buf.stack), THREAD_PRIORITY_MAIN - 1, 0, thread, NULL, "thread"); |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue