x86-asm: Implement clflush opcode
[tinycc.git] / tests / Makefile
bloba86e8a2ff53e224930c19db43ed6385b265bedaa
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 dlltest \
17 abitest \
18 vla_test-run \
19 tests2-dir \
20 pp-dir
22 BTESTS = test1b test3b btest
24 # test4 -- problem with -static
25 # asmtest / asmtest2 -- minor differences with gcc
26 # btest -- works on i386 (including win32)
28 # bounds-checking is supported only on i386
29 ifneq ($(ARCH),i386)
30 TESTS := $(filter-out $(BTESTS),$(TESTS))
31 endif
32 ifdef CONFIG_WIN32
33 TESTS := $(filter-out $(BTESTS),$(TESTS))
34 endif
35 ifeq ($(TARGETOS),Darwin)
36 TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS))
37 endif
38 ifeq (,$(filter arm64 i386 x86-64,$(ARCH)))
39 TESTS := $(filter-out vla_test-run,$(TESTS))
40 endif
41 ifeq ($(CONFIG_arm_eabi),yes)
42 TESTS := $(filter-out test3,$(TESTS))
43 endif
44 ifeq (,$(filter i386 x86-64,$(ARCH)))
45 TESTS := $(filter-out dlltest,$(TESTS))
46 endif
48 # run local version of tcc with local libraries and includes
49 TCCFLAGS = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
50 ifdef CONFIG_WIN32
51 TCCFLAGS = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
52 PATH := $(CURDIR)/$(TOP):$(PATH) # for libtcc_test to find libtcc.dll
53 endif
55 TCC = $(TOP)/tcc $(TCCFLAGS)
56 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS)
58 ifeq ($(TARGETOS),Darwin)
59 CFLAGS += -Wl,-flat_namespace,-undefined,warning
60 TCCFLAGS += -D_ANSI_SOURCE
61 export MACOSX_DEPLOYMENT_TARGET:=10.2
62 endif
64 DISAS = objdump -d
66 all test : clean-s $(TESTS)
68 hello-exe: ../examples/ex1.c
69 @echo ------------ $@ ------------
70 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
72 hello-run: ../examples/ex1.c
73 @echo ------------ $@ ------------
74 $(TCC) -run $<
76 libtest: libtcc_test$(EXESUF)
77 @echo ------------ $@ ------------
78 ./libtcc_test$(EXESUF) $(TCCFLAGS)
80 libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
81 $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
83 %-dir:
84 @echo ------------ $@ ------------
85 $(MAKE) -k -C $*
87 # test.ref - generate using cc
88 test.ref: tcctest.c
89 $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
90 ./tcctest.gcc > $@
92 # auto test
93 test1 test1b: tcctest.c test.ref
94 @echo ------------ $@ ------------
95 $(TCC) -run $< > test.out1
96 @diff -u test.ref test.out1 && echo "Auto Test OK"
98 # iterated test2 (compile tcc then compile tcctest.c !)
99 test2 test2b: tcctest.c test.ref
100 @echo ------------ $@ ------------
101 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
102 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
104 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
105 test3 test3b: tcctest.c test.ref
106 @echo ------------ $@ ------------
107 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
108 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
110 test%b : TCCFLAGS += -b
112 # binary output test
113 test4: tcctest.c test.ref
114 @echo ------------ $@ ------------
115 # object + link output
116 $(TCC) -c -o tcctest3.o $<
117 $(TCC) -o tcctest3 tcctest3.o
118 ./tcctest3 > test3.out
119 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
120 # dynamic output
121 $(TCC) -o tcctest1 $<
122 ./tcctest1 > test1.out
123 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
124 # dynamic output + bound check
125 $(TCC) -b -o tcctest4 $<
126 ./tcctest4 > test4.out
127 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
128 # static output
129 $(TCC) -static -o tcctest2 $<
130 ./tcctest2 > test2.out
131 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
133 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
134 dlltest:
135 @echo ------------ $@ ------------
136 $(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL ../libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
137 $(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
138 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c
139 ifndef CONFIG_WIN32
140 @echo ------------ $@ with PIC ------------
141 $(CC) $(CFLAGS) -fPIC -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c ../libtcc.c
142 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
143 $(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
144 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c
145 endif
146 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
149 # memory and bound check auto test
150 BOUNDS_OK = 1 4 8 10 14
151 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
153 btest: boundtest.c
154 @echo ------------ $@ ------------
155 @for i in $(BOUNDS_OK); do \
156 echo ; echo --- boundtest $$i ---; \
157 if $(TCC) -b -run $< $$i ; then \
158 echo succeeded as expected; \
159 else\
160 echo Failed positive test $$i ; exit 1 ; \
161 fi ;\
162 done ;\
163 for i in $(BOUNDS_FAIL); do \
164 echo ; echo --- boundtest $$i ---; \
165 if $(TCC) -b -run $< $$i ; then \
166 echo Failed negative test $$i ; exit 1 ;\
167 else\
168 echo failed as expected; \
169 fi ;\
170 done ;\
171 echo; echo Bound test OK
173 # speed test
174 speedtest: ex2 ex3
175 @echo ------------ $@ ------------
176 time ./ex2 1238 2 3 4 10 13 4
177 time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
178 time ./ex3 35
179 time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
181 weaktest: tcctest.c test.ref
182 $(TCC) -c $< -o weaktest.tcc.o
183 $(CC) -c $< -o weaktest.gcc.o -I. $(CFLAGS)
184 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
185 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
186 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
188 ex%: $(TOPSRC)/examples/ex%.c
189 $(CC) -o $@ $< $(CFLAGS)
191 # tiny assembler testing
192 asmtest.ref: asmtest.S
193 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
194 objdump -D asmtest.ref.o > asmtest.ref
196 asmtest asmtest2: asmtest.ref
197 @echo ------------ $@ ------------
198 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
199 objdump -D asmtest.o > asmtest.out
200 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
202 # test assembler with tcc compiled by itself
203 asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
205 # Check that code generated by libtcc is binary compatible with
206 # that generated by CC
207 abitest-cc$(EXESUF): abitest.c $(LIBTCC)
208 $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
210 abitest-tcc$(EXESUF): abitest.c libtcc.c
211 $(TCC) -o $@ $^ $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS)
213 ABITESTS := abitest-cc$(EXESUF)
214 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
215 ABITESTS += abitest-tcc$(EXESUF)
216 endif
218 abitest: $(ABITESTS)
219 @echo ------------ $@ ------------
220 ./abitest-cc$(EXESUF) $(TCCFLAGS)
221 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
222 ./abitest-tcc$(EXESUF) $(TCCFLAGS)
223 endif
225 vla_test$(EXESUF): vla_test.c
226 $(TCC) -o $@ $^
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 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc \
250 *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] ex? tcc_g
251 $(MAKE) -C tests2 $@
252 $(MAKE) -C pp $@
254 # silent clean, used before running tests
255 clean-s:
256 @$(MAKE) -s --no-print-directory clean