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