Deal with more tentative definitions
[tinycc.git] / tests / Makefile
blob9a4d123164d944fa8683f2f0736acebad84bb6bc
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) $(LDFLAGS)
10 # what tests to run
11 TESTS = \
12 hello-exe \
13 hello-run \
14 libtest \
15 test3 \
16 memtest \
17 dlltest \
18 abitest \
19 asm-c-connect-test \
20 vla_test-run \
21 cross-test \
22 tests2-dir \
23 pp-dir
25 BTESTS = test1b test3b btest
27 # test4 -- problem with -static
28 # asmtest / asmtest2 -- minor differences with gcc
29 # btest -- works on i386 (including win32)
31 # bounds-checking is supported only on i386
32 ifneq ($(ARCH),i386)
33 TESTS := $(filter-out $(BTESTS),$(TESTS))
34 endif
35 ifdef CONFIG_WIN32
36 TESTS := $(filter-out $(BTESTS),$(TESTS))
37 endif
38 ifdef CONFIG_OSX # -run only
39 TESTS := hello-run libtest tests2-dir pp-dir
40 endif
41 ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
42 TESTS := $(filter-out vla_test-run,$(TESTS))
43 endif
44 ifeq ($(CONFIG_arm_eabi),yes)
45 TESTS := $(filter-out test3,$(TESTS))
46 endif
47 ifeq (,$(filter i386 x86_64,$(ARCH)))
48 TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS))
49 endif
50 ifndef CONFIG_cross
51 TESTS := $(filter-out cross-%,$(TESTS))
52 endif
54 ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
55 PATH := $(CURDIR)/$(TOP)$(if $(findstring :\,$(PATH)),;,:)$(PATH)
56 endif
58 RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
59 DISAS = objdump -d
60 DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
62 all test :
63 $(MAKE) clean-s
64 $(MAKE) $(TESTS)
66 hello-exe: ../examples/ex1.c
67 @echo ------------ $@ ------------
68 $(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
70 hello-run: ../examples/ex1.c
71 @echo ------------ $@ ------------
72 $(TCC) -run $< || $(DUMPTCC)
74 libtest: libtcc_test$(EXESUF)
75 @echo ------------ $@ ------------
76 ./libtcc_test$(EXESUF) $(TCCFLAGS)
78 libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
79 $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
81 %-dir:
82 @echo ------------ $@ ------------
83 $(MAKE) -k -C $*
85 # test.ref - generate using cc
86 test.ref: tcctest.c
87 $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
88 ./tcctest.gcc > $@
90 # auto test
91 test1 test1b: tcctest.c test.ref
92 @echo ------------ $@ ------------
93 $(TCC) -run $< > test.out1
94 @diff -u test.ref test.out1 && echo "Auto Test OK"
96 # iterated test2 (compile tcc then compile tcctest.c !)
97 test2 test2b: tcctest.c test.ref
98 @echo ------------ $@ ------------
99 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
100 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
102 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
103 test3 test3b: tcctest.c test.ref
104 @echo ------------ $@ ------------
105 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
106 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
108 test%b : TCCFLAGS += -b
110 # binary output test
111 test4: tcctest.c test.ref
112 @echo ------------ $@ ------------
113 # object + link output
114 $(TCC) -c -o tcctest3.o $<
115 $(TCC) -o tcctest3 tcctest3.o
116 ./tcctest3 > test3.out
117 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
118 # dynamic output
119 $(TCC) -o tcctest1 $<
120 ./tcctest1 > test1.out
121 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
122 # dynamic output + bound check
123 $(TCC) -b -o tcctest4 $<
124 ./tcctest4 > test4.out
125 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
126 # static output
127 $(TCC) -static -o tcctest2 $<
128 ./tcctest2 > test2.out
129 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
131 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
132 dlltest:
133 @echo ------------ $@ ------------
134 $(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
135 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
136 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
137 ifndef CONFIG_WIN32
138 @echo ------------ $@ with PIC ------------
139 $(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
140 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
141 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
142 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
143 endif
144 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
146 memtest:
147 @echo ------------ $@ ------------
148 $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
149 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
150 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
153 # memory and bound check auto test
154 BOUNDS_OK = 1 4 8 10 14
155 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
157 btest: boundtest.c
158 @echo ------------ $@ ------------
159 @for i in $(BOUNDS_OK); do \
160 echo ; echo --- boundtest $$i ---; \
161 if $(TCC) -b -run $< $$i ; then \
162 echo succeeded as expected; \
163 else\
164 echo Failed positive test $$i ; exit 1 ; \
165 fi ;\
166 done ;\
167 for i in $(BOUNDS_FAIL); do \
168 echo ; echo --- boundtest $$i ---; \
169 if $(TCC) -b -run $< $$i ; then \
170 echo Failed negative test $$i ; exit 1 ;\
171 else\
172 echo failed as expected; \
173 fi ;\
174 done ;\
175 echo; echo Bound test OK
177 # speed test
178 speedtest: ex2 ex3
179 @echo ------------ $@ ------------
180 time ./ex2 1238 2 3 4 10 13 4
181 time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
182 time ./ex3 35
183 time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
185 weaktest: tcctest.c test.ref
186 $(TCC) -c $< -o weaktest.tcc.o
187 $(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
188 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
189 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
190 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
192 ex%: $(TOPSRC)/examples/ex%.c
193 $(CC) -o $@ $< $(CFLAGS)
195 # tiny assembler testing
196 asmtest.ref: asmtest.S
197 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
198 objdump -D asmtest.ref.o > asmtest.ref
200 asmtest asmtest2: asmtest.ref
201 @echo ------------ $@ ------------
202 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
203 objdump -D asmtest.o > asmtest.out
204 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
206 # test assembler with tcc compiled by itself
207 asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
209 # Check that code generated by libtcc is binary compatible with
210 # that generated by CC
211 abitest-cc$(EXESUF): abitest.c $(LIBTCC)
212 $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
214 abitest-tcc$(EXESUF): abitest.c libtcc.c
215 $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
217 ABITESTS := abitest-cc$(EXESUF)
218 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
219 ABITESTS += abitest-tcc$(EXESUF)
220 endif
222 abitest: $(ABITESTS)
223 @echo ------------ $@ ------------
224 ./abitest-cc$(EXESUF) $(TCCFLAGS)
225 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
226 ./abitest-tcc$(EXESUF) $(TCCFLAGS)
227 endif
229 vla_test$(EXESUF): vla_test.c
230 $(TCC) -o $@ $^
232 vla_test-run: vla_test$(EXESUF)
233 @echo ------------ $@ ------------
234 ./vla_test$(EXESUF)
236 asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
237 $(TCC) -o $@ $^
239 asm-c-connect-%.o: asm-c-connect-%.c
240 $(TCC) -c -o $@ $<
242 asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
243 $(TCC) -o $@ $^
245 asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
246 @echo ------------ $@ ------------
247 ./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
248 ./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
249 @diff -u asm-c-connect.out1 asm-c-connect.out2 && echo "ok"
251 cross-test :
252 @echo ------------ $@ ------------
253 $(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
254 $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
255 $(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
256 $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
257 $(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
258 $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok"
259 $(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
260 $(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
261 $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
262 $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
263 $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
265 # targets for development
266 %.bin: %.c tcc
267 $(TCC) -g -o $@ $<
268 $(DISAS) $@
270 instr: instr.o
271 objdump -d instr.o
273 instr.o: instr.S
274 $(CC) -o $@ -c $< -O2 -Wall -g
276 cache: tcc_g
277 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
278 vg_annotate tcc.c > /tmp/linpack.cache.log
280 # clean
281 clean:
282 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
283 rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
284 rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
285 rm -f ex? tcc_g weaktest.*.txt *.def
286 @$(MAKE) -C tests2 $@
287 @$(MAKE) -C pp $@
289 # silent clean, used before running tests
290 clean-s:
291 @$(MAKE) -s --no-print-directory clean