diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2017-04-06 17:22:02 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2017-04-11 11:38:20 +0100 |
commit | 75d1021159cc6700e0c3cdaf3bfe8ae2c700d58c (patch) | |
tree | 0a9a37f2847f2787cc97768eb8f007d390100055 | |
parent | ca87b093d46dfc590fbebac68c7ae90ad050f3eb (diff) |
test8: Use symbolic constants for expect_fault values
Use symbolic constants for expect_fault values rather than hardcoded
magic numbers.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r-- | test8.c | 45 |
1 files changed, 25 insertions, 20 deletions
@@ -23,8 +23,13 @@ void try(volatile char *p) testDiag("Got %x", tval); } -static volatile -unsigned expect_fault = 1; +#define EXPECT_NO_FAULT 1 +#define EXPECT_MEMFAULT 2 +#define EXPECT_TAKEN_MEMFAULT 3 +#define EXPECT_HARDFAULT 10 +#define EXPECT_TAKEN_HARDFAULT 11 + +static volatile unsigned expect_fault = EXPECT_NO_FAULT; static void checkfault(unsigned v) @@ -35,12 +40,12 @@ void checkfault(unsigned v) void hard(uint32_t *sp) { testDiag("In HardFault handler"); - if(expect_fault==10) { + if(expect_fault==EXPECT_HARDFAULT) { sp = get_src_stack(sp); inst_skip(sp); testDiag("Trying access offlimits inside HardFault handler"); try(offlimits); - expect_fault = 11; + expect_fault = EXPECT_TAKEN_HARDFAULT; return; } testDiag("Unexpected HardFault!!"); @@ -64,10 +69,10 @@ void mem(uint32_t *sp) testDiag("In MemFault, Addr 0x%x, from 0x%x", addr, sp[6]); switch(expect_fault) { - case 2: /* expected */ - expect_fault = 3; + case EXPECT_MEMFAULT: + expect_fault = EXPECT_TAKEN_MEMFAULT; break; - case 1: + case EXPECT_NO_FAULT: testDiag("Unexpected MemFault!!"); abort(); default: @@ -139,7 +144,7 @@ void main(void) out32(SCB(0xd24), 1<<16); // enable MemFault with SHCSR testDiag("In Main"); - expect_fault = 1; + expect_fault = EXPECT_NO_FAULT; /* priority of entries is highest to lowest (0 checked last) */ @@ -157,55 +162,55 @@ void main(void) testDiag("Access offlimits with MPU disabled (should not fault)"); try(offlimits); - checkfault(1); + checkfault(EXPECT_NO_FAULT); testDiag("Enable MPU"); enable_mpu(1,1,0); asm("cpsie if"); - expect_fault = 2; + expect_fault = EXPECT_MEMFAULT; testDiag("Access offlimits with MPU enabled (should fault)"); try(offlimits); - checkfault(3); + checkfault(EXPECT_TAKEN_MEMFAULT); testDiag("In Main"); - expect_fault = 1; + expect_fault = EXPECT_NO_FAULT; testDiag("Access privonly (should not fault)"); try(privonly); - checkfault(1); + checkfault(EXPECT_NO_FAULT); testDiag("drop_priv"); - expect_fault = 2; + expect_fault = EXPECT_MEMFAULT; drop_priv(); testDiag("Access privonly as user (should fault)"); try(privonly); - checkfault(3); + checkfault(EXPECT_TAKEN_MEMFAULT); testDiag("Back in Main, regaining privilege"); asm("svc 1"); - expect_fault = 1; + expect_fault = EXPECT_NO_FAULT; testDiag("Access privonly as priv (should not fault)"); try(privonly); - checkfault(1); + checkfault(EXPECT_NO_FAULT); asm("cpsid i"); testDiag("Check escalation of MemManage to HardFault"); - expect_fault = 10; + expect_fault = EXPECT_HARDFAULT; try(offlimits); - checkfault(11); + checkfault(EXPECT_TAKEN_HARDFAULT); #if 0 /* don't try to test unrecoverable errors */ testDiag("Enable MPU w/ HFNMIENA"); enable_mpu(1,1,1); testDiag("fault to hardfault (will escalate to unrecoverable)"); - expect_fault = 10; + expect_fault = EXPECT_HARDFAULT; try(offlimits); testDiag("Shouldn't be here!"); #endif |