diff --git a/ports/cortex-m/boards/qemu/Makefile.include b/ports/cortex-m/boards/qemu/Makefile.include index 18800ab..02c7c94 100644 --- a/ports/cortex-m/boards/qemu/Makefile.include +++ b/ports/cortex-m/boards/qemu/Makefile.include @@ -12,4 +12,16 @@ OOCD_INTERFACE ?= stlink-v2-1 OOCD_BOARD ?= st_nucleo_f103rb objs += board_setup.o -# aobjs += helloworld.o \ No newline at end of file +# aobjs += helloworld.o + +# Special requirements for running automated tests with QEMU + +QEMU ?= qemu-system-gnuarmeclipse +.DEFAULT_GOAL := all +.SECONDEXPANSION: + +.PHONY: qemutests +qemutests: $$(addsuffix .sim, $$(sort $$(build_telfs))) + +%.sim: $$(basename $$@) + boards/qemu/run_test.exp $(QEMU) $(*) diff --git a/ports/cortex-m/boards/qemu/README.md b/ports/cortex-m/boards/qemu/README.md index a7b3aee..29889d8 100644 --- a/ports/cortex-m/boards/qemu/README.md +++ b/ports/cortex-m/boards/qemu/README.md @@ -15,7 +15,17 @@ a usable target. After installing you can use it to run the test binaries like this: ``` -qemu-system-gnuarmeclipse -nographic -monitor null -serial stdio \ - -semihosting --semihosting-config target=native \ - --machine NUCLEO-F103RB --kernel build/kern1.elf --verbose +qemu-system-gnuarmeclipse -nographic -monitor null \ + -semihosting --machine NUCLEO-F103RB \ + --verbose --kernel build/kern1.elf ``` + +The whole test suite can be run in an automatic way from the build system by +using the tool `expect`. + +``` +make BOARD=qemu QEMU=/path/to/your/qemu/binary qemutests +``` + +If your qemu-binary is called `qemu-system-gnuarmeclipse` and is located +in your search path, you can omit the `QEMU=...` part. diff --git a/ports/cortex-m/boards/qemu/run_test.exp b/ports/cortex-m/boards/qemu/run_test.exp new file mode 100755 index 0000000..c35ddf4 --- /dev/null +++ b/ports/cortex-m/boards/qemu/run_test.exp @@ -0,0 +1,40 @@ +#!/usr/bin/env expect + +# Expect script to run an automated test within the simulator (QEMU) and +# check for successful completion. +# +# Arguments: +# +# Returns 0 on successful test run within QEMU, 1 on failure + + +# Start the test +spawn [lindex $argv 0] -nographic -monitor null -semihosting \ + --machine NUCLEO-F103RB --kernel [lindex $argv 1] + +# Expect to see the test starting within 10 seconds +set timeout 10 + +# Wait for the test to start ("Go") +expect { + "Go" { + puts "Test started" + + # The test could take up to 3 minutes to complete once started + set timeout 180 + + # Now expect to see "Pass" or "Fail" within 3 minutes + expect { + "Pass" { puts "Test passed"; exit 0 } + "Fail" { puts "Test failed"; exit 1 } + timeout { puts "Test timed out without completing"; exit 1 } + } + } + + timeout { + # Didn't receive "Go" within 10 seconds + puts "Test failed to start ('Go' not seen)" + exit 1 + } +} +