Fixes for tests/Makefile.
[tinycc/kirr.git] / tests / Makefile
bloba608c18850df4474616477d231c576207c805dd5
2 # Tiny C Compiler Makefile - tests
5 # what tests to run
6 TESTS = libtest test3
8 # these should work too
9 # TESTS += test1 test2 speed
11 # these don't work as they should
12 # TESTS += test4 btest asmtest
15 TOP = ..
16 include $(TOP)/Makefile
18 # run local version of tcc with local libraries and includes
19 TCC = ../tcc -B..
20 RUN_TCC = $(TARGET) -run ../tcc.c -B..
21 DISAS=objdump -d
23 all test : $(TESTS)
25 # make sure that tcc exists
26 $(TESTS) : ../tcc
27 ../tcc ../libtcc.a :
28 $(MAKE) -C ..
30 # libtcc test
31 libtest: libtcc_test$(EXESUF)
32 @echo ------------ $@ ------------
33 ./libtcc_test lib_path=..
35 libtcc_test$(EXESUF): libtcc_test.c ../libtcc.a
36 $(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS)
38 # test.ref - generate using gcc
39 test.ref: tcctest.c
40 $(CC) -o tcctest.gcc $< -w -I.. -I../include $(CFLAGS)
41 ./tcctest.gcc > $@
43 # auto test
44 test1: test.ref
45 @echo ------------ $@ ------------
46 $(TCC) -run tcctest.c > test.out1
47 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
49 # iterated test2 (compile tcc then compile tcctest.c !)
50 test2: test.ref
51 @echo ------------ $@ ------------
52 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
53 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
55 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
56 test3: test.ref
57 @echo ------------ $@ ------------
58 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
59 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
61 # binary output test
62 test4: test.ref
63 @echo ------------ $@ ------------
64 # dynamic output
65 $(TCC) -o tcctest1 tcctest.c
66 ./tcctest1 > test1.out
67 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
68 # object + link output
69 $(TCC) -c -o tcctest3.o tcctest.c
70 $(TCC) -o tcctest3 tcctest3.o
71 ./tcctest3 > test3.out
72 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
73 # static output
74 $(TCC) -static -o tcctest2 tcctest.c
75 ./tcctest2 > test2.out
76 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
77 # dynamic output + bound check
78 $(TCC) -b -o tcctest4 tcctest.c
79 ./tcctest4 > test4.out
80 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
82 # memory and bound check auto test
83 BOUNDS_OK = 1 4 8 10
84 BOUNDS_FAIL= 2 5 7 9 11 12 13
86 btest: boundtest.c
87 @echo ------------ $@ ------------
88 @for i in $(BOUNDS_OK); do \
89 if $(TCC) -b -run boundtest.c $$i ; then \
90 /bin/true ; \
91 else\
92 echo Failed positive test $$i ; exit 1 ; \
93 fi ;\
94 done ;\
95 for i in $(BOUNDS_FAIL); do \
96 if $(TCC) -b -run boundtest.c $$i ; then \
97 echo Failed negative test $$i ; exit 1 ;\
98 else\
99 /bin/true ; \
100 fi ;\
101 done ;\
102 echo Bound test OK
104 # speed test
105 speed: ex2 ex3
106 @echo ------------ $@ ------------
107 time ./ex2 1238 2 3 4 10 13 4
108 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
109 time ./ex3 35
110 time $(TCC) -run ../examples/ex3.c 35
112 ex%: ../examples/ex%.c
113 $(CC) -o $@ $< $(CFLAGS)
115 # tiny assembler testing
116 asmtest.ref: asmtest.S
117 $(CC) -o asmtest.ref.o -c asmtest.S
118 objdump -D asmtest.ref.o > $@
120 asmtest: asmtest.ref
121 @echo ------------ $@ ------------
122 $(TCC) -c asmtest.S
123 objdump -D asmtest.o > $@
124 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
126 # targets for development
127 %.bin: %.c tcc
128 $(TCC) -g -o $@ $<
129 $(DISAS) $@
131 instr: instr.o
132 objdump -d instr.o
134 instr.o: instr.S
135 $(CC) -o $@ -c $< -O2 -Wall -g
137 cache: tcc_g
138 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
139 vg_annotate tcc.c > /tmp/linpack.cache.log
141 # clean
142 clean:
143 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
144 tcctest[1234] ex? libtcc_test tcc_g