Fix C99ism in vswap()
[tinycc.git] / tests / Makefile
blobc1833423b5587b385a4de140f57d065da7e3803d
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 VPATH = $(top_srcdir)/tests
9 # what tests to run
10 TESTS = libtest \
11 test1 \
12 test2 \
13 test3 \
14 speedtest \
15 btest \
16 test1b\
17 test2b\
18 test3b\
19 weaktest
21 # test4 # this test does not seem to work on any platform
22 # asmtest # this test does not seem to work on any platform
24 # bounds-checking is supported only on i386
25 ifneq ($(ARCH),i386)
26 TESTS := $(filter-out btest,$(TESTS))
27 TESTS := $(filter-out test1b,$(TESTS))
28 TESTS := $(filter-out test2b,$(TESTS))
29 TESTS := $(filter-out test3b,$(TESTS))
30 endif
32 # these should work too
33 # TESTS += test1 test2 speedtest btest weaktest
35 # some tests do not pass on all platforms, remove them for now
36 ifeq ($(TARGETOS),Linux)
37 TESTS := $(filter-out weaktest,$(TESTS))
38 endif
39 ifeq ($(TARGETOS),Darwin)
40 TESTS := $(filter-out test1,$(TESTS))
41 TESTS := $(filter-out test2,$(TESTS))
42 TESTS := $(filter-out test3,$(TESTS))
43 TESTS := $(filter-out btest,$(TESTS))
44 TESTS := $(filter-out weaktest,$(TESTS))
45 endif
47 ifdef DISABLE_STATIC
48 export LD_LIBRARY_PATH:=$(CURDIR)/..
49 endif
51 ifeq ($(TARGETOS),Darwin)
52 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
53 export MACOSX_DEPLOYMENT_TARGET:=10.2
54 NATIVE_DEFINES+=-D_ANSI_SOURCE
55 endif
57 # run local version of tcc with local libraries and includes
58 TCC = ../tcc -B.. $(NATIVE_DEFINES)
59 ifdef CONFIG_WIN32
60 TCC := $(TCC) -I $(top_srcdir)/win32/include -L$(top_build)
61 endif
62 RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..
63 DISAS=objdump -d
65 all test : $(TESTS)
67 # make sure that tcc exists
68 test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc
69 ../%:
70 $(MAKE) -C .. $*
72 # libtcc test
73 ifdef LIBTCC1
74 LIBTCC1:=$(TOP)/$(LIBTCC1)
75 endif
77 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
78 @echo ------------ $@ ------------
79 ./libtcc_test$(EXESUF) lib_path=..
81 libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
82 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
84 # test.ref - generate using gcc
85 # copy only tcclib.h so GCC's stddef and stdarg will be used
86 test.ref: tcctest.c
87 cp ../include/tcclib.h .
88 $(CC) -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
89 ./tcctest.gcc > $@
91 # auto test
92 test1: test.ref
93 @echo ------------ $@ ------------
94 $(TCC) -run tcctest.c > test.out1
95 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
97 test1b: test.ref
98 @echo ------------ $@ ------------
99 $(TCC) -b -run tcctest.c > test.out1b
100 @if diff -u test.ref test.out1b ; then echo "Auto Test OK"; fi
102 # iterated test2 (compile tcc then compile tcctest.c !)
103 test2: test.ref
104 @echo ------------ $@ ------------
105 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
106 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
108 test2b: test.ref ../bcheck.o
109 @echo ------------ $@ ------------
110 $(TCC) -b $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2b
111 @if diff -u test.ref test.out2b ; then echo "Auto Test2b OK"; fi
113 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
114 test3: test.ref
115 @echo ------------ $@ ------------
116 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
117 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
119 test3b: test.ref
120 @echo ------------ $@ ------------
121 $(TCC) -b $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3b
122 @if diff -u test.ref test.out3b ; then echo "Auto Test3 OK"; fi
124 # binary output test
125 test4: test.ref
126 @echo ------------ $@ ------------
127 # dynamic output
128 $(TCC) -o tcctest1 tcctest.c
129 ./tcctest1 > test1.out
130 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
131 # object + link output
132 $(TCC) -c -o tcctest3.o tcctest.c
133 $(TCC) -o tcctest3 tcctest3.o
134 ./tcctest3 > test3.out
135 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
136 # static output
137 $(TCC) -static -o tcctest2 tcctest.c
138 ./tcctest2 > test2.out
139 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
140 # dynamic output + bound check
141 $(TCC) -b -o tcctest4 tcctest.c
142 ./tcctest4 > test4.out
143 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
145 # memory and bound check auto test
146 BOUNDS_OK = 1 4 8 10 14
147 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
149 btest: boundtest.c ../bcheck.o
150 @echo ------------ $@ ------------
151 @for i in $(BOUNDS_OK); do \
152 echo ; echo --- boundtest $$i ---; \
153 if $(TCC) -b -run boundtest.c $$i ; then \
154 echo succeded as expected; \
155 else\
156 echo Failed positive test $$i ; exit 1 ; \
157 fi ;\
158 done ;\
159 for i in $(BOUNDS_FAIL); do \
160 echo ; echo --- boundtest $$i ---; \
161 if $(TCC) -b -run boundtest.c $$i ; then \
162 echo Failed negative test $$i ; exit 1 ;\
163 else\
164 echo failed as expected; \
165 fi ;\
166 done ;\
167 echo; echo Bound test OK
169 # speed test
170 speedtest: ex2 ex3
171 @echo ------------ $@ ------------
172 time ./ex2 1238 2 3 4 10 13 4
173 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
174 time ./ex3 35
175 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
177 weaktest: test.ref
178 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
179 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
180 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
181 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
182 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
184 ex%: $(top_srcdir)/examples/ex%.c
185 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
187 # tiny assembler testing
188 asmtest.ref: asmtest.S
189 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
190 objdump -D asmtest.ref.o > asmtest.ref
192 asmtest: asmtest.ref
193 @echo ------------ $@ ------------
194 $(TCC) -c asmtest.S
195 objdump -D asmtest.o > asmtest.out
196 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
198 # targets for development
199 %.bin: %.c tcc
200 $(TCC) -g -o $@ $<
201 $(DISAS) $@
203 instr: instr.o
204 objdump -d instr.o
206 instr.o: instr.S
207 $(CC) -o $@ -c $< -O2 -Wall -g
209 cache: tcc_g
210 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
211 vg_annotate tcc.c > /tmp/linpack.cache.log
213 # clean
214 clean:
215 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc \
216 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h