Limit access end-of-struct warning a bit
[tinycc.git] / tests / Makefile
blob00d2c9eb2da4db963e9743dbacdbdc954a4641a5
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 vla_test-run \
20 cross-test \
21 tests2-dir \
22 pp-dir
24 BTESTS = test1b test3b btest
26 # test4 -- problem with -static
27 # asmtest / asmtest2 -- minor differences with gcc
28 # btest -- works on i386 (including win32)
30 # bounds-checking is supported only on i386
31 ifneq ($(ARCH),i386)
32 TESTS := $(filter-out $(BTESTS),$(TESTS))
33 endif
34 ifdef CONFIG_WIN32
35 TESTS := $(filter-out $(BTESTS),$(TESTS))
36 endif
37 ifdef CONFIG_OSX # -run only
38 TESTS := hello-run libtest tests2-dir pp-dir
39 endif
40 ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
41 TESTS := $(filter-out vla_test-run,$(TESTS))
42 endif
43 ifeq ($(CONFIG_arm_eabi),yes)
44 TESTS := $(filter-out test3,$(TESTS))
45 endif
46 ifeq (,$(filter i386 x86_64,$(ARCH)))
47 TESTS := $(filter-out dlltest,$(TESTS))
48 endif
49 ifndef CONFIG_cross
50 TESTS := $(filter-out cross-%,$(TESTS))
51 endif
53 ifdef CONFIG_WIN32
54 SEP = $(if $(findstring :\,$(PATH)),;,:)
55 PATH := $(CURDIR)/$(TOP)$(SEP)$(PATH) # for libtcc_test to find libtcc.dll
56 endif
58 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -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) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
133 $(TCC) $(NATIVE_DEFINES) $(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 -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
138 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
139 $(TCC) $(NATIVE_DEFINES) $(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) -DONE_SOURCE -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
147 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(TOPSRC)/tcc.c $(LIBS)
148 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -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) -DONE_SOURCE $(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 cross-test :
235 @echo ------------ $@ ------------
236 $(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
237 $(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
238 $(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
239 $(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
240 $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
241 $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
242 $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
244 # targets for development
245 %.bin: %.c tcc
246 $(TCC) -g -o $@ $<
247 $(DISAS) $@
249 instr: instr.o
250 objdump -d instr.o
252 instr.o: instr.S
253 $(CC) -o $@ -c $< -O2 -Wall -g
255 cache: tcc_g
256 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
257 vg_annotate tcc.c > /tmp/linpack.cache.log
259 # clean
260 clean:
261 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
262 rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
263 rm -f ex? tcc_g weaktest.*.txt *.def
264 @$(MAKE) -C tests2 $@
265 @$(MAKE) -C pp $@
267 # silent clean, used before running tests
268 clean-s:
269 @$(MAKE) -s --no-print-directory clean