Add a test runner

This commit is contained in:
Romain Goyet
2015-05-03 14:02:25 +02:00
parent ea9bcc82e3
commit c314a1e296
3 changed files with 71 additions and 3 deletions

View File

@@ -7,11 +7,19 @@ CFLAGS=-march=armv7e-m -mcpu=cortex-m4 -mthumb -std=c99 -g -Iarch/stm32f429
CC=clang
CFLAGS=-target thumbv7em-unknown-eabi -mcpu=cortex-m4 -Iarch/stm32f429 -Wall
objs := boot/crt0.o src/blinky.o arch/stm32f429/registers/rcc.o arch/stm32f429/registers/gpio.o
objs := boot/crt0.o arch/stm32f429/registers/rcc.o arch/stm32f429/registers/gpio.o
default: boot.elf
run: boot.elf
$(GDB) -x gdb_script.gdb boot.elf
test: test.elf
$(GDB) -x test/gdb_script.gdb test.elf
test.elf: $(objs) test/runner.o
@$(LD) -T boot/stm32f429_flash.ld $(objs) test/runner.o -o $@
boot.hex: boot.elf
@echo "OBJCOPY $@"
@$(OBJCOPY) -O ihex boot.elf boot.hex
@@ -20,9 +28,9 @@ boot.bin: boot.elf
@echo "OBJCOPY $@"
@$(OBJCOPY) -O binary boot.elf boot.bin
boot.elf: $(objs)
boot.elf: $(objs) src/blinky.o
@echo "LD $@"
@$(LD) -T boot/stm32f429_flash.ld $(objs) -o $@
@$(LD) -T boot/stm32f429_flash.ld $(objs) src/blinky.o -o $@
%.o: %.c
@echo "CC $@"

14
test/gdb_script.gdb Normal file
View File

@@ -0,0 +1,14 @@
# Let's connect to OpenOCD
target remote localhost:3333
# Load our executable
load test.elf
# Tell OpenOCD to reset and halt
monitor reset halt
# Add a breakpoint
break debugger
# Launch the test suite
continue

46
test/runner.c Normal file
View File

@@ -0,0 +1,46 @@
#include <registers.h>
void assert(int condition);
void low_level_sleep(int iterations) {
for (int i=0;i<iterations;i++) {
}
}
void debugger() {
while(1) {
}
}
void halt(int success) {
RCC_AHB1ENR->GPIOGEN = 1;
if (success) {
GPIO_MODER(GPIOG)->MODER13 = GPIO_MODE_OUTPUT;
for (int i=0;i<5; i++) {
GPIO_ODR(GPIOG)->ODR13 = 0;
low_level_sleep(50000);
GPIO_ODR(GPIOG)->ODR13 = 1;
low_level_sleep(50000);
}
} else {
GPIO_MODER(GPIOG)->MODER14 = GPIO_MODE_OUTPUT;
for (int i=0;i<5; i++) {
GPIO_ODR(GPIOG)->ODR14 = 0;
low_level_sleep(50000);
GPIO_ODR(GPIOG)->ODR14 = 1;
low_level_sleep(50000);
}
}
debugger();
}
void assert(int condition) {
if (!condition) {
halt(0);
}
}
int main(int argc, char * argv[]) {
// Run assertions
halt(1);
}