Use functions to get relocation info
[tinycc/jakubkaszycki.git] / tests / Makefile
blob50b3a8cd963abbb805e45a17a3914f4141809f5a
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
8 CFLAGS = -I$(TOPSRC) -I$(TOP)
10 # what tests to run
11 TESTS = \
12 hello-exe \
13 hello-run \
14 libtest \
15 test3 \
16 abitest \
17 vla_test-run \
18 tests2-dir \
19 pp-dir
21 BTESTS = test1b test3b btest
23 # test4 -- problem with -static
24 # asmtest / asmtest2 -- minor differences with gcc
25 # btest -- works on i386 (including win32)
27 # bounds-checking is supported only on i386
28 ifneq ($(ARCH),i386)
29 TESTS := $(filter-out $(BTESTS),$(TESTS))
30 endif
31 ifdef CONFIG_WIN32
32 TESTS := $(filter-out $(BTESTS),$(TESTS))
33 endif
34 ifeq ($(TARGETOS),Darwin)
35 TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS))
36 endif
37 ifeq (,$(filter arm64 i386 x86-64,$(ARCH)))
38 TESTS := $(filter-out vla_test-run,$(TESTS))
39 endif
40 ifeq ($(CONFIG_arm_eabi),yes)
41 TESTS := $(filter-out test3,$(TESTS))
42 endif
44 # run local version of tcc with local libraries and includes
45 TCCFLAGS = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
46 ifdef CONFIG_WIN32
47 TCCFLAGS = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
48 PATH := $(CURDIR)/$(TOP):$(PATH) # for libtcc_test to find libtcc.dll
49 endif
51 TCC = $(TOP)/tcc $(TCCFLAGS)
52 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS)
54 ifeq ($(TARGETOS),Darwin)
55 CFLAGS += -Wl,-flat_namespace,-undefined,warning
56 TCCFLAGS += -D_ANSI_SOURCE
57 export MACOSX_DEPLOYMENT_TARGET:=10.2
58 endif
60 DISAS = objdump -d
62 all test : clean-s $(TESTS)
64 hello-exe: ../examples/ex1.c
65 @echo ------------ $@ ------------
66 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
68 hello-run: ../examples/ex1.c
69 @echo ------------ $@ ------------
70 $(TCC) -run $<
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 # memory and bound check auto test
130 BOUNDS_OK = 1 4 8 10 14
131 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
133 btest: boundtest.c
134 @echo ------------ $@ ------------
135 @for i in $(BOUNDS_OK); do \
136 echo ; echo --- boundtest $$i ---; \
137 if $(TCC) -b -run $< $$i ; then \
138 echo succeeded as expected; \
139 else\
140 echo Failed positive test $$i ; exit 1 ; \
141 fi ;\
142 done ;\
143 for i in $(BOUNDS_FAIL); do \
144 echo ; echo --- boundtest $$i ---; \
145 if $(TCC) -b -run $< $$i ; then \
146 echo Failed negative test $$i ; exit 1 ;\
147 else\
148 echo failed as expected; \
149 fi ;\
150 done ;\
151 echo; echo Bound test OK
153 # speed test
154 speedtest: ex2 ex3
155 @echo ------------ $@ ------------
156 time ./ex2 1238 2 3 4 10 13 4
157 time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
158 time ./ex3 35
159 time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
161 weaktest: tcctest.c test.ref
162 $(TCC) -c $< -o weaktest.tcc.o
163 $(CC) -c $< -o weaktest.gcc.o -I. $(CFLAGS)
164 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
165 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
166 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
168 ex%: $(TOPSRC)/examples/ex%.c
169 $(CC) -o $@ $< $(CFLAGS)
171 # tiny assembler testing
172 asmtest.ref: asmtest.S
173 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
174 objdump -D asmtest.ref.o > asmtest.ref
176 asmtest asmtest2: asmtest.ref
177 @echo ------------ $@ ------------
178 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
179 objdump -D asmtest.o > asmtest.out
180 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
182 # test assembler with tcc compiled by itself
183 asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
185 # Check that code generated by libtcc is binary compatible with
186 # that generated by CC
187 abitest-cc$(EXESUF): abitest.c $(LIBTCC)
188 $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
190 abitest-tcc$(EXESUF): abitest.c libtcc.c
191 $(TCC) -o $@ $^ $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS)
193 ABITESTS := abitest-cc$(EXESUF)
194 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
195 ABITESTS += abitest-tcc$(EXESUF)
196 endif
198 abitest: $(ABITESTS)
199 @echo ------------ $@ ------------
200 ./abitest-cc$(EXESUF) $(TCCFLAGS)
201 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
202 ./abitest-tcc$(EXESUF) $(TCCFLAGS)
203 endif
205 vla_test$(EXESUF): vla_test.c
206 $(TCC) -o $@ $^
208 vla_test-run: vla_test$(EXESUF)
209 @echo ------------ $@ ------------
210 ./vla_test$(EXESUF)
212 # targets for development
213 %.bin: %.c tcc
214 $(TCC) -g -o $@ $<
215 $(DISAS) $@
217 instr: instr.o
218 objdump -d instr.o
220 instr.o: instr.S
221 $(CC) -o $@ -c $< -O2 -Wall -g
223 cache: tcc_g
224 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
225 vg_annotate tcc.c > /tmp/linpack.cache.log
227 # clean
228 clean:
229 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc \
230 *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] ex? tcc_g
231 $(MAKE) -C tests2 $@
232 $(MAKE) -C pp $@
234 # silent clean, used before running tests
235 clean-s:
236 @$(MAKE) -s --no-print-directory clean