tests: btest should only run on targets supporting bcheck
[tinycc.git] / tests / Makefile
blobda7c3f971237399cb0664ad71f81b6a8be2fdc4b
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
8 # what tests to run
9 TESTS = libtest \
10 test1 \
11 test2 \
12 test3 \
13 speedtest \
14 btest \
15 weaktest
17 # test4 # this test does not seem to work on any platform
18 # asmtest # this test does not seem to work on any platform
20 # bounds-checking is supported only on i386
21 ifneq ($(ARCH),i386)
22 TESTS := $(filter-out btest,$(TESTS))
23 endif
25 # these should work too
26 # TESTS += test1 test2 speedtest btest weaktest
28 # some tests do not pass on all platforms, remove them for now
29 ifeq ($(TARGETOS),Linux)
30 TESTS := $(filter-out weaktest,$(TESTS))
31 endif
32 ifeq ($(TARGETOS),Darwin)
33 TESTS := $(filter-out test1,$(TESTS))
34 TESTS := $(filter-out test2,$(TESTS))
35 TESTS := $(filter-out test3,$(TESTS))
36 TESTS := $(filter-out btest,$(TESTS))
37 TESTS := $(filter-out weaktest,$(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 TCC = ../tcc -B.. $(NATIVE_DEFINES)
52 ifdef CONFIG_WIN32
53 TCC := $(TCC) -I $(TOP)/win32/include -L$(TOP)
54 endif
55 RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..
56 DISAS=objdump -d
58 all test : $(TESTS)
60 # make sure that tcc exists
61 test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc
62 ../%:
63 $(MAKE) -C .. $*
65 # libtcc test
66 ifdef LIBTCC1
67 LIBTCC1:=$(TOP)/$(LIBTCC1)
68 endif
70 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
71 @echo ------------ $@ ------------
72 ./libtcc_test$(EXESUF) lib_path=..
74 libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)
75 $(CC) -o $@ $^ -I.. $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
77 # test.ref - generate using gcc
78 # copy only tcclib.h so GCC's stddef and stdarg will be used
79 test.ref: tcctest.c
80 cp ../include/tcclib.h .
81 $(CC) -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
82 ./tcctest.gcc > $@
84 # auto test
85 test1: test.ref
86 @echo ------------ $@ ------------
87 $(TCC) -run tcctest.c > test.out1
88 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
90 # iterated test2 (compile tcc then compile tcctest.c !)
91 test2: test.ref
92 @echo ------------ $@ ------------
93 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
94 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
96 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
97 test3: test.ref
98 @echo ------------ $@ ------------
99 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
100 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
102 # binary output test
103 test4: test.ref
104 @echo ------------ $@ ------------
105 # dynamic output
106 $(TCC) -o tcctest1 tcctest.c
107 ./tcctest1 > test1.out
108 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
109 # object + link output
110 $(TCC) -c -o tcctest3.o 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 # static output
115 $(TCC) -static -o tcctest2 tcctest.c
116 ./tcctest2 > test2.out
117 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
118 # dynamic output + bound check
119 $(TCC) -b -o tcctest4 tcctest.c
120 ./tcctest4 > test4.out
121 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
123 # memory and bound check auto test
124 BOUNDS_OK = 1 4 8 10 14
125 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
127 btest: boundtest.c ../bcheck.o
128 @echo ------------ $@ ------------
129 @for i in $(BOUNDS_OK); do \
130 echo ; echo --- boundtest $$i ---; \
131 if $(TCC) -b -run boundtest.c $$i ; then \
132 echo succeded as expected; \
133 else\
134 echo Failed positive test $$i ; exit 1 ; \
135 fi ;\
136 done ;\
137 for i in $(BOUNDS_FAIL); do \
138 echo ; echo --- boundtest $$i ---; \
139 if $(TCC) -b -run boundtest.c $$i ; then \
140 echo Failed negative test $$i ; exit 1 ;\
141 else\
142 echo failed as expected; \
143 fi ;\
144 done ;\
145 echo; echo Bound test OK
147 # speed test
148 speedtest: ex2 ex3
149 @echo ------------ $@ ------------
150 time ./ex2 1238 2 3 4 10 13 4
151 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
152 time ./ex3 35
153 time $(TCC) -run ../examples/ex3.c 35
155 weaktest: test.ref
156 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
157 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
158 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
159 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
160 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
162 ex%: ../examples/ex%.c
163 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
165 # tiny assembler testing
166 asmtest.ref: asmtest.S
167 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
168 objdump -D asmtest.ref.o > asmtest.ref
170 asmtest: asmtest.ref
171 @echo ------------ $@ ------------
172 $(TCC) -c asmtest.S
173 objdump -D asmtest.o > asmtest.out
174 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
176 # targets for development
177 %.bin: %.c tcc
178 $(TCC) -g -o $@ $<
179 $(DISAS) $@
181 instr: instr.o
182 objdump -d instr.o
184 instr.o: instr.S
185 $(CC) -o $@ -c $< -O2 -Wall -g
187 cache: tcc_g
188 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
189 vg_annotate tcc.c > /tmp/linpack.cache.log
191 # clean
192 clean:
193 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
194 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h