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