Use CString to concat linker options
[tinycc.git] / tests / Makefile
blob4ce9dfaabf0aa41919bf1d20a8639d48c9ee7b63
2 # Tiny C Compiler Makefile - tests
5 # what tests to run
6 TESTS = libtest test1 test3
8 # these should work too
9 TESTS += test2 speedtest btest weaktest
11 # these don't work as they should
12 # TESTS += test4 asmtest
14 TOP = ..
15 include $(TOP)/Makefile
17 ifdef DISABLE_STATIC
18 export LD_LIBRARY_PATH:=$(CURDIR)/..
19 endif
21 ifeq ($(TARGETOS),Darwin)
22 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
23 export MACOSX_DEPLOYMENT_TARGET:=10.2
24 NATIVE_DEFINES+=-D_ANSI_SOURCE
25 endif
27 # run local version of tcc with local libraries and includes
28 TCC = ../tcc -B..
29 RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..
30 DISAS=objdump -d
32 all test : $(TESTS)
34 # make sure that tcc exists
35 test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc
36 ../%:
37 $(MAKE) -C .. $*
39 # libtcc test
40 ifdef LIBTCC1
41 LIBTCC1:=$(TOP)/$(LIBTCC1)
42 endif
44 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
45 @echo ------------ $@ ------------
46 ./libtcc_test$(EXESUF) lib_path=..
48 libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)
49 $(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS) $(LINK_LIBTCC)
51 # test.ref - generate using gcc
52 # copy only tcclib.h so GCC's stddef and stdarg will be used
53 test.ref: tcctest.c
54 cp ../include/tcclib.h .
55 $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS) -std=gnu99
56 ./tcctest.gcc > $@
58 # auto test
59 test1: test.ref
60 @echo ------------ $@ ------------
61 $(TCC) -run tcctest.c > test.out1
62 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
64 # iterated test2 (compile tcc then compile tcctest.c !)
65 test2: test.ref
66 @echo ------------ $@ ------------
67 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
68 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
70 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
71 test3: test.ref
72 @echo ------------ $@ ------------
73 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
74 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
76 # binary output test
77 test4: test.ref
78 @echo ------------ $@ ------------
79 # dynamic output
80 $(TCC) -o tcctest1 tcctest.c
81 ./tcctest1 > test1.out
82 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
83 # object + link output
84 $(TCC) -c -o tcctest3.o tcctest.c
85 $(TCC) -o tcctest3 tcctest3.o
86 ./tcctest3 > test3.out
87 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
88 # static output
89 $(TCC) -static -o tcctest2 tcctest.c
90 ./tcctest2 > test2.out
91 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
92 # dynamic output + bound check
93 $(TCC) -b -o tcctest4 tcctest.c
94 ./tcctest4 > test4.out
95 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
97 # memory and bound check auto test
98 BOUNDS_OK = 1 4 8 10 14
99 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
101 btest: boundtest.c ../bcheck.o
102 @echo ------------ $@ ------------
103 @for i in $(BOUNDS_OK); do \
104 echo ; echo --- boundtest $$i ---; \
105 if $(TCC) -b -run boundtest.c $$i ; then \
106 echo succeded as expected; \
107 else\
108 echo Failed positive test $$i ; exit 1 ; \
109 fi ;\
110 done ;\
111 for i in $(BOUNDS_FAIL); do \
112 echo ; echo --- boundtest $$i ---; \
113 if $(TCC) -b -run boundtest.c $$i ; then \
114 echo Failed negative test $$i ; exit 1 ;\
115 else\
116 echo failed as expected; \
117 fi ;\
118 done ;\
119 echo; echo Bound test OK
121 # speed test
122 speedtest: ex2 ex3
123 @echo ------------ $@ ------------
124 time ./ex2 1238 2 3 4 10 13 4
125 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
126 time ./ex3 35
127 time $(TCC) -run ../examples/ex3.c 35
129 weaktest: test.ref
130 $(TCC) -c tcctest.c -o weaktest.tcc.o
131 $(CC) -c tcctest.c -o weaktest.gcc.o -I. -w $(CFLAGS)
132 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
133 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
134 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
136 ex%: ../examples/ex%.c
137 $(CC) -o $@ $< $(CFLAGS)
139 # tiny assembler testing
140 asmtest.ref: asmtest.S
141 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
142 objdump -D asmtest.ref.o > asmtest.ref
144 asmtest: asmtest.ref
145 @echo ------------ $@ ------------
146 $(TCC) -c asmtest.S
147 objdump -D asmtest.o > asmtest.out
148 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
150 # targets for development
151 %.bin: %.c tcc
152 $(TCC) -g -o $@ $<
153 $(DISAS) $@
155 instr: instr.o
156 objdump -d instr.o
158 instr.o: instr.S
159 $(CC) -o $@ -c $< -O2 -Wall -g
161 cache: tcc_g
162 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
163 vg_annotate tcc.c > /tmp/linpack.cache.log
165 # clean
166 clean:
167 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
168 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h