More cleanup tests
[tinycc.git] / tests / Makefile
blobd3c49fb9961c15edf1f5bcc4262d89ebe80ffcf5
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 : clean-s $(TESTS)
64 hello-exe: ../examples/ex1.c
65 @echo ------------ $@ ------------
66 $(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
68 hello-run: ../examples/ex1.c
69 @echo ------------ $@ ------------
70 $(TCC) -run $< || $(DUMPTCC)
72 libtest: libtcc_test$(EXESUF)
73 @echo ------------ $@ ------------
74 ./libtcc_test$(EXESUF) $(TCCFLAGS)
76 libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
77 $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
79 %-dir:
80 @echo ------------ $@ ------------
81 $(MAKE) -k -C $*
83 # test.ref - generate using cc
84 test.ref: tcctest.c
85 $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
86 ./tcctest.gcc > $@
88 # auto test
89 test1 test1b: tcctest.c test.ref
90 @echo ------------ $@ ------------
91 $(TCC) -run $< > test.out1
92 @diff -u test.ref test.out1 && echo "Auto Test OK"
94 # iterated test2 (compile tcc then compile tcctest.c !)
95 test2 test2b: tcctest.c test.ref
96 @echo ------------ $@ ------------
97 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
98 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
100 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
101 test3 test3b: tcctest.c test.ref
102 @echo ------------ $@ ------------
103 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
104 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
106 test%b : TCCFLAGS += -b
108 # binary output test
109 test4: tcctest.c test.ref
110 @echo ------------ $@ ------------
111 # object + link output
112 $(TCC) -c -o tcctest3.o $<
113 $(TCC) -o tcctest3 tcctest3.o
114 ./tcctest3 > test3.out
115 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
116 # dynamic output
117 $(TCC) -o tcctest1 $<
118 ./tcctest1 > test1.out
119 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
120 # dynamic output + bound check
121 $(TCC) -b -o tcctest4 $<
122 ./tcctest4 > test4.out
123 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
124 # static output
125 $(TCC) -static -o tcctest2 $<
126 ./tcctest2 > test2.out
127 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
129 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
130 dlltest:
131 @echo ------------ $@ ------------
132 $(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
133 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
134 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
135 ifndef CONFIG_WIN32
136 @echo ------------ $@ with PIC ------------
137 $(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
138 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
139 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
140 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
141 endif
142 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
144 memtest:
145 @echo ------------ $@ ------------
146 $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
147 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
148 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
151 # memory and bound check auto test
152 BOUNDS_OK = 1 4 8 10 14
153 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
155 btest: boundtest.c
156 @echo ------------ $@ ------------
157 @for i in $(BOUNDS_OK); do \
158 echo ; echo --- boundtest $$i ---; \
159 if $(TCC) -b -run $< $$i ; then \
160 echo succeeded as expected; \
161 else\
162 echo Failed positive test $$i ; exit 1 ; \
163 fi ;\
164 done ;\
165 for i in $(BOUNDS_FAIL); do \
166 echo ; echo --- boundtest $$i ---; \
167 if $(TCC) -b -run $< $$i ; then \
168 echo Failed negative test $$i ; exit 1 ;\
169 else\
170 echo failed as expected; \
171 fi ;\
172 done ;\
173 echo; echo Bound test OK
175 # speed test
176 speedtest: ex2 ex3
177 @echo ------------ $@ ------------
178 time ./ex2 1238 2 3 4 10 13 4
179 time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
180 time ./ex3 35
181 time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
183 weaktest: tcctest.c test.ref
184 $(TCC) -c $< -o weaktest.tcc.o
185 $(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
186 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
187 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
188 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
190 ex%: $(TOPSRC)/examples/ex%.c
191 $(CC) -o $@ $< $(CFLAGS)
193 # tiny assembler testing
194 asmtest.ref: asmtest.S
195 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
196 objdump -D asmtest.ref.o > asmtest.ref
198 asmtest asmtest2: asmtest.ref
199 @echo ------------ $@ ------------
200 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
201 objdump -D asmtest.o > asmtest.out
202 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
204 # test assembler with tcc compiled by itself
205 asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
207 # Check that code generated by libtcc is binary compatible with
208 # that generated by CC
209 abitest-cc$(EXESUF): abitest.c $(LIBTCC)
210 $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
212 abitest-tcc$(EXESUF): abitest.c libtcc.c
213 $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
215 ABITESTS := abitest-cc$(EXESUF)
216 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
217 ABITESTS += abitest-tcc$(EXESUF)
218 endif
220 abitest: $(ABITESTS)
221 @echo ------------ $@ ------------
222 ./abitest-cc$(EXESUF) $(TCCFLAGS)
223 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
224 ./abitest-tcc$(EXESUF) $(TCCFLAGS)
225 endif
227 vla_test$(EXESUF): vla_test.c
228 $(TCC) -o $@ $^
230 vla_test-run: vla_test$(EXESUF)
231 @echo ------------ $@ ------------
232 ./vla_test$(EXESUF)
234 asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
235 $(TCC) -o $@ $^
237 asm-c-connect-%.o: asm-c-connect-%.c
238 $(TCC) -c -o $@ $<
240 asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
241 $(TCC) -o $@ $^
243 asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
244 @echo ------------ $@ ------------
245 ./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
246 ./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
247 @diff -u asm-c-connect.out1 asm-c-connect.out2 && echo "ok"
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) asm-c-connect-sep$(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