x86_64: Use addend on relocs
[tinycc.git] / tests / Makefile
blobcf817adf06ce87fb57104d6fb4de8a280a879f19
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 (,$(filter arm64 i386 x86-64,$(ARCH)))
45 TESTS := $(filter-out vla_test-run,$(TESTS))
46 endif
47 ifeq ($(CONFIG_arm_eabi),yes)
48 TESTS := $(filter-out test3,$(TESTS))
49 endif
51 ifdef DISABLE_STATIC
52 export LD_LIBRARY_PATH:=$(CURDIR)/..
53 endif
55 ifeq ($(TARGETOS),Darwin)
56 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
57 export MACOSX_DEPLOYMENT_TARGET:=10.2
58 NATIVE_DEFINES+=-D_ANSI_SOURCE
59 endif
61 # run local version of tcc with local libraries and includes
62 TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include -L$(TOP)
63 ifdef CONFIG_WIN32
64 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -L$(TOP)
65 endif
66 XTCCFLAGS = -B$(TOP) -B$(top_srcdir)/win32 -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
68 TCC = $(TOP)/tcc $(TCCFLAGS)
69 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS)
71 DISAS = objdump -d
73 # libtcc test
74 ifdef LIBTCC1
75 ifdef CONFIG_WIN32
76 LIBTCC1:=$(TOP)/win32/libtcc/libtcc.a
77 else
78 LIBTCC1:=$(TOP)/$(LIBTCC1)
79 endif
80 endif
82 all test : $(TESTS)
84 hello-exe: ../examples/ex1.c
85 @echo ------------ $@ ------------
86 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
88 hello-cross: ../examples/ex1.c
89 @echo ------------ $@ ------------
90 for XTCC in $(PROGS_CROSS) ; \
91 do echo -n "Test of $$XTCC... "; \
92 out=$$($(TOP)/$$XTCC $(XTCCFLAGS) -c $< 2>&1); \
93 test $$? -ne 0 && { echo "Failed\n$$out\n" ; $(TOP)/$$XTCC -vv; exit 1; } ; \
94 echo "Success"; \
95 done
97 hello-run: ../examples/ex1.c
98 @echo ------------ $@ ------------
99 $(TCC) -run $<
101 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
102 @echo ------------ $@ ------------
103 ./libtcc_test$(EXESUF) $(TCCFLAGS)
105 libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
106 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
108 %-dir:
109 @echo ------------ $@ ------------
110 $(MAKE) -k -C $*
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) -m32 -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) $(TCCFLAGS)
227 if [ "$(CONFIG_arm_eabi)" != "yes" ]; then ./abitest-tcc$(EXESUF) $(TCCFLAGS); fi
229 vla_test$(EXESUF): vla_test.c
230 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS)
231 vla_test-run: vla_test$(EXESUF)
232 @echo ------------ $@ ------------
233 ./vla_test$(EXESUF)
235 # targets for development
236 %.bin: %.c tcc
237 $(TCC) -g -o $@ $<
238 $(DISAS) $@
240 instr: instr.o
241 objdump -d instr.o
243 instr.o: instr.S
244 $(CC) -o $@ -c $< -O2 -Wall -g
246 cache: tcc_g
247 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
248 vg_annotate tcc.c > /tmp/linpack.cache.log
250 # clean
251 clean:
252 $(MAKE) -C tests2 $@
253 $(MAKE) -C pp $@
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