aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile24
-rw-r--r--tests/core_test.c52
-rw-r--r--tests/test.c8
3 files changed, 84 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..43d4134
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,24 @@
+DEBUG := #-DDEBUG
+
+LIB430COREDIR = ..
+
+TEST_CSRC = test.c
+TEST_OUT = $(patsubst %.c,%.o,$(TEST_CSRC))
+
+all: $(LIB430COREDIR)/lib430core.a $(TEST_OUT)
+
+$(LIB430COREDIR)/lib430core.a:
+ @$(MAKE) -C ..
+
+.c.o:
+ @echo "Testing" $< "..."
+ @msp430-elf32-gcc -T../link.ld $< -o tmp.elf -nostdlib -lgcc -lc
+ @msp430-elf32-objcopy -Obinary tmp.elf tmp.bin
+ @echo "#define TESTBIN \\" > test.h
+ @od -t x1 tmp.bin | awk '{for (i=2; i<=NF; i++) printf "0x" $$i ", "}' >> test.h
+ @printf "\n#define TESTSIZE %u \n" $$(msp430-elf32-objdump tmp.elf -Dj .text | grep -E "^\s+[0-9a-fA-F]+:" | wc -l) >> test.h
+ @echo >> test.h
+ @gcc -Os -ggdb -g3 -Wall -W -pedantic $(DEBUG) -I../src -o tmp \
+ core_test.c -L$(LIB430COREDIR) -l430core
+ @./tmp > log
+ @rm log tmp.elf tmp.bin tmp test.h
diff --git a/tests/core_test.c b/tests/core_test.c
new file mode 100644
index 0000000..08e2650
--- /dev/null
+++ b/tests/core_test.c
@@ -0,0 +1,52 @@
+#include "core.h"
+#include "test.h"
+
+#include <stdio.h>
+
+//#define DEBUG
+
+#ifdef DEBUG
+static void dump_state(msp430_t *state)
+{
+ puts("MSP430 dump state:");
+ printf("R0/PC: 0x%04x R1/SP: 0x%04x R2/SR: 0x%04x R3: 0x%04x\n",
+ state->reg[0], state->reg[1], state->reg[2], state->reg[3]);
+ printf("R4: 0x%04x R5: 0x%04x R6: 0x%04x R7: 0x%04x\n",
+ state->reg[4], state->reg[5], state->reg[6], state->reg[7]);
+ printf("R8: 0x%04x R9: 0x%04x R10: 0x%04x R11: 0x%04x\n",
+ state->reg[8], state->reg[9], state->reg[10], state->reg[11]);
+ printf("R12: 0x%04x R13: 0x%04x R14: 0x%04x R15: 0x%04x\n\n",
+ state->reg[12], state->reg[13], state->reg[14], state->reg[15]);
+}
+#endif // DEBUG
+
+static uint8_t mem[0x10000] = {
+ TESTBIN
+};
+
+int main()
+{
+ msp430_t state;
+
+ msp430_init_state(&state, mem);
+
+#ifdef DEBUG
+ dump_state(&state);
+#endif // DEBUG
+ int r;
+ do {
+ r = msp430_do_cycle(&state);
+ if (r < 0) {
+ printf("Failed to execute near PC=0x%04x!\n", state.reg[0]);
+ return 1;
+ //break;
+ }
+
+#ifdef DEBUG
+ dump_state(&state);
+#endif // DEBUG
+ } while (r != 1);
+
+ return 0;
+}
+
diff --git a/tests/test.c b/tests/test.c
new file mode 100644
index 0000000..8eb344a
--- /dev/null
+++ b/tests/test.c
@@ -0,0 +1,8 @@
+int main()
+{
+ volatile int *mem = (int *)0x200;
+ *mem = 24;
+ for (int i = 0; i < 8; ++i)
+ *mem += 2;
+ return *mem;
+}