0e6fc46f469d7dcb855e6548ac3b198f70cee6a6
[tinycc.git] / tests / Makefile
blob0e6fc46f469d7dcb855e6548ac3b198f70cee6a6
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 VPATH = $(top_srcdir)/tests
9 # what tests to run
10 TESTS = \
11 hello \
12 libtest \
13 test3 \
14 moretests
16 # test4 -- problem with -static
17 # asmtest -- minor differences with gcc
18 # btest -- works on i386 (including win32)
19 # test3 -- win32 does not know how to printf long doubles
21 # bounds-checking is supported only on i386
22 ifneq ($(ARCH),i386)
23 TESTS := $(filter-out btest,$(TESTS))
24 endif
25 ifdef CONFIG_WIN32
26 TESTS := $(filter-out test3,$(TESTS))
27 endif
28 ifeq ($(TARGETOS),Darwin)
29 TESTS := $(filter-out hello test3 btest,$(TESTS))
30 endif
32 ifdef DISABLE_STATIC
33 export LD_LIBRARY_PATH:=$(CURDIR)/..
34 endif
36 ifeq ($(TARGETOS),Darwin)
37 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
38 export MACOSX_DEPLOYMENT_TARGET:=10.2
39 NATIVE_DEFINES+=-D_ANSI_SOURCE
40 endif
42 # run local version of tcc with local libraries and includes
43 TCCFLAGS = -B$(TOP)
44 ifdef CONFIG_WIN32
45 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP)
46 endif
48 TCC = $(TOP)/tcc $(TCCFLAGS)
49 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOP)/tcc.c $(TCCFLAGS)
51 DISAS = objdump -d
53 # libtcc test
54 ifdef LIBTCC1
55 LIBTCC1:=$(TOP)/$(LIBTCC1)
56 endif
58 all test : $(TESTS)
60 hello: ../examples/ex1.c
61 @echo ------------ $@ ------------
62 $(TCC) $< -o $@$(EXESUF) && ./$@$(EXESUF)
63 $(TCC) -run $<
65 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
66 @echo ------------ $@ ------------
67 ./libtcc_test$(EXESUF) lib_path=..
69 libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
70 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
72 moretests:
73 @echo ------------ $@ ------------
74 $(MAKE) -C tests2
76 # test.ref - generate using gcc
77 # copy only tcclib.h so GCC's stddef and stdarg will be used
78 test.ref: tcctest.c
79 cp ../include/tcclib.h .
80 gcc -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
81 ./tcctest.gcc > $@
83 # auto test
84 test1: test.ref
85 @echo ------------ $@ ------------
86 $(TCC) -run tcctest.c > test.out1
87 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
89 # iterated test2 (compile tcc then compile tcctest.c !)
90 test2: test.ref
91 @echo ------------ $@ ------------
92 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
93 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
95 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
96 test3: test.ref
97 @echo ------------ $@ ------------
98 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
99 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
101 # binary output test
102 test4: test.ref
103 @echo ------------ $@ ------------
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 # dynamic output
110 $(TCC) -o tcctest1 tcctest.c
111 ./tcctest1 > test1.out
112 @if diff -u test.ref test1.out ; then echo "Dynamic 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
117 # static output
118 $(TCC) -static -o tcctest2 tcctest.c
119 ./tcctest2 > test2.out
120 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
122 # memory and bound check auto test
123 BOUNDS_OK = 1 4 8 10 14
124 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
126 btest: boundtest.c
127 @echo ------------ $@ ------------
128 @for i in $(BOUNDS_OK); do \
129 echo ; echo --- boundtest $$i ---; \
130 if $(TCC) -b -run boundtest.c $$i ; then \
131 echo succeded as expected; \
132 else\
133 echo Failed positive test $$i ; exit 1 ; \
134 fi ;\
135 done ;\
136 for i in $(BOUNDS_FAIL); do \
137 echo ; echo --- boundtest $$i ---; \
138 if $(TCC) -b -run boundtest.c $$i ; then \
139 echo Failed negative test $$i ; exit 1 ;\
140 else\
141 echo failed as expected; \
142 fi ;\
143 done ;\
144 echo; echo Bound test OK
146 # speed test
147 speedtest: ex2 ex3
148 @echo ------------ $@ ------------
149 time ./ex2 1238 2 3 4 10 13 4
150 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
151 time ./ex3 35
152 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
154 weaktest: test.ref
155 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
156 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
157 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
158 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
159 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
161 ex%: $(top_srcdir)/examples/ex%.c
162 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
164 # tiny assembler testing
165 asmtest.ref: asmtest.S
166 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
167 objdump -D asmtest.ref.o > asmtest.ref
169 asmtest: asmtest.ref
170 @echo ------------ $@ ------------
171 $(TCC) -c asmtest.S
172 objdump -D asmtest.o > asmtest.out
173 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
175 # targets for development
176 %.bin: %.c tcc
177 $(TCC) -g -o $@ $<
178 $(DISAS) $@
180 instr: instr.o
181 objdump -d instr.o
183 instr.o: instr.S
184 $(CC) -o $@ -c $< -O2 -Wall -g
186 cache: tcc_g
187 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
188 vg_annotate tcc.c > /tmp/linpack.cache.log
190 # clean
191 clean:
192 $(MAKE) -C tests2 $@
193 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
194 hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h