weak definitions overrule non-weak prototypes
[tinycc.git] / tests / Makefile
blob4bebc2be51063d169c05306b7ec70412f7727068
2 # Tiny C Compiler Makefile - tests
5 # what tests to run
6 TESTS = libtest test3
8 # these should work too
9 # TESTS += test1 test2 speedtest btest weaktest
11 # these don't work as they should
12 # TESTS += test4 asmtest
14 TOP = ..
15 include $(TOP)/Makefile
17 ifdef DISABLE_STATIC
18 export LD_LIBRARY_PATH:=$(CURDIR)/..
19 endif
21 # run local version of tcc with local libraries and includes
22 TCC = ../tcc -B..
23 RUN_TCC = $(NATIVE_DEFINES) -run ../tcc.c -B..
24 DISAS=objdump -d
26 all test : $(TESTS)
28 # make sure that tcc exists
29 test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc
30 ../%:
31 $(MAKE) -C .. $*
33 # libtcc test
34 libtest: libtcc_test$(EXESUF) ../libtcc1.a
35 @echo ------------ $@ ------------
36 ./libtcc_test$(EXESUF) lib_path=..
38 libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)
39 $(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS) $(LINK_LIBTCC)
41 # test.ref - generate using gcc
42 # copy only tcclib.h so GCC's stddef and stdarg will be used
43 test.ref: tcctest.c
44 cp -u ../include/tcclib.h .
45 $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS)
46 ./tcctest.gcc > $@
48 # auto test
49 test1: test.ref
50 @echo ------------ $@ ------------
51 $(TCC) -run tcctest.c > test.out1
52 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
54 # iterated test2 (compile tcc then compile tcctest.c !)
55 test2: test.ref
56 @echo ------------ $@ ------------
57 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
58 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
60 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
61 test3: test.ref
62 @echo ------------ $@ ------------
63 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
64 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
66 # binary output test
67 test4: test.ref
68 @echo ------------ $@ ------------
69 # dynamic output
70 $(TCC) -o tcctest1 tcctest.c
71 ./tcctest1 > test1.out
72 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
73 # object + link output
74 $(TCC) -c -o tcctest3.o tcctest.c
75 $(TCC) -o tcctest3 tcctest3.o
76 ./tcctest3 > test3.out
77 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
78 # static output
79 $(TCC) -static -o tcctest2 tcctest.c
80 ./tcctest2 > test2.out
81 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
82 # dynamic output + bound check
83 $(TCC) -b -o tcctest4 tcctest.c
84 ./tcctest4 > test4.out
85 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
87 # memory and bound check auto test
88 BOUNDS_OK = 1 4 8 10 14
89 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
91 btest: boundtest.c ../bcheck.o
92 @echo ------------ $@ ------------
93 @for i in $(BOUNDS_OK); do \
94 echo ; echo --- boundtest $$i ---; \
95 if $(TCC) -b -run boundtest.c $$i ; then \
96 echo succeded as expected; \
97 else\
98 echo Failed positive test $$i ; exit 1 ; \
99 fi ;\
100 done ;\
101 for i in $(BOUNDS_FAIL); do \
102 echo ; echo --- boundtest $$i ---; \
103 if $(TCC) -b -run boundtest.c $$i ; then \
104 echo Failed negative test $$i ; exit 1 ;\
105 else\
106 echo failed as expected; \
107 fi ;\
108 done ;\
109 echo; echo Bound test OK
111 # speed test
112 speedtest: ex2 ex3
113 @echo ------------ $@ ------------
114 time ./ex2 1238 2 3 4 10 13 4
115 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
116 time ./ex3 35
117 time $(TCC) -run ../examples/ex3.c 35
119 weaktest: test.ref
120 $(TCC) -c tcctest.c -o weaktest.tcc.o
121 $(CC) -c tcctest.c -o weaktest.gcc.o -I. -w $(CFLAGS)
122 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
123 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
124 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
126 ex%: ../examples/ex%.c
127 $(CC) -o $@ $< $(CFLAGS)
129 # tiny assembler testing
130 asmtest.ref: asmtest.S
131 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
132 objdump -D asmtest.ref.o > asmtest.ref
134 asmtest: asmtest.ref
135 @echo ------------ $@ ------------
136 $(TCC) -c asmtest.S
137 objdump -D asmtest.o > asmtest.out
138 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
140 # targets for development
141 %.bin: %.c tcc
142 $(TCC) -g -o $@ $<
143 $(DISAS) $@
145 instr: instr.o
146 objdump -d instr.o
148 instr.o: instr.S
149 $(CC) -o $@ -c $< -O2 -Wall -g
151 cache: tcc_g
152 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
153 vg_annotate tcc.c > /tmp/linpack.cache.log
155 # clean
156 clean:
157 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
158 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h