tests: Cleanup the test harnesses
[simavr] / tests / Makefile
1 #
2 # This makefile takes each "at*" file, extracts it's part name
3 # And compiles it into an ELF binary.
4 # It also disassembles it for debugging purposes.
5
6 #       Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
7 #
8 #       This file is part of simavr.
9 #
10 #       simavr is free software: you can redistribute it and/or modify
11 #       it under the terms of the GNU General Public License as published by
12 #       the Free Software Foundation, either version 3 of the License, or
13 #       (at your option) any later version.
14 #
15 #       simavr is distributed in the hope that it will be useful,
16 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #       GNU General Public License for more details.
19 #
20 #       You should have received a copy of the GNU General Public License
21 #       along with simavr.  If not, see <http://www.gnu.org/licenses/>.
22
23
24 SHELL           = /bin/bash
25
26 sources         := $(wildcard at*.c)
27 simavr          = ..
28
29 IPATH           += ${simavr}/include
30 IPATH           += ${simavr}/simavr/sim
31 CFLAGS          += -Wall
32 LDFLAGS         += -L${simavr}/simavr/${OBJ} -lsimavr
33
34 tests_src       = ${wildcard test_*.c}
35 tests           = ${patsubst %.c, ${OBJ}/%.tst, ${tests_src}}
36
37 all: obj axf tests
38
39 include ../Makefile.common
40
41 tests:  ${tests}
42         
43 axf: ${sources:.c=.axf}
44         
45
46 ${OBJ}/%.tst: tests.c %.c
47 ifeq ($(V),1)
48         $(CC) -MMD ${CFLAGS}  ${LFLAGS} -o $@ $^ $(LDFLAGS)
49 else
50         @echo TST $@
51         @$(CC) -MMD ${CFLAGS}  ${LFLAGS} -o $@ $^ $(LDFLAGS)
52 endif
53
54 run_tests: all
55         @export LD_LIBRARY_PATH=${simavr}/simavr/${OBJ} ;\
56         num_failed=0 ;\
57         num_run=0 ;\
58         for test in ${OBJ}/test_*.tst; do \
59             num_run=$$(($$num_run+1)) ;\
60             if ! $$test; then \
61                         echo "$$test returned with exit value $$?." ;\
62                         num_failed=$$(($$num_failed+1)) ;\
63             fi ;\
64         done ;\
65         echo "Tests run: $$num_run  Successes: $$(($$num_run-$num_failed)) Failures: $$num_failed"
66
67 clean: clean-${OBJ}
68         rm -f *.axf