tccrun: review last changes
[tinycc.git] / tests / Makefile
blob3906bf5aeb44960747575dbf48915c6934892a89
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
8 CFLAGS := $(filter-out -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
10 # what tests to run
11 TESTS = \
12 hello-exe \
13 hello-run \
14 libtest \
15 libtest_mt \
16 test3 \
17 abitest \
18 asm-c-connect-test \
19 vla_test-run \
20 tests2-dir \
21 pp-dir \
22 memtest \
23 dlltest \
24 cross-test
26 # test4_static -- Not all relocation types are implemented yet.
27 # asmtest / asmtest2 -- minor differences with gcc
29 ifeq ($(CONFIG_backtrace),no)
30 TESTS := $(filter-out libtest_mt, $(TESTS))
31 else ifneq ($(CONFIG_bcheck),no)
32 TESTS += btest test1b tccb
33 endif
34 ifeq ($(CONFIG_dll),no)
35 TESTS := $(filter-out dlltest, $(TESTS))
36 endif
37 ifeq (-$(CONFIG_arm_eabi)-$(CONFIG_arm_vfp)-,-yes--)
38 TESTS := $(filter-out test3 test1b,$(TESTS))
39 endif
40 ifeq (,$(filter i386 x86_64,$(ARCH)))
41 TESTS := $(filter-out asm-c-connect-test,$(TESTS))
42 endif
43 ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
44 PATH := $(CURDIR)/$(TOP)$(if $(findstring ;,$(PATH)),;,:)$(PATH)
45 endif
46 ifdef CONFIG_OSX
47 LIBS += $(LINK_LIBTCC)
48 endif
49 ifeq ($(ARCH),arm)
50 # tcctest refers to the alignment of functions, and with thumb mode
51 # the low bit of code addresses selects the mode, so the "alignment"
52 # of functions via bit masking comes out as 1. Just disable thumb.
53 test.ref: CFLAGS+=-marm
54 endif
55 ifeq ($(ARCH)$(CONFIG_WIN32),i386)
56 # tcctest.c:get_asm_string uses a construct that is checked too strictly
57 # by GCC in 32bit mode when PIC is enabled.
58 test.ref: CFLAGS+=-fno-PIC -fno-PIE -Wl,-z,notext
59 endif
60 ifeq ($(CC_NAME),msvc)
61 test.ref abitest : CC = gcc
62 endif
63 ifeq ($(TARGETOS),OpenBSD)
64 dlltest: CFLAGS+=-fno-stack-protector
65 endif
66 ifneq (,$(filter FreeBSD NetBSD,$(TARGETOS)))
67 # test3 has dlsym problems
68 TESTS := $(filter-out test3,$(TESTS))
69 TESTS += test1
70 endif
72 RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
73 DISAS = objdump -d
74 ifdef CONFIG_OSX
75 DUMPTCC = (set -x; $(TOP)/tcc -vv; otool -L $(TOP)/tcc; exit 1)
76 else
77 DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
78 endif
80 all test :
81 @echo ------------ version ------------
82 @$(TCC_LOCAL) -v
83 @$(MAKE) --no-print-directory -s clean
84 @$(MAKE) --no-print-directory -s -r _all
86 _all : $(TESTS)
88 hello-exe: ../examples/ex1.c
89 @echo ------------ $@ ------------
90 $(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
92 hello-run: ../examples/ex1.c
93 @echo ------------ $@ ------------
94 $(TCC) -run $< || $(DUMPTCC)
96 libtes%: libtcc_tes%$(EXESUF)
97 @echo ------------ $@ ------------
98 ./libtcc_tes$*$(EXESUF) $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES)
100 libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
101 $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
103 libtcc_test_mt$(EXESUF): libtcc_test_mt.c $(LIBTCC)
104 $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
106 %-dir:
107 @echo ------------ $@ ------------
108 $(MAKE) -k -C $*
110 # test.ref - generate using cc
111 test.ref: tcctest.c
112 $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
113 ./tcctest.gcc > $@
115 # auto test
116 test1 test1b: tcctest.c test.ref
117 @echo ------------ $@ ------------
118 $(TCC) $(RUN_TCC) -w -run $< > test.out1
119 @diff -u test.ref test.out1 && echo "$(AUTO_TEST) OK"
121 # iterated test2 (compile tcc then compile tcctest.c !)
122 test2 test2b: tcctest.c test.ref
123 @echo ------------ $@ ------------
124 $(TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out2
125 @diff -u test.ref test.out2 && echo "$(AUTO_TEST)2 OK"
127 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
128 test3 test3b: tcctest.c test.ref
129 @echo ------------ $@ ------------
130 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out3
131 @diff -u test.ref test.out3 && echo "$(AUTO_TEST)3 OK"
133 AUTO_TEST = Auto Test
134 test%b : TCCFLAGS += -b -bt1
135 test%b : AUTO_TEST = Auto Bound-Test
137 # binary output test
138 test4: tcctest.c test.ref
139 @echo ------------ $@ ------------
140 # object + link output
141 $(TCC) -c -o tcctest3.o $<
142 $(TCC) -o tcctest3 tcctest3.o
143 ./tcctest3 > test3.out
144 @if diff -u test.ref test3.out ; then echo "Object $(AUTO_TEST) OK"; fi
145 # dynamic output
146 $(TCC) -o tcctest1 $<
147 ./tcctest1 > test1.out
148 @if diff -u test.ref test1.out ; then echo "Dynamic $(AUTO_TEST) OK"; fi
149 # dynamic output + bound check
150 $(TCC) -b -o tcctest4 $<
151 ./tcctest4 > test4.out
152 @if diff -u test.ref test4.out ; then echo "BCheck $(AUTO_TEST) OK"; fi
154 test4_static: tcctest.c test.ref
155 @echo ------------ $@ ------------
156 # static output.
157 $(TCC) -static -o tcctest2 $<
158 ./tcctest2 > test2.out
159 @if diff -u test.ref test2.out ; then echo "Static $(AUTO_TEST) OK"; fi
161 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
162 dlltest:
163 @echo ------------ $@ ------------
164 $(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
165 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
166 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
167 ifeq (,$(filter Darwin WIN32,$(TARGETOS)))
168 @echo ------------ $@ with PIC ------------
169 $(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
170 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
171 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
172 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
173 endif
174 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
176 memtest:
177 @echo ------------ $@ ------------
178 $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
179 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
180 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) -w $(TOPSRC)/tests/tcctest.c
181 @echo OK
183 # memory and bound check auto test
184 BOUNDS_OK = 1 4 8 10 14 16
185 BOUNDS_FAIL= 2 5 6 7 9 11 12 13 15 17 18
187 btest: boundtest.c
188 @echo ------------ $@ ------------
189 @for i in $(BOUNDS_OK); do \
190 if $(TCC) -b -run $< $$i >/dev/null 2>&1 ; then \
191 echo "Test $$i succeeded as expected" ; \
192 else\
193 echo "Failed positive test $$i" ; exit 1 ; \
194 fi ;\
195 done ;\
196 for i in $(BOUNDS_FAIL); do \
197 if $(TCC) -b -bt1 -run $< $$i >/dev/null 2>&1 ; then \
198 echo "Failed negative test $$i" ; exit 1 ;\
199 else\
200 echo "Test $$i failed as expected" ; \
201 fi ;\
202 done ;\
203 echo Bound-Test OK
205 tccb:
206 @echo ------------ $@ ------------
207 $(TCC) -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES) -o tccb1.exe
208 mv tccb1.exe tccb2.exe
209 ./tccb2.exe -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES) -o tccb1.exe
210 cmp -s tccb1.exe tccb2.exe && echo "Exe Bound-Rest OK"
213 # speed test
214 speedtest: ex2 ex3
215 @echo ------------ $@ ------------
216 time ./ex2 1238 2 3 4 10 13 4
217 time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
218 time ./ex3 35
219 time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
221 weaktest: tcctest.c test.ref
222 @echo ------------ $@ ------------
223 $(TCC) -c $< -o weaktest.tcc.o
224 $(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
225 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
226 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
227 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
229 ex%: $(TOPSRC)/examples/ex%.c
230 $(CC) -o $@ $< $(CFLAGS)
232 # tiny assembler testing
233 asmtest.ref: asmtest.S
234 $(CC) -Wa,-W -Wa,-mx86-used-note=no -o asmtest.ref.o -c asmtest.S
235 objdump -D asmtest.ref.o > asmtest.ref
237 ifeq ($(ARCH),arm)
238 asmtest asmtest2:
239 TCC="${TCC}" ./arm-asm-testsuite.sh
240 else
241 asmtest asmtest2: asmtest.ref
242 @echo ------------ $@ ------------
243 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
244 objdump -D asmtest.o > asmtest.out
245 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
246 endif
248 # test assembler with tcc compiled by itself
249 asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
251 # Check that code generated by libtcc is binary compatible with
252 # that generated by CC
253 abitest-cc.exe: abitest.c $(LIBTCC)
254 $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
256 abitest-tcc.exe: abitest.c libtcc.c
257 $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
259 abitest-% : abitest-%.exe
260 @echo ------------ $@ ------------
261 ./$< $(TCCFLAGS)
263 abitest: abitest-cc
264 ifneq (-$(CONFIG_arm_eabi)-$(CONFIG_arm_vfp)-,-yes--)
265 abitest: abitest-tcc
266 endif
268 vla_test$(EXESUF): vla_test.c
269 $(TCC) -o $@ $^
271 vla_test-run: vla_test$(EXESUF)
272 @echo ------------ $@ ------------
273 ./vla_test$(EXESUF)
275 .PHONY: abitest vla_test tccb
277 asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
278 $(TCC) -o $@ $^
280 asm-c-connect-%.o: asm-c-connect-%.c
281 $(TCC) -c -o $@ $<
283 asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
284 $(TCC) -o $@ $^
286 asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
287 @echo ------------ $@ ------------
288 ./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
289 ./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
290 @diff -u asm-c-connect.out1 asm-c-connect.out2 || (echo "error"; exit 1)
292 # quick sanity check for cross-compilers
293 cross-test : tcctest.c examples/ex3.c
294 @echo ------------ $@ ------------
295 $(foreach T,$(CROSS-TGTS),$(call CROSS-COMPILE,$T))
297 CROSS-TGTS = \
298 i386 \
299 i386-win32 \
300 i386-OpenBSD \
301 x86_64 \
302 x86_64-win32 \
303 x86_64-osx \
304 x86_64-FreeBSD \
305 x86_64-NetBSD \
306 x86_64-OpenBSD \
307 arm-fpa \
308 arm-eabihf \
309 arm-NetBSD \
310 arm-wince \
311 arm64 \
312 arm64-osx \
313 arm64-FreeBSD \
314 arm64-NetBSD \
315 arm64-OpenBSD \
316 riscv64 \
319 define CROSS-COMPILE
320 @echo " . $(1)"
321 $(TCC) $(DEF-$1) -DTCC_CROSS_TEST -run $(TOPSRC)/tcc.c \
322 -c $(if $(findstring c67,$1),$(filter %/ex3.c,$^),$<) -w $(TCCFLAGS)
324 endef
326 # targets for development
327 %.bin: %.c tcc
328 $(TCC) -g -o $@ $<
329 $(DISAS) $@
331 instr: instr.o
332 objdump -d instr.o
334 instr.o: instr.S
335 $(CC) -o $@ -c $< -O2 -Wall -g
337 cache: tcc_g
338 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
339 vg_annotate tcc.c > /tmp/linpack.cache.log
341 # clean
342 clean:
343 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
344 rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
345 rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
346 rm -f ex? tcc_g weaktest.*.txt *.def *.pdb *.obj libtcc_test_mt
347 @$(MAKE) -C tests2 $@
348 @$(MAKE) -C pp $@