Considering the effect of CH_EOF on line_num
[tinycc.git] / tests / Makefile
blob9ace5b05f5e19867db1177b750894c482bac7c18
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 SRCDIR = $(top_srcdir)/tests
8 VPATH = $(SRCDIR) $(top_srcdir)
10 # what tests to run
11 TESTS = \
12 hello-exe \
13 hello-run \
14 libtest \
15 test3 \
16 $(BTESTS) \
17 abitest \
18 vla_test-run \
19 moretests
21 BTESTS = test1b test3b btest
23 ifdef CONFIG_CROSS
24 TESTS += hello-cross
25 endif
27 # test4 -- problem with -static
28 # asmtest -- minor differences with gcc
29 # btest -- works on i386 (including win32)
31 # bounds-checking is supported only on i386
32 ifneq ($(ARCH),i386)
33 TESTS := $(filter-out $(BTESTS),$(TESTS))
34 endif
35 ifdef CONFIG_WIN32
36 TESTS := w32-prep $(filter-out $(BTESTS),$(TESTS))
37 endif
38 ifeq ($(TARGETOS),Darwin)
39 TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS))
40 endif
41 ifeq ($(ARCH),i386)
42 else ifneq ($(ARCH),x86-64)
43 TESTS := $(filter-out vla_test-run,$(TESTS))
44 endif
46 ifdef DISABLE_STATIC
47 export LD_LIBRARY_PATH:=$(CURDIR)/..
48 endif
50 ifeq ($(TARGETOS),Darwin)
51 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
52 export MACOSX_DEPLOYMENT_TARGET:=10.2
53 NATIVE_DEFINES+=-D_ANSI_SOURCE
54 endif
56 # run local version of tcc with local libraries and includes
57 TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
58 ifdef CONFIG_WIN32
59 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -I$(TOP) -L$(TOP)
60 endif
61 XTCCFLAGS = -B$(TOP) -B$(top_srcdir)/win32 -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
63 TCC = $(TOP)/tcc $(TCCFLAGS)
64 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS)
66 DISAS = objdump -d
68 # libtcc test
69 ifdef LIBTCC1
70 LIBTCC1:=$(TOP)/$(LIBTCC1)
71 endif
73 all test : clean $(TESTS)
75 hello-exe: ../examples/ex1.c
76 @echo ------------ $@ ------------
77 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
79 hello-cross: ../examples/ex1.c
80 @echo ------------ $@ ------------
81 for XTCC in $(PROGS_CROSS) ; \
82 do echo -n "Test of $$XTCC... "; \
83 out=$$($(TOP)/$$XTCC $(XTCCFLAGS) -c $< 2>&1); \
84 test $$? -ne 0 && { echo "Failed\n$$out\n" ; $(TOP)/$$XTCC -vv; exit 1; } ; \
85 echo "Success"; \
86 done
88 hello-run: ../examples/ex1.c
89 @echo ------------ $@ ------------
90 $(TCC) -run $<
92 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
93 @echo ------------ $@ ------------
94 ./libtcc_test$(EXESUF) lib_path=..
96 libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
97 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
99 moretests:
100 @echo ------------ $@ ------------
101 $(MAKE) -C tests2
103 w32-prep:
104 cp ../libtcc1.a ../lib
106 # test.ref - generate using cc
107 test.ref: tcctest.c
108 $(CC) -o tcctest.cc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
109 ./tcctest.cc > $@
111 # auto test
112 test1 test1b: tcctest.c test.ref
113 @echo ------------ $@ ------------
114 $(TCC) -run $< > test.out1
115 @diff -u test.ref test.out1 && echo "Auto Test OK"
117 # iterated test2 (compile tcc then compile tcctest.c !)
118 test2 test2b: tcctest.c test.ref
119 @echo ------------ $@ ------------
120 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
121 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
123 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
124 test3 test3b: tcctest.c test.ref
125 @echo ------------ $@ ------------
126 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
127 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
129 test%b : TCCFLAGS += -b
131 # binary output test
132 test4: tcctest.c test.ref
133 @echo ------------ $@ ------------
134 # object + link output
135 $(TCC) -c -o tcctest3.o $<
136 $(TCC) -o tcctest3 tcctest3.o
137 ./tcctest3 > test3.out
138 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
139 # dynamic output
140 $(TCC) -o tcctest1 $<
141 ./tcctest1 > test1.out
142 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
143 # dynamic output + bound check
144 $(TCC) -b -o tcctest4 $<
145 ./tcctest4 > test4.out
146 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
147 # static output
148 $(TCC) -static -o tcctest2 $<
149 ./tcctest2 > test2.out
150 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
152 # memory and bound check auto test
153 BOUNDS_OK = 1 4 8 10 14
154 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
156 btest: boundtest.c
157 @echo ------------ $@ ------------
158 @for i in $(BOUNDS_OK); do \
159 echo ; echo --- boundtest $$i ---; \
160 if $(TCC) -b -run $< $$i ; then \
161 echo succeeded as expected; \
162 else\
163 echo Failed positive test $$i ; exit 1 ; \
164 fi ;\
165 done ;\
166 for i in $(BOUNDS_FAIL); do \
167 echo ; echo --- boundtest $$i ---; \
168 if $(TCC) -b -run $< $$i ; then \
169 echo Failed negative test $$i ; exit 1 ;\
170 else\
171 echo failed as expected; \
172 fi ;\
173 done ;\
174 echo; echo Bound test OK
176 # speed test
177 speedtest: ex2 ex3
178 @echo ------------ $@ ------------
179 time ./ex2 1238 2 3 4 10 13 4
180 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
181 time ./ex3 35
182 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
184 weaktest: tcctest.c test.ref
185 $(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
186 $(CC) -c $< -o weaktest.cc.o -I. $(CPPFLAGS) -w $(CFLAGS)
187 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
188 objdump -t weaktest.cc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.cc.o.txt
189 diff weaktest.cc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
191 ex%: $(top_srcdir)/examples/ex%.c
192 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
194 # tiny assembler testing
195 asmtest.ref: asmtest.S
196 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
197 objdump -D asmtest.ref.o > asmtest.ref
199 asmtest: asmtest.ref
200 @echo ------------ $@ ------------
201 $(TCC) -c asmtest.S
202 objdump -D asmtest.o > asmtest.out
203 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
205 # Check that code generated by libtcc is binary compatible with
206 # that generated by CC
207 abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
208 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
210 abitest-tcc$(EXESUF): abitest.c libtcc.c
211 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS) $(LDFLAGS) -I$(top_srcdir)
213 abitest: abitest-cc$(EXESUF) abitest-tcc$(EXESUF)
214 @echo ------------ $@ ------------
215 ./abitest-cc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
216 ./abitest-tcc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
218 vla_test$(EXESUF): vla_test.c
219 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS)
220 vla_test-run: vla_test$(EXESUF)
221 @echo ------------ $@ ------------
222 ./vla_test$(EXESUF)
224 # targets for development
225 %.bin: %.c tcc
226 $(TCC) -g -o $@ $<
227 $(DISAS) $@
229 instr: instr.o
230 objdump -d instr.o
232 instr.o: instr.S
233 $(CC) -o $@ -c $< -O2 -Wall -g
235 cache: tcc_g
236 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
237 vg_annotate tcc.c > /tmp/linpack.cache.log
239 # clean
240 clean:
241 $(MAKE) -C tests2 $@
242 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \
243 *-cc *-tcc *.exe \
244 hello libtcc_test vla_test tcctest[1234] ex? tcc_g tcclib.h \
245 ../lib/libtcc1.a