Make abitest.c have predictable result
[tinycc.git] / tests / Makefile
blob08dfa42b20025ca87f187238f1e272eb386510e3
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 SRCDIR = $(top_srcdir)/tests
8 VPATH = $(SRCDIR)
10 # what tests to run
11 TESTS = \
12 hello-exe \
13 hello-run \
14 libtest \
15 test3 \
16 abitest \
17 vla_test-run \
18 moretests
20 # test4 -- problem with -static
21 # asmtest -- minor differences with gcc
22 # btest -- works on i386 (including win32)
23 # test3 -- win32 does not know how to printf long doubles
25 # bounds-checking is supported only on i386
26 ifneq ($(ARCH),i386)
27 TESTS := $(filter-out btest,$(TESTS))
28 endif
29 ifdef CONFIG_WIN32
30 TESTS := $(filter-out test3,$(TESTS))
31 endif
32 ifeq ($(TARGETOS),Darwin)
33 TESTS := $(filter-out hello-exe test3 btest,$(TESTS))
34 endif
35 ifeq ($(ARCH),i386)
36 else ifneq ($(ARCH),x86-64)
37 TESTS := $(filter-out vla_test-run,$(TESTS))
38 endif
40 ifdef DISABLE_STATIC
41 export LD_LIBRARY_PATH:=$(CURDIR)/..
42 endif
44 ifeq ($(TARGETOS),Darwin)
45 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
46 export MACOSX_DEPLOYMENT_TARGET:=10.2
47 NATIVE_DEFINES+=-D_ANSI_SOURCE
48 endif
50 # run local version of tcc with local libraries and includes
51 TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
52 ifdef CONFIG_WIN32
53 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -I$(TOP) -L$(TOP)
54 endif
56 TCC = $(TOP)/tcc $(TCCFLAGS)
57 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS)
59 DISAS = objdump -d
61 # libtcc test
62 ifdef LIBTCC1
63 LIBTCC1:=$(TOP)/$(LIBTCC1)
64 endif
66 all test : $(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) $(LIBTCC1)
77 @echo ------------ $@ ------------
78 ./libtcc_test$(EXESUF) lib_path=..
80 libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
81 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
83 moretests:
84 @echo ------------ $@ ------------
85 $(MAKE) -C tests2
87 # test.ref - generate using gcc
88 # copy only tcclib.h so GCC's stddef and stdarg will be used
89 test.ref: tcctest.c
90 gcc -o tcctest.gcc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
91 ./tcctest.gcc > $@
93 # auto test
94 test1: test.ref
95 @echo ------------ $@ ------------
96 $(TCC) -run $(SRCDIR)/tcctest.c > test.out1
97 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
99 # iterated test2 (compile tcc then compile tcctest.c !)
100 test2: test.ref
101 @echo ------------ $@ ------------
102 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out2
103 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
105 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
106 test3: test.ref
107 @echo ------------ $@ ------------
108 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out3
109 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
111 # binary output test
112 test4: test.ref
113 @echo ------------ $@ ------------
114 # object + link output
115 $(TCC) -c -o tcctest3.o $(SRCDIR)/tcctest.c
116 $(TCC) -o tcctest3 tcctest3.o
117 ./tcctest3 > test3.out
118 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
119 # dynamic output
120 $(TCC) -o tcctest1 $(SRCDIR)/tcctest.c
121 ./tcctest1 > test1.out
122 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
123 # dynamic output + bound check
124 $(TCC) -b -o tcctest4 $(SRCDIR)/tcctest.c
125 ./tcctest4 > test4.out
126 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
127 # static output
128 $(TCC) -static -o tcctest2 $(SRCDIR)/tcctest.c
129 ./tcctest2 > test2.out
130 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
132 # memory and bound check auto test
133 BOUNDS_OK = 1 4 8 10 14
134 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
136 btest: boundtest.c
137 @echo ------------ $@ ------------
138 @for i in $(BOUNDS_OK); do \
139 echo ; echo --- boundtest $$i ---; \
140 if $(TCC) -b -run boundtest.c $$i ; then \
141 echo succeded as expected; \
142 else\
143 echo Failed positive test $$i ; exit 1 ; \
144 fi ;\
145 done ;\
146 for i in $(BOUNDS_FAIL); do \
147 echo ; echo --- boundtest $$i ---; \
148 if $(TCC) -b -run boundtest.c $$i ; then \
149 echo Failed negative test $$i ; exit 1 ;\
150 else\
151 echo failed as expected; \
152 fi ;\
153 done ;\
154 echo; echo Bound test OK
156 # speed test
157 speedtest: ex2 ex3
158 @echo ------------ $@ ------------
159 time ./ex2 1238 2 3 4 10 13 4
160 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
161 time ./ex3 35
162 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
164 weaktest: test.ref
165 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
166 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
167 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
168 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
169 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
171 ex%: $(top_srcdir)/examples/ex%.c
172 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
174 # tiny assembler testing
175 asmtest.ref: asmtest.S
176 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
177 objdump -D asmtest.ref.o > asmtest.ref
179 asmtest: asmtest.ref
180 @echo ------------ $@ ------------
181 $(TCC) -c asmtest.S
182 objdump -D asmtest.o > asmtest.out
183 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
185 # Check that code generated by libtcc is binary compatible with
186 # that generated by CC
187 abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
188 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
190 abitest-tcc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
191 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
193 abitest: abitest-cc$(EXESUF) abitest-tcc$(EXESUF)
194 @echo ------------ $@ ------------
195 ./abitest-cc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
196 ./abitest-tcc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
198 vla_test$(EXESUF): vla_test.c
199 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS)
200 vla_test-run: vla_test$(EXESUF)
201 @echo ------------ $@ ------------
202 ./vla_test$(EXESUF)
204 # targets for development
205 %.bin: %.c tcc
206 $(TCC) -g -o $@ $<
207 $(DISAS) $@
209 instr: instr.o
210 objdump -d instr.o
212 instr.o: instr.S
213 $(CC) -o $@ -c $< -O2 -Wall -g
215 cache: tcc_g
216 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
217 vg_annotate tcc.c > /tmp/linpack.cache.log
219 # clean
220 clean:
221 $(MAKE) -C tests2 $@
222 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
223 hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
225 Makefile: $(SRCDIR)/Makefile
226 cp $< $@