af1fdb8440d315d36b2ed18425f69265a886f4ee
[tinycc.git] / tests / Makefile
blobaf1fdb8440d315d36b2ed18425f69265a886f4ee
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 weaktest,$(TESTS))
26 endif
27 ifeq ($(TARGETOS),Darwin)
28 TESTS := $(filter-out test1,$(TESTS))
29 TESTS := $(filter-out test2,$(TESTS))
30 TESTS := $(filter-out test3,$(TESTS))
31 TESTS := $(filter-out btest,$(TESTS))
32 TESTS := $(filter-out weaktest,$(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 TCC = ../tcc -B.. $(NATIVE_DEFINES)
47 ifdef CONFIG_WIN32
48 TCC := $(TCC) -I $(TOP)/win32/include -L$(TOP)
49 endif
50 RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..
51 DISAS=objdump -d
53 all test : $(TESTS)
55 # make sure that tcc exists
56 test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc
57 ../%:
58 $(MAKE) -C .. $*
60 # libtcc test
61 ifdef LIBTCC1
62 LIBTCC1:=$(TOP)/$(LIBTCC1)
63 endif
65 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
66 @echo ------------ $@ ------------
67 ./libtcc_test$(EXESUF) lib_path=..
69 libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)
70 $(CC) -o $@ $^ -I.. $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
72 # test.ref - generate using gcc
73 # copy only tcclib.h so GCC's stddef and stdarg will be used
74 test.ref: tcctest.c
75 cp ../include/tcclib.h .
76 $(CC) -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
77 ./tcctest.gcc > $@
79 # auto test
80 test1: test.ref
81 @echo ------------ $@ ------------
82 $(TCC) -run tcctest.c > test.out1
83 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
85 # iterated test2 (compile tcc then compile tcctest.c !)
86 test2: test.ref
87 @echo ------------ $@ ------------
88 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
89 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
91 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
92 test3: test.ref
93 @echo ------------ $@ ------------
94 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
95 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
97 # binary output test
98 test4: test.ref
99 @echo ------------ $@ ------------
100 # dynamic output
101 $(TCC) -o tcctest1 tcctest.c
102 ./tcctest1 > test1.out
103 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
104 # object + link output
105 $(TCC) -c -o tcctest3.o tcctest.c
106 $(TCC) -o tcctest3 tcctest3.o
107 ./tcctest3 > test3.out
108 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
109 # static output
110 $(TCC) -static -o tcctest2 tcctest.c
111 ./tcctest2 > test2.out
112 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
113 # dynamic output + bound check
114 $(TCC) -b -o tcctest4 tcctest.c
115 ./tcctest4 > test4.out
116 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
118 # memory and bound check auto test
119 BOUNDS_OK = 1 4 8 10 14
120 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
122 btest: boundtest.c ../bcheck.o
123 @echo ------------ $@ ------------
124 @for i in $(BOUNDS_OK); do \
125 echo ; echo --- boundtest $$i ---; \
126 if $(TCC) -b -run boundtest.c $$i ; then \
127 echo succeded as expected; \
128 else\
129 echo Failed positive test $$i ; exit 1 ; \
130 fi ;\
131 done ;\
132 for i in $(BOUNDS_FAIL); do \
133 echo ; echo --- boundtest $$i ---; \
134 if $(TCC) -b -run boundtest.c $$i ; then \
135 echo Failed negative test $$i ; exit 1 ;\
136 else\
137 echo failed as expected; \
138 fi ;\
139 done ;\
140 echo; echo Bound test OK
142 # speed test
143 speedtest: ex2 ex3
144 @echo ------------ $@ ------------
145 time ./ex2 1238 2 3 4 10 13 4
146 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
147 time ./ex3 35
148 time $(TCC) -run ../examples/ex3.c 35
150 weaktest: test.ref
151 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
152 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
153 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
154 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
155 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
157 ex%: ../examples/ex%.c
158 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
160 # tiny assembler testing
161 asmtest.ref: asmtest.S
162 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
163 objdump -D asmtest.ref.o > asmtest.ref
165 asmtest: asmtest.ref
166 @echo ------------ $@ ------------
167 $(TCC) -c asmtest.S
168 objdump -D asmtest.o > asmtest.out
169 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
171 # targets for development
172 %.bin: %.c tcc
173 $(TCC) -g -o $@ $<
174 $(DISAS) $@
176 instr: instr.o
177 objdump -d instr.o
179 instr.o: instr.S
180 $(CC) -o $@ -c $< -O2 -Wall -g
182 cache: tcc_g
183 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
184 vg_annotate tcc.c > /tmp/linpack.cache.log
186 # clean
187 clean:
188 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
189 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h