Fix another corner case with C/asm symtable
[tinycc.git] / tests / Makefile
blobf06f39c37ac72b40c462e986782249bc3f2ffc10
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 ifdef CONFIG_WIN32
55 SEP = $(if $(findstring :\,$(PATH)),;,:)
56 PATH := $(CURDIR)/$(TOP)$(SEP)$(PATH) # for libtcc_test to find libtcc.dll
57 endif
59 RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
60 DISAS = objdump -d
61 DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
63 all test : clean-s $(TESTS)
65 hello-exe: ../examples/ex1.c
66 @echo ------------ $@ ------------
67 $(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
69 hello-run: ../examples/ex1.c
70 @echo ------------ $@ ------------
71 $(TCC) -run $< || $(DUMPTCC)
73 libtest: libtcc_test$(EXESUF)
74 @echo ------------ $@ ------------
75 ./libtcc_test$(EXESUF) $(TCCFLAGS)
77 libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
78 $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
80 %-dir:
81 @echo ------------ $@ ------------
82 $(MAKE) -k -C $*
84 # test.ref - generate using cc
85 test.ref: tcctest.c
86 $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
87 ./tcctest.gcc > $@
89 # auto test
90 test1 test1b: tcctest.c test.ref
91 @echo ------------ $@ ------------
92 $(TCC) -run $< > test.out1
93 @diff -u test.ref test.out1 && echo "Auto Test OK"
95 # iterated test2 (compile tcc then compile tcctest.c !)
96 test2 test2b: tcctest.c test.ref
97 @echo ------------ $@ ------------
98 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
99 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
101 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
102 test3 test3b: tcctest.c test.ref
103 @echo ------------ $@ ------------
104 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
105 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
107 test%b : TCCFLAGS += -b
109 # binary output test
110 test4: tcctest.c test.ref
111 @echo ------------ $@ ------------
112 # object + link output
113 $(TCC) -c -o tcctest3.o $<
114 $(TCC) -o tcctest3 tcctest3.o
115 ./tcctest3 > test3.out
116 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
117 # dynamic output
118 $(TCC) -o tcctest1 $<
119 ./tcctest1 > test1.out
120 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
121 # dynamic output + bound check
122 $(TCC) -b -o tcctest4 $<
123 ./tcctest4 > test4.out
124 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
125 # static output
126 $(TCC) -static -o tcctest2 $<
127 ./tcctest2 > test2.out
128 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
130 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
131 dlltest:
132 @echo ------------ $@ ------------
133 $(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
134 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
135 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
136 ifndef CONFIG_WIN32
137 @echo ------------ $@ with PIC ------------
138 $(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
139 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
140 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
141 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
142 endif
143 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
145 memtest:
146 @echo ------------ $@ ------------
147 $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
148 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
149 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
152 # memory and bound check auto test
153 BOUNDS_OK = 1 4 8 10 14
154 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
156 btest: boundtest.c
157 @echo ------------ $@ ------------
158 @for i in $(BOUNDS_OK); do \
159 echo ; echo --- boundtest $$i ---; \
160 if $(TCC) -b -run $< $$i ; then \
161 echo succeeded as expected; \
162 else\
163 echo Failed positive test $$i ; exit 1 ; \
164 fi ;\
165 done ;\
166 for i in $(BOUNDS_FAIL); do \
167 echo ; echo --- boundtest $$i ---; \
168 if $(TCC) -b -run $< $$i ; then \
169 echo Failed negative test $$i ; exit 1 ;\
170 else\
171 echo failed as expected; \
172 fi ;\
173 done ;\
174 echo; echo Bound test OK
176 # speed test
177 speedtest: ex2 ex3
178 @echo ------------ $@ ------------
179 time ./ex2 1238 2 3 4 10 13 4
180 time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
181 time ./ex3 35
182 time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
184 weaktest: tcctest.c test.ref
185 $(TCC) -c $< -o weaktest.tcc.o
186 $(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
187 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
188 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
189 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
191 ex%: $(TOPSRC)/examples/ex%.c
192 $(CC) -o $@ $< $(CFLAGS)
194 # tiny assembler testing
195 asmtest.ref: asmtest.S
196 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
197 objdump -D asmtest.ref.o > asmtest.ref
199 asmtest asmtest2: asmtest.ref
200 @echo ------------ $@ ------------
201 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
202 objdump -D asmtest.o > asmtest.out
203 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
205 # test assembler with tcc compiled by itself
206 asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
208 # Check that code generated by libtcc is binary compatible with
209 # that generated by CC
210 abitest-cc$(EXESUF): abitest.c $(LIBTCC)
211 $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
213 abitest-tcc$(EXESUF): abitest.c libtcc.c
214 $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
216 ABITESTS := abitest-cc$(EXESUF)
217 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
218 ABITESTS += abitest-tcc$(EXESUF)
219 endif
221 abitest: $(ABITESTS)
222 @echo ------------ $@ ------------
223 ./abitest-cc$(EXESUF) $(TCCFLAGS)
224 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
225 ./abitest-tcc$(EXESUF) $(TCCFLAGS)
226 endif
228 vla_test$(EXESUF): vla_test.c
229 $(TCC) -o $@ $^
231 vla_test-run: vla_test$(EXESUF)
232 @echo ------------ $@ ------------
233 ./vla_test$(EXESUF)
235 asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
236 $(TCC) -o $@ $^
238 asm-c-connect-%.o: asm-c-connect-%.c
239 $(TCC) -c -o $@ $<
241 asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
242 $(TCC) -o $@ $^
244 asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
245 @echo ------------ $@ ------------
246 ./asm-c-connect$(EXESUF)
247 ./asm-c-connect-sep$(EXESUF)
249 cross-test :
250 @echo ------------ $@ ------------
251 $(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
252 $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
253 $(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
254 $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
255 $(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
256 $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok"
257 $(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
258 $(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
259 $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
260 $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
261 $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
263 # targets for development
264 %.bin: %.c tcc
265 $(TCC) -g -o $@ $<
266 $(DISAS) $@
268 instr: instr.o
269 objdump -d instr.o
271 instr.o: instr.S
272 $(CC) -o $@ -c $< -O2 -Wall -g
274 cache: tcc_g
275 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
276 vg_annotate tcc.c > /tmp/linpack.cache.log
278 # clean
279 clean:
280 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
281 rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
282 rm -f asm-c-connect$(EXESUF)
283 rm -f ex? tcc_g weaktest.*.txt *.def
284 @$(MAKE) -C tests2 $@
285 @$(MAKE) -C pp $@
287 # silent clean, used before running tests
288 clean-s:
289 @$(MAKE) -s --no-print-directory clean