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