aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-04-06 17:16:06 +0100
committerPeter Maydell <peter.maydell@linaro.org>2017-04-11 11:38:20 +0100
commit8c267e7892c0c2710e2708d9180eca3b8abcf6e6 (patch)
tree8ab06854fe1c7a4945779cac35ee0338deba3e3a
parent75d1021159cc6700e0c3cdaf3bfe8ae2c700d58c (diff)
test8: Provide nicer human-readable diagnostics for checkfault()
When checking whether we got the kind of fault we expected, provide a more easily human-readable description of what happened. Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--test8.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/test8.c b/test8.c
index 887cd4b..6e41c68 100644
--- a/test8.c
+++ b/test8.c
@@ -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)