drop alloca #define
[tinycc.git] / tests / Makefile
blobddd493227b0c9092ba80429feda8ca500a105c4f
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 = $(NATIVE_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 cp -u ../include/tcclib.h .
41 $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS)
42 ./tcctest.gcc > $@
44 # auto test
45 test1: test.ref
46 @echo ------------ $@ ------------
47 $(TCC) -run tcctest.c > test.out1
48 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
50 # iterated test2 (compile tcc then compile tcctest.c !)
51 test2: test.ref
52 @echo ------------ $@ ------------
53 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
54 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
56 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
57 test3: test.ref
58 @echo ------------ $@ ------------
59 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
60 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
62 # binary output test
63 test4: test.ref
64 @echo ------------ $@ ------------
65 # dynamic output
66 $(TCC) -o tcctest1 tcctest.c
67 ./tcctest1 > test1.out
68 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
69 # object + link output
70 $(TCC) -c -o tcctest3.o tcctest.c
71 $(TCC) -o tcctest3 tcctest3.o
72 ./tcctest3 > test3.out
73 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
74 # static output
75 $(TCC) -static -o tcctest2 tcctest.c
76 ./tcctest2 > test2.out
77 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
78 # dynamic output + bound check
79 $(TCC) -b -o tcctest4 tcctest.c
80 ./tcctest4 > test4.out
81 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
83 # memory and bound check auto test
84 BOUNDS_OK = 1 4 8 10
85 BOUNDS_FAIL= 2 5 7 9 11 12 13
87 btest: boundtest.c
88 @echo ------------ $@ ------------
89 @for i in $(BOUNDS_OK); do \
90 if $(TCC) -b -run boundtest.c $$i ; then \
91 /bin/true ; \
92 else\
93 echo Failed positive test $$i ; exit 1 ; \
94 fi ;\
95 done ;\
96 for i in $(BOUNDS_FAIL); do \
97 if $(TCC) -b -run boundtest.c $$i ; then \
98 echo Failed negative test $$i ; exit 1 ;\
99 else\
100 /bin/true ; \
101 fi ;\
102 done ;\
103 echo Bound test OK
105 # speed test
106 speed: ex2 ex3
107 @echo ------------ $@ ------------
108 time ./ex2 1238 2 3 4 10 13 4
109 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
110 time ./ex3 35
111 time $(TCC) -run ../examples/ex3.c 35
113 ex%: ../examples/ex%.c
114 $(CC) -o $@ $< $(CFLAGS)
116 # tiny assembler testing
117 asmtest.ref: asmtest.S
118 $(CC) -o asmtest.ref.o -c asmtest.S
119 objdump -D asmtest.ref.o > $@
121 asmtest: asmtest.ref
122 @echo ------------ $@ ------------
123 $(TCC) -c asmtest.S
124 objdump -D asmtest.o > $@
125 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
127 # targets for development
128 %.bin: %.c tcc
129 $(TCC) -g -o $@ $<
130 $(DISAS) $@
132 instr: instr.o
133 objdump -d instr.o
135 instr.o: instr.S
136 $(CC) -o $@ -c $< -O2 -Wall -g
138 cache: tcc_g
139 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
140 vg_annotate tcc.c > /tmp/linpack.cache.log
142 # clean
143 clean:
144 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
145 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h