diff options
Diffstat (limited to 'test8.c')
-rw-r--r-- | test8.c | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -31,10 +31,44 @@ void try(volatile char *p) static volatile unsigned expect_fault = EXPECT_NO_FAULT; +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +static const char *expect_fault_name[] = { + [EXPECT_NO_FAULT] = "no fault", + [EXPECT_MEMFAULT] = "MemManage fault", + [EXPECT_TAKEN_MEMFAULT] = "MemManage fault taken", + [EXPECT_HARDFAULT] = "HardFault", + [EXPECT_TAKEN_HARDFAULT] = "HardFault taken", +}; + +const char *faultname(unsigned int f) +{ + if (f > ARRAY_SIZE(expect_fault_name) || !expect_fault_name[f]) { + /* This would be a test case code error */ + testDiag("faultname passed bad expect_fault state 0x%x", f); + abort(); + } + return expect_fault_name[f]; +} + static void checkfault(unsigned v) { - testEqI(v, expect_fault, "fault state"); + if (v == expect_fault) { + testPass("%s as expected", faultname(v)); + } else { + int curstate = expect_fault; + + /* If expect_fault is still EXPECT_MEMFAULT or EXPECT_HARDFAULT + * then we didn't actually take a fault, so report that as + * "no fault". + */ + if (curstate == EXPECT_MEMFAULT || curstate == EXPECT_HARDFAULT) { + curstate = EXPECT_NO_FAULT; + } + + testFail("expected %s but %s", faultname(v), faultname(curstate)); + } } void hard(uint32_t *sp) |