diff --git a/ports/arm/platforms/dm36x/Makefile b/ports/arm/platforms/dm36x/Makefile index afb4762..eae663b 100644 --- a/ports/arm/platforms/dm36x/Makefile +++ b/ports/arm/platforms/dm36x/Makefile @@ -4,6 +4,9 @@ # Build all test applications: # make +# +# Run all tests communicating via UART +# make tests # Location of build tools and atomthreads sources KERNEL_DIR=../../../../kernel @@ -12,6 +15,15 @@ PORT_DIR=../.. CC=arm-none-eabi-gcc OBJCOPY=arm-none-eabi-objcopy +# Location of TFTP root folder for running tests via U-Boot/TFTP. +# Note, you may need to run the Makefile as root in order to write +# to this folder. +TESTS_TFTPROOT=/var/lib/tftpboot + +# TTY device and baudrate for automated tests. +TESTS_TTYDEV=/dev/ttyUSB0 +TESTS_TTYBAUD=115200 + # Enable stack-checking. #STACK_CHECK=true @@ -128,3 +140,11 @@ doxygen: doxygen ../../Doxyfile doxygen ./Doxyfile +# Run tests on target with expect and serial output +phony_test_bins = $(addsuffix .sim, $(TEST_BINS)) +tests: $(phony_test_bins) +.PHONY: tests $(phony_test_bins) +$(phony_test_bins): + cp $(BUILD_DIR)/$(basename $@) $(TESTS_TFTPROOT)/test.bin + @echo Running test $(basename $@) + ./run_test.exp $(TESTS_TTYDEV) $(TESTS_TTYBAUD) diff --git a/ports/arm/platforms/dm36x/run_test.exp b/ports/arm/platforms/dm36x/run_test.exp new file mode 100755 index 0000000..91935b6 --- /dev/null +++ b/ports/arm/platforms/dm36x/run_test.exp @@ -0,0 +1,50 @@ +#!/usr/bin/env expect + +# Expect script to check an automated test's results via a serial port +# and check for successful completion. +# +# You are expected to set the target's U-boot up to automatically load +# the app on your TFTP server called "test.bin". Before this script is +# started the Makefile should have copied the next test binary to the +# file "test.bin" in your TFTP root folder. The user must sit and +# hit the reset button after every test completion in order to make +# the board load and run the next test.bin file. +# +# Arguments: +# +# Returns 0 on successful test run, 1 on failure + +# Set the serial port baudrate +stty [lindex $argv 1] < [lindex $argv 0] + +# Start the test +spawn cat [lindex $argv 0] +puts "Ready: reset the target!" + +# Expect to see the test starting within 60 seconds (give long enough +# for user to reset the board after running the last test). +set timeout 60 + +# Wait for the test to start ("Go") +expect { + "Go\r" { + 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\r" { puts "Test passed"; exit 0 } + "Fail\r" { 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 + } +} +