fix-mixed-struct (patch by Pip Cet)
[tinycc.git] / tests / Makefile
blob270eaa710012b702bac23dbe90aa2f38f17349a1
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 tests2-dir pp-dir
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 := $(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 -L$(TOP)
64 ifdef CONFIG_WIN32
65 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -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) $(TCCFLAGS)
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 %-dir:
106 @echo ------------ $@ ------------
107 $(MAKE) -k -C $*
109 # test.ref - generate using cc
110 test.ref: tcctest.c
111 $(CC) -o tcctest.cc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
112 ./tcctest.cc > $@
114 # auto test
115 test1 test1b: tcctest.c test.ref
116 @echo ------------ $@ ------------
117 $(TCC) -run $< > test.out1
118 @diff -u test.ref test.out1 && echo "Auto Test OK"
120 # iterated test2 (compile tcc then compile tcctest.c !)
121 test2 test2b: tcctest.c test.ref
122 @echo ------------ $@ ------------
123 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
124 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
126 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
127 test3 test3b: tcctest.c test.ref
128 @echo ------------ $@ ------------
129 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
130 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
132 test%b : TCCFLAGS += -b
134 # binary output test
135 test4: tcctest.c test.ref
136 @echo ------------ $@ ------------
137 # object + link output
138 $(TCC) -c -o tcctest3.o $<
139 $(TCC) -o tcctest3 tcctest3.o
140 ./tcctest3 > test3.out
141 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
142 # dynamic output
143 $(TCC) -o tcctest1 $<
144 ./tcctest1 > test1.out
145 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
146 # dynamic output + bound check
147 $(TCC) -b -o tcctest4 $<
148 ./tcctest4 > test4.out
149 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
150 # static output
151 $(TCC) -static -o tcctest2 $<
152 ./tcctest2 > test2.out
153 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
155 # memory and bound check auto test
156 BOUNDS_OK = 1 4 8 10 14
157 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
159 btest: boundtest.c
160 @echo ------------ $@ ------------
161 @for i in $(BOUNDS_OK); do \
162 echo ; echo --- boundtest $$i ---; \
163 if $(TCC) -b -run $< $$i ; then \
164 echo succeeded as expected; \
165 else\
166 echo Failed positive test $$i ; exit 1 ; \
167 fi ;\
168 done ;\
169 for i in $(BOUNDS_FAIL); do \
170 echo ; echo --- boundtest $$i ---; \
171 if $(TCC) -b -run $< $$i ; then \
172 echo Failed negative test $$i ; exit 1 ;\
173 else\
174 echo failed as expected; \
175 fi ;\
176 done ;\
177 echo; echo Bound test OK
179 # speed test
180 speedtest: ex2 ex3
181 @echo ------------ $@ ------------
182 time ./ex2 1238 2 3 4 10 13 4
183 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
184 time ./ex3 35
185 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
187 weaktest: tcctest.c test.ref
188 $(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
189 $(CC) -c $< -o weaktest.cc.o -I. $(CPPFLAGS) -w $(CFLAGS)
190 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
191 objdump -t weaktest.cc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.cc.o.txt
192 diff weaktest.cc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
194 ex%: $(top_srcdir)/examples/ex%.c
195 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
197 # tiny assembler testing
198 asmtest.ref: asmtest.S
199 $(CC) -m32 -Wa,-W -o asmtest.ref.o -c asmtest.S
200 objdump -D asmtest.ref.o > asmtest.ref
202 asmtest: asmtest.ref
203 @echo ------------ $@ ------------
204 $(TCC) -c asmtest.S
205 objdump -D asmtest.o > asmtest.out
206 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
208 # Check that code generated by libtcc is binary compatible with
209 # that generated by CC
210 abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
211 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
213 abitest-tcc$(EXESUF): abitest.c libtcc.c
214 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS) $(LDFLAGS) -I$(top_srcdir)
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 if [ "$(CONFIG_arm_eabi)" != "yes" ]; then ./abitest-tcc$(EXESUF) $(TCCFLAGS); fi
226 vla_test$(EXESUF): vla_test.c
227 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS)
228 vla_test-run: vla_test$(EXESUF)
229 @echo ------------ $@ ------------
230 ./vla_test$(EXESUF)
232 # targets for development
233 %.bin: %.c tcc
234 $(TCC) -g -o $@ $<
235 $(DISAS) $@
237 instr: instr.o
238 objdump -d instr.o
240 instr.o: instr.S
241 $(CC) -o $@ -c $< -O2 -Wall -g
243 cache: tcc_g
244 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
245 vg_annotate tcc.c > /tmp/linpack.cache.log
247 # clean
248 clean:
249 $(MAKE) -C tests2 $@
250 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \
251 *-cc *-tcc *.exe \
252 hello libtcc_test vla_test tcctest[1234] ex? tcc_g