timer: Avoid infinite cycle timer on TCNT write
[simavr] / tests / Makefile
index 0cf07f2..7bc3d34 100644 (file)
@@ -1,9 +1,9 @@
 #
-# This makefile take each "at*" file, extracts it's part name
-# And compile it into an ELF binary.
-# It also disassemble it for debugging purposes.
+# This makefile takes each "at*" file, extracts it's part name
+# And compiles it into an ELF binary.
+# It also disassembles it for debugging purposes.
 # 
-#      Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
+#      Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 #
 #      This file is part of simavr.
 #
 #      You should have received a copy of the GNU General Public License
 #      along with simavr.  If not, see <http://www.gnu.org/licenses/>.
 
+sources                := $(wildcard at*.c)
+simavr                 = ..
 
-SHELL   = /bin/bash
+IPATH          += ${simavr}/include
+IPATH          += ${simavr}/simavr/sim
 
-sources                := $(wildcard at*.c)
+tests_src      = ${wildcard test_*.c}
+tests          = ${patsubst %.c, ${OBJ}/%.tst, ${tests_src}}
 
-all :  ${sources:.c=.axf}
-# if you want hex files
-#all : ${sources:.c=.hex}
-# if you need assembler output
-#all :  ${sources:.c=.s}  
+all: obj axf tests
 
 include ../Makefile.common
 
-clean:
-       rm -f *.hex *.o *.axf *.s
+tests: ${tests}
+       
+axf: ${sources:.c=.axf}
+       
+
+${OBJ}/%.tst: tests.c %.c
+ifeq ($(V),1)
+       $(CC) -MMD ${CPPFLAGS} ${CFLAGS} ${LFLAGS} -o $@ ${patsubst %.h,, ${^}} $(LDFLAGS)
+else
+       @echo TST $@
+       @$(CC) -MMD ${CPPFLAGS} ${CFLAGS} ${LFLAGS} -o $@ ${patsubst %.h,, ${^}} $(LDFLAGS)
+endif
+
+run_tests: all
+       @export LD_LIBRARY_PATH=${simavr}/simavr/${OBJ} ;\
+       num_failed=0 ;\
+       num_run=0 ;\
+       for test in ${OBJ}/test_*.tst; do \
+           num_run=$$(($$num_run+1)) ;\
+           if ! $$test; then \
+                       echo "$$test returned with exit value $$?." ;\
+                       num_failed=$$(($$num_failed+1)) ;\
+           fi ;\
+       done ;\
+       echo "Tests run: $$num_run  Successes: $$(($$num_run-$num_failed)) Failures: $$num_failed"
+
+clean: clean-${OBJ}
+       rm -f *.axf