Add armv6l to ARM supported processors
[tinycc.git] / tests / Makefile
blob4f057f4904b721e4e4113829d7ae745afc51e3a1
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 # these should work too
21 # TESTS += test1 test2 speedtest btest weaktest
23 # some tests do not pass on all platforms, remove them for now
24 ifeq ($(TARGETOS),Linux)
25 TESTS := $(filter-out btest,$(TESTS))
26 TESTS := $(filter-out weaktest,$(TESTS))
27 endif
28 ifeq ($(TARGETOS),Darwin)
29 TESTS := $(filter-out test1,$(TESTS))
30 TESTS := $(filter-out test2,$(TESTS))
31 TESTS := $(filter-out test3,$(TESTS))
32 TESTS := $(filter-out btest,$(TESTS))
33 TESTS := $(filter-out weaktest,$(TESTS))
34 endif
36 ifdef DISABLE_STATIC
37 export LD_LIBRARY_PATH:=$(CURDIR)/..
38 endif
40 ifeq ($(TARGETOS),Darwin)
41 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
42 export MACOSX_DEPLOYMENT_TARGET:=10.2
43 NATIVE_DEFINES+=-D_ANSI_SOURCE
44 endif
46 # run local version of tcc with local libraries and includes
47 TCC = ../tcc -B.. $(NATIVE_DEFINES)
48 ifdef CONFIG_WIN32
49 TCC := $(TCC) -I $(TOP)/win32/include -L$(TOP)
50 endif
51 RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..
52 DISAS=objdump -d
54 all test : $(TESTS)
56 # make sure that tcc exists
57 test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc
58 ../%:
59 $(MAKE) -C .. $*
61 # libtcc test
62 ifdef LIBTCC1
63 LIBTCC1:=$(TOP)/$(LIBTCC1)
64 endif
66 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
67 @echo ------------ $@ ------------
68 ./libtcc_test$(EXESUF) lib_path=..
70 libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)
71 $(CC) -o $@ $^ -I.. $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
73 # test.ref - generate using gcc
74 # copy only tcclib.h so GCC's stddef and stdarg will be used
75 test.ref: tcctest.c
76 cp ../include/tcclib.h .
77 $(CC) -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 $(LDFLAGS)
78 ./tcctest.gcc > $@
80 # auto test
81 test1: test.ref
82 @echo ------------ $@ ------------
83 $(TCC) -run tcctest.c > test.out1
84 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
86 # iterated test2 (compile tcc then compile tcctest.c !)
87 test2: test.ref
88 @echo ------------ $@ ------------
89 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
90 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
92 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
93 test3: test.ref
94 @echo ------------ $@ ------------
95 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
96 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
98 # binary output test
99 test4: test.ref
100 @echo ------------ $@ ------------
101 # dynamic output
102 $(TCC) -o tcctest1 tcctest.c
103 ./tcctest1 > test1.out
104 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
105 # object + link output
106 $(TCC) -c -o tcctest3.o tcctest.c
107 $(TCC) -o tcctest3 tcctest3.o
108 ./tcctest3 > test3.out
109 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
110 # static output
111 $(TCC) -static -o tcctest2 tcctest.c
112 ./tcctest2 > test2.out
113 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
114 # dynamic output + bound check
115 $(TCC) -b -o tcctest4 tcctest.c
116 ./tcctest4 > test4.out
117 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
119 # memory and bound check auto test
120 BOUNDS_OK = 1 4 8 10 14
121 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
123 btest: boundtest.c ../bcheck.o
124 @echo ------------ $@ ------------
125 @for i in $(BOUNDS_OK); do \
126 echo ; echo --- boundtest $$i ---; \
127 if $(TCC) -b -run boundtest.c $$i ; then \
128 echo succeded as expected; \
129 else\
130 echo Failed positive test $$i ; exit 1 ; \
131 fi ;\
132 done ;\
133 for i in $(BOUNDS_FAIL); do \
134 echo ; echo --- boundtest $$i ---; \
135 if $(TCC) -b -run boundtest.c $$i ; then \
136 echo Failed negative test $$i ; exit 1 ;\
137 else\
138 echo failed as expected; \
139 fi ;\
140 done ;\
141 echo; echo Bound test OK
143 # speed test
144 speedtest: ex2 ex3
145 @echo ------------ $@ ------------
146 time ./ex2 1238 2 3 4 10 13 4
147 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
148 time ./ex3 35
149 time $(TCC) -run ../examples/ex3.c 35
151 weaktest: test.ref
152 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
153 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
154 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
155 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
156 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
158 ex%: ../examples/ex%.c
159 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
161 # tiny assembler testing
162 asmtest.ref: asmtest.S
163 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
164 objdump -D asmtest.ref.o > asmtest.ref
166 asmtest: asmtest.ref
167 @echo ------------ $@ ------------
168 $(TCC) -c asmtest.S
169 objdump -D asmtest.o > asmtest.out
170 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
172 # targets for development
173 %.bin: %.c tcc
174 $(TCC) -g -o $@ $<
175 $(DISAS) $@
177 instr: instr.o
178 objdump -d instr.o
180 instr.o: instr.S
181 $(CC) -o $@ -c $< -O2 -Wall -g
183 cache: tcc_g
184 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
185 vg_annotate tcc.c > /tmp/linpack.cache.log
187 # clean
188 clean:
189 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
190 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h