aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Davidsaver <mdavidsaver@gmail.com>2016-07-09 13:28:01 -0400
committerMichael Davidsaver <mdavidsaver@gmail.com>2016-07-09 13:28:01 -0400
commitbf5faf03a3f45d4fd81e09b80d76c0f55cddbba0 (patch)
tree273c165c22bfbf36cdb3b9e6b4cef75be3adcf5b
parented5def7f7332d9e6e74293000b1794720b597fb4 (diff)
reformat test5
-rw-r--r--Makefile2
-rwxr-xr-xruntests.sh1
-rw-r--r--test5.c119
3 files changed, 56 insertions, 66 deletions
diff --git a/Makefile b/Makefile
index 9e764f6..09d5eb4 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ all: test12-kern.bin
test1-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o testme.o test1.o
test3-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test3.o
test4-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o testme.o test4.o
-test5-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test5.o
+test5-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o testme.o test5.o
test6-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test6.o
test7-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test7.o
test8-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test8.o inst_skip.o
diff --git a/runtests.sh b/runtests.sh
index 26e3573..3e68052 100755
--- a/runtests.sh
+++ b/runtests.sh
@@ -37,4 +37,5 @@ dotest test1-kern.bin
dotest test9-kern.bin
dotest test10-kern.bin
dotest test4-kern.bin
+dotest test5-kern.bin
exit $RET
diff --git a/test5.c b/test5.c
index 9365da9..86cb13c 100644
--- a/test5.c
+++ b/test5.c
@@ -1,25 +1,24 @@
/* Test Mode/Stack changes
*/
#include "armv7m.h"
-
-extern char _main_stack_top, _proc_stack_top;
-extern char _main_stack_bot, _proc_stack_bot;
+#include "testme.h"
static
-volatile unsigned test;
+unsigned testseq;
-static
-void test_equal(const char *msg, uint32_t lhs, uint32_t rhs)
+#define SEQ() __atomic_add_fetch(&testseq, 1, __ATOMIC_RELAXED)
+
+#define CHECK_SEQ(N) testEqI(N, SEQ(), "SEQ " #N)
+
+static inline
+void test_equal(const char *m, uint32_t expect, uint32_t actual)
{
- puts(lhs==rhs ? "ok - " : "fail - ");
- puthex(lhs);
- puts(" == ");
- puthex(rhs);
- puts(" # ");
- puts(msg);
- putc('\n');
+ testEqI(expect, actual, m);
}
+extern char _main_stack_top, _proc_stack_top;
+extern char _main_stack_bot, _proc_stack_bot;
+
static
void show_control(unsigned ectrl, unsigned evect)
{
@@ -29,9 +28,7 @@ void show_control(unsigned ectrl, unsigned evect)
__asm__ ("mov %0,sp" : "=r"(sp) ::);
__asm__ ("mrs %0,IPSR" : "=r"(avect) ::);
__asm__ ("mrs %0,CONTROL" : "=r"(actrl) ::);
- puts(" SP ");
- puthex((uint32_t)sp);
- putc('\n');
+ testDiag("SP %p", sp);
test_equal("CONTROL", ectrl, actrl);
test_equal("IPSR", evect, avect);
@@ -41,17 +38,12 @@ void show_control(unsigned ectrl, unsigned evect)
else if(sp>&_proc_stack_bot && sp<=&_proc_stack_top)
instack = 2;
else {
- puts("fail - Corrupt SP ");
- puthex((uint32_t)sp);
- putc('\n');
+ testFail("fail - Corrupt SP %p", sp);
return;
}
- if((avect>0 && instack==0) || (avect==0 && (actrl&2)==instack))
- puts("ok - stack ");
- else
- puts("fail - stack ");
- putc(instack?'2':'0');
- putc('\n');
+ testOk((avect>0 && instack==0) || (avect==0 && (actrl&2)==instack),
+ "stack%c, avect=%x instack=%x actrl=%x", instack?'2':'0',
+ (unsigned)avect, (unsigned)instack, (unsigned)actrl);
}
static
@@ -70,27 +62,25 @@ void show_masks(unsigned expect)
static
void svc(void)
{
+ unsigned test = SEQ();
+ printk("# in SVC SEQ %u\n", test);
switch(test) {
case 1:
- puts("2. SVC\n");
show_control(0, 11);
break;
- case 2:
- puts("6. SVC\n");
+ case 3:
show_control(0, 11);
break;
- case 3:
- puts("10. SVC\n");
+ case 5:
show_control(1, 11);
break;
- case 4:
- puts("15. SVC\n");
+ case 7:
show_masks(0);
__asm__ volatile ("cpsid i" :::);
show_masks(1);
break;
default:
- puts("Fail SVC\n");
+ testFail("Fail SVC\n");
abort();
}
}
@@ -98,15 +88,16 @@ void svc(void)
static
void hard(void)
{
- if(test==5) {
+ unsigned test = SEQ();
+ testDiag("HARDFAULT %u", test);
+ if(test==9) {
+ testDiag("Set CONTROL=0");
uint32_t val = 0;
- puts("18. HardFault\n");
__asm__ volatile ("msr CONTROL, %0" :: "r"(val):);
- test = 6;
- return;
+ } else {
+ testFail("Unexpected HardFault SEQ %u", test);
+ abort();
}
- puts("Unexpected HardFault\n");
- abort();
}
void main(void)
@@ -114,84 +105,82 @@ void main(void)
run_table.svc = svc;
run_table.hard = hard;
+ testInit(45);
+
{
uint32_t temp = (uint32_t)&_proc_stack_top;
__asm__ volatile ("msr PSP,%0" :: "r"(temp) :);
}
- puts(" MSP ");
- puthex((uint32_t)&_main_stack_top);
- puts("\n PSP ");
- puthex((uint32_t)&_proc_stack_top);
- putc('\n');
+ testDiag("MSP=%p PSP=%p", &_main_stack_top, &_proc_stack_top);
show_control(0, 0);
- test = 1;
- puts("1. Start, trigger SVC\n");
+ testDiag("Start, trigger SVC");
CPSIE(if);
SVC(42);
- puts("3. Back in main\n");
+ testDiag("Back in main");
+ CHECK_SEQ(2);
show_control(0, 0);
- puts("4. Priv w/ proc stack\n");
+ testDiag("Priv w/ proc stack");
{
uint32_t val = 2;
__asm__ volatile ("msr CONTROL,%0" :: "r"(val):);
}
show_control(2, 0);
- test = 2;
- puts("5. trigger SVC\n");
+ testDiag("trigger SVC");
SVC(42);
- puts("7. Back in main\n");
+ testDiag("Back in main");
+ CHECK_SEQ(4);
show_control(2, 0);
- test = 3;
- puts("8. Drop privlage\n");
+ testDiag("Drop privlage");
{
uint32_t val = 3;
__asm__ volatile ("msr CONTROL,%0" :: "r"(val):);
}
show_control(3, 0);
- puts("9. trigger SVC\n");
+ testDiag("trigger SVC");
SVC(42);
- puts("11. Back in main\n");
+ testDiag("Back in main");
+ CHECK_SEQ(6);
show_control(3, 0);
- puts("12. Try to restore privlage and switch stack (should be noop)\n");
+ testDiag("Try to restore privlage and switch stack (should be noop)");
{
uint32_t val = 0;
__asm__ volatile ("msr CONTROL,%0" :: "r"(val):);
}
show_control(3, 0);
- test = 4;
- puts("13. Try to set masks\n");
+ testDiag("Try to set masks");
CPSID(if);
show_masks(0); /* doesn't work */
- puts("14. trigger SVC\n");
+ testDiag("trigger SVC");
SVC(42);
- puts("16. Back in main\n");
+ testDiag("Back in main");
+ CHECK_SEQ(8);
show_masks(0); /* unprivlaged doesn't see mask */
- test = 5;
- puts("17. trigger HardFault (restores priv)\n");
+ testDiag("trigger HardFault (restores priv)");
SVC(42);
- puts("19. Back in main\n");
+ testDiag("Back in main");
+ CHECK_SEQ(10);
show_control(2, 0);
- puts("restore MSP\n");
+ testDiag("restore MSP");
{
uint32_t val = 0;
__asm__ volatile ("msr CONTROL,%0" :: "r"(val):);
}
show_control(0, 0);
- puts("Done.\n");
+ testDiag("Done.");
}