Update ChangeLog
[tinycc.git] / tests / Makefile
blob558d06c79faa5a232ce3d317a6589ec465ebbce7
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
8 CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC)
10 # what tests to run
11 TESTS = \
12 hello-exe \
13 hello-run \
14 libtest \
15 test3 \
16 memtest \
17 dlltest \
18 abitest \
19 vla_test-run \
20 tests2-dir \
21 pp-dir
23 BTESTS = test1b test3b btest
25 # test4 -- problem with -static
26 # asmtest / asmtest2 -- minor differences with gcc
27 # btest -- works on i386 (including win32)
29 # bounds-checking is supported only on i386
30 ifneq ($(ARCH),i386)
31 TESTS := $(filter-out $(BTESTS),$(TESTS))
32 endif
33 ifdef CONFIG_WIN32
34 TESTS := $(filter-out $(BTESTS),$(TESTS))
35 endif
36 ifeq ($(TARGETOS),Darwin)
37 TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS))
38 endif
39 ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
40 TESTS := $(filter-out vla_test-run,$(TESTS))
41 endif
42 ifeq ($(CONFIG_arm_eabi),yes)
43 TESTS := $(filter-out test3,$(TESTS))
44 endif
45 ifeq (,$(filter i386 x86_64,$(ARCH)))
46 TESTS := $(filter-out dlltest,$(TESTS))
47 endif
49 # run local version of tcc with local libraries and includes
50 TCCFLAGS = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
51 ifdef CONFIG_WIN32
52 TCCFLAGS = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
53 PATH := $(CURDIR)/$(TOP):$(PATH) # for libtcc_test to find libtcc.dll
54 endif
56 TCC = $(TOP)/tcc $(TCCFLAGS)
57 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS)
59 ifeq ($(TARGETOS),Darwin)
60 CFLAGS += -Wl,-flat_namespace,-undefined,warning
61 TCCFLAGS += -D_ANSI_SOURCE
62 export MACOSX_DEPLOYMENT_TARGET:=10.2
63 endif
65 DISAS = objdump -d
67 all test : clean-s $(TESTS)
69 hello-exe: ../examples/ex1.c
70 @echo ------------ $@ ------------
71 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
73 hello-run: ../examples/ex1.c
74 @echo ------------ $@ ------------
75 $(TCC) -run $<
77 libtest: libtcc_test$(EXESUF)
78 @echo ------------ $@ ------------
79 ./libtcc_test$(EXESUF) $(TCCFLAGS)
81 libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
82 $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
84 %-dir:
85 @echo ------------ $@ ------------
86 $(MAKE) -k -C $*
88 # test.ref - generate using cc
89 test.ref: tcctest.c
90 $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
91 ./tcctest.gcc > $@
93 # auto test
94 test1 test1b: tcctest.c test.ref
95 @echo ------------ $@ ------------
96 $(TCC) -run $< > test.out1
97 @diff -u test.ref test.out1 && echo "Auto Test OK"
99 # iterated test2 (compile tcc then compile tcctest.c !)
100 test2 test2b: tcctest.c test.ref
101 @echo ------------ $@ ------------
102 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
103 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
105 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
106 test3 test3b: tcctest.c test.ref
107 @echo ------------ $@ ------------
108 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
109 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
111 test%b : TCCFLAGS += -b
113 # binary output test
114 test4: tcctest.c test.ref
115 @echo ------------ $@ ------------
116 # object + link output
117 $(TCC) -c -o tcctest3.o $<
118 $(TCC) -o tcctest3 tcctest3.o
119 ./tcctest3 > test3.out
120 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
121 # dynamic output
122 $(TCC) -o tcctest1 $<
123 ./tcctest1 > test1.out
124 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
125 # dynamic output + bound check
126 $(TCC) -b -o tcctest4 $<
127 ./tcctest4 > test4.out
128 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
129 # static output
130 $(TCC) -static -o tcctest2 $<
131 ./tcctest2 > test2.out
132 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
134 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
135 dlltest:
136 @echo ------------ $@ ------------
137 $(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
138 $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
139 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
140 ifndef CONFIG_WIN32
141 @echo ------------ $@ with PIC ------------
142 $(CC) $(CFLAGS) -fPIC -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
143 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
144 $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
145 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
146 endif
147 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
149 memtest:
150 @echo ------------ $@ ------------
151 $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
152 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(TOPSRC)/tcc.c $(LIBS)
153 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
156 # memory and bound check auto test
157 BOUNDS_OK = 1 4 8 10 14
158 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
160 btest: boundtest.c
161 @echo ------------ $@ ------------
162 @for i in $(BOUNDS_OK); do \
163 echo ; echo --- boundtest $$i ---; \
164 if $(TCC) -b -run $< $$i ; then \
165 echo succeeded as expected; \
166 else\
167 echo Failed positive test $$i ; exit 1 ; \
168 fi ;\
169 done ;\
170 for i in $(BOUNDS_FAIL); do \
171 echo ; echo --- boundtest $$i ---; \
172 if $(TCC) -b -run $< $$i ; then \
173 echo Failed negative test $$i ; exit 1 ;\
174 else\
175 echo failed as expected; \
176 fi ;\
177 done ;\
178 echo; echo Bound test OK
180 # speed test
181 speedtest: ex2 ex3
182 @echo ------------ $@ ------------
183 time ./ex2 1238 2 3 4 10 13 4
184 time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
185 time ./ex3 35
186 time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
188 weaktest: tcctest.c test.ref
189 $(TCC) -c $< -o weaktest.tcc.o
190 $(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
191 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
192 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
193 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
195 ex%: $(TOPSRC)/examples/ex%.c
196 $(CC) -o $@ $< $(CFLAGS)
198 # tiny assembler testing
199 asmtest.ref: asmtest.S
200 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
201 objdump -D asmtest.ref.o > asmtest.ref
203 asmtest asmtest2: asmtest.ref
204 @echo ------------ $@ ------------
205 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
206 objdump -D asmtest.o > asmtest.out
207 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
209 # test assembler with tcc compiled by itself
210 asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
212 # Check that code generated by libtcc is binary compatible with
213 # that generated by CC
214 abitest-cc$(EXESUF): abitest.c $(LIBTCC)
215 $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
217 abitest-tcc$(EXESUF): abitest.c libtcc.c
218 $(TCC) -o $@ $^ $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS)
220 ABITESTS := abitest-cc$(EXESUF)
221 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
222 ABITESTS += abitest-tcc$(EXESUF)
223 endif
225 abitest: $(ABITESTS)
226 @echo ------------ $@ ------------
227 ./abitest-cc$(EXESUF) $(TCCFLAGS)
228 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
229 ./abitest-tcc$(EXESUF) $(TCCFLAGS)
230 endif
232 vla_test$(EXESUF): vla_test.c
233 $(TCC) -o $@ $^
235 vla_test-run: vla_test$(EXESUF)
236 @echo ------------ $@ ------------
237 ./vla_test$(EXESUF)
239 # targets for development
240 %.bin: %.c tcc
241 $(TCC) -g -o $@ $<
242 $(DISAS) $@
244 instr: instr.o
245 objdump -d instr.o
247 instr.o: instr.S
248 $(CC) -o $@ -c $< -O2 -Wall -g
250 cache: tcc_g
251 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
252 vg_annotate tcc.c > /tmp/linpack.cache.log
254 # clean
255 clean:
256 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc \
257 *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] \
258 ex? tcc_g *.def weaktest.*.txt
259 $(MAKE) -C tests2 $@
260 $(MAKE) -C pp $@
262 # silent clean, used before running tests
263 clean-s:
264 @$(MAKE) -s --no-print-directory clean