A right fix for the array in struct initialization w/o '{'
[tinycc.git] / tests / Makefile
blobbc68de0d0a47db085a1fa63deb3fe0069bf48007
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 SRCDIR = $(top_srcdir)/tests
8 VPATH = $(SRCDIR) $(top_srcdir)
10 # clear CFLAGS and LDFLAGS
11 CFLAGS :=
12 LDFLAGS :=
14 # what tests to run
15 TESTS = \
16 hello-exe \
17 hello-run \
18 libtest \
19 test3 \
20 abitest \
21 vla_test-run \
22 moretests
24 BTESTS = test1b test3b btest
26 ifdef CONFIG_CROSS
27 TESTS += hello-cross
28 endif
30 # test4 -- problem with -static
31 # asmtest -- minor differences with gcc
32 # btest -- works on i386 (including win32)
34 # bounds-checking is supported only on i386
35 ifneq ($(ARCH),i386)
36 TESTS := $(filter-out $(BTESTS),$(TESTS))
37 endif
38 ifdef CONFIG_WIN32
39 TESTS := w32-prep $(filter-out $(BTESTS),$(TESTS))
40 endif
41 ifeq ($(TARGETOS),Darwin)
42 TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS))
43 endif
44 ifeq ($(ARCH),i386)
45 else ifneq ($(ARCH),x86-64)
46 TESTS := $(filter-out vla_test-run,$(TESTS))
47 endif
48 ifeq ($(CONFIG_arm_eabi),yes)
49 TESTS := $(filter-out test3,$(TESTS))
50 endif
52 ifdef DISABLE_STATIC
53 export LD_LIBRARY_PATH:=$(CURDIR)/..
54 endif
56 ifeq ($(TARGETOS),Darwin)
57 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
58 export MACOSX_DEPLOYMENT_TARGET:=10.2
59 NATIVE_DEFINES+=-D_ANSI_SOURCE
60 endif
62 # run local version of tcc with local libraries and includes
63 TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
64 ifdef CONFIG_WIN32
65 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -I$(TOP) -L$(TOP)
66 endif
67 XTCCFLAGS = -B$(TOP) -B$(top_srcdir)/win32 -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
69 TCC = $(TOP)/tcc $(TCCFLAGS)
70 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS)
72 DISAS = objdump -d
74 # libtcc test
75 ifdef LIBTCC1
76 LIBTCC1:=$(TOP)/$(LIBTCC1)
77 endif
79 all test : $(TESTS)
81 hello-exe: ../examples/ex1.c
82 @echo ------------ $@ ------------
83 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
85 hello-cross: ../examples/ex1.c
86 @echo ------------ $@ ------------
87 for XTCC in $(PROGS_CROSS) ; \
88 do echo -n "Test of $$XTCC... "; \
89 out=$$($(TOP)/$$XTCC $(XTCCFLAGS) -c $< 2>&1); \
90 test $$? -ne 0 && { echo "Failed\n$$out\n" ; $(TOP)/$$XTCC -vv; exit 1; } ; \
91 echo "Success"; \
92 done
94 hello-run: ../examples/ex1.c
95 @echo ------------ $@ ------------
96 $(TCC) -run $<
98 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
99 @echo ------------ $@ ------------
100 ./libtcc_test$(EXESUF) lib_path=..
102 libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
103 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
105 moretests:
106 @echo ------------ $@ ------------
107 $(MAKE) -C tests2
109 w32-prep:
110 cp ../libtcc1.a ../lib
112 # test.ref - generate using cc
113 test.ref: tcctest.c
114 $(CC) -o tcctest.cc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
115 ./tcctest.cc > $@
117 # auto test
118 test1 test1b: tcctest.c test.ref
119 @echo ------------ $@ ------------
120 $(TCC) -run $< > test.out1
121 @diff -u test.ref test.out1 && echo "Auto Test OK"
123 # iterated test2 (compile tcc then compile tcctest.c !)
124 test2 test2b: tcctest.c test.ref
125 @echo ------------ $@ ------------
126 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
127 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
129 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
130 test3 test3b: tcctest.c test.ref
131 @echo ------------ $@ ------------
132 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
133 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
135 test%b : TCCFLAGS += -b
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
153 # static output
154 $(TCC) -static -o tcctest2 $<
155 ./tcctest2 > test2.out
156 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
158 # memory and bound check auto test
159 BOUNDS_OK = 1 4 8 10 14
160 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
162 btest: boundtest.c
163 @echo ------------ $@ ------------
164 @for i in $(BOUNDS_OK); do \
165 echo ; echo --- boundtest $$i ---; \
166 if $(TCC) -b -run $< $$i ; then \
167 echo succeeded as expected; \
168 else\
169 echo Failed positive test $$i ; exit 1 ; \
170 fi ;\
171 done ;\
172 for i in $(BOUNDS_FAIL); do \
173 echo ; echo --- boundtest $$i ---; \
174 if $(TCC) -b -run $< $$i ; then \
175 echo Failed negative test $$i ; exit 1 ;\
176 else\
177 echo failed as expected; \
178 fi ;\
179 done ;\
180 echo; echo Bound test OK
182 # speed test
183 speedtest: ex2 ex3
184 @echo ------------ $@ ------------
185 time ./ex2 1238 2 3 4 10 13 4
186 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
187 time ./ex3 35
188 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
190 weaktest: tcctest.c test.ref
191 $(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
192 $(CC) -c $< -o weaktest.cc.o -I. $(CPPFLAGS) -w $(CFLAGS)
193 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
194 objdump -t weaktest.cc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.cc.o.txt
195 diff weaktest.cc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
197 ex%: $(top_srcdir)/examples/ex%.c
198 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
200 # tiny assembler testing
201 asmtest.ref: asmtest.S
202 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
203 objdump -D asmtest.ref.o > asmtest.ref
205 asmtest: asmtest.ref
206 @echo ------------ $@ ------------
207 $(TCC) -c asmtest.S
208 objdump -D asmtest.o > asmtest.out
209 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
211 # Check that code generated by libtcc is binary compatible with
212 # that generated by CC
213 abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
214 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
216 abitest-tcc$(EXESUF): abitest.c libtcc.c
217 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS) $(LDFLAGS) -I$(top_srcdir)
219 ABITESTS := abitest-cc$(EXESUF)
220 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
221 ABITESTS += abitest-tcc$(EXESUF)
222 endif
224 abitest: $(ABITESTS)
225 @echo ------------ $@ ------------
226 ./abitest-cc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
227 if [ "$(CONFIG_arm_eabi)" != "yes" ]; then \
228 ./abitest-tcc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"; fi
230 vla_test$(EXESUF): vla_test.c
231 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS)
232 vla_test-run: vla_test$(EXESUF)
233 @echo ------------ $@ ------------
234 ./vla_test$(EXESUF)
236 # targets for development
237 %.bin: %.c tcc
238 $(TCC) -g -o $@ $<
239 $(DISAS) $@
241 instr: instr.o
242 objdump -d instr.o
244 instr.o: instr.S
245 $(CC) -o $@ -c $< -O2 -Wall -g
247 cache: tcc_g
248 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
249 vg_annotate tcc.c > /tmp/linpack.cache.log
251 # clean
252 clean:
253 $(MAKE) -C tests2 $@
254 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \
255 *-cc *-tcc *.exe \
256 hello libtcc_test vla_test tcctest[1234] ex? tcc_g tcclib.h \
257 ../lib/libtcc1.a