make: new lib/Makefile for libtcc1.a on more platforms
[tinycc.git] / tests / Makefile
blobd7e94b9f898482870412ecfcadea21617be3103a
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
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 ../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 : ../tcc
30 ../%:
31 $(MAKE) -C .. $*
33 # libtcc test
34 libtest: libtcc_test$(EXESUF) ../libtcc1.a
35 @echo ------------ $@ ------------
36 ./libtcc_test$(EXESUF) lib_path=..
38 libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)
39 $(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS) $(LINK_LIBTCC)
41 # test.ref - generate using gcc
42 test.ref: tcctest.c
43 $(CC) -o tcctest.gcc $< -w $(CFLAGS) -I../include
44 ./tcctest.gcc > $@
46 # auto test
47 test1: test.ref
48 @echo ------------ $@ ------------
49 $(TCC) -run tcctest.c > test.out1
50 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
52 # iterated test2 (compile tcc then compile tcctest.c !)
53 test2: test.ref
54 @echo ------------ $@ ------------
55 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
56 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
58 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
59 test3: test.ref
60 @echo ------------ $@ ------------
61 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
62 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
64 # binary output test
65 test4: test.ref
66 @echo ------------ $@ ------------
67 # dynamic output
68 $(TCC) -o tcctest1 tcctest.c
69 ./tcctest1 > test1.out
70 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
71 # object + link output
72 $(TCC) -c -o tcctest3.o tcctest.c
73 $(TCC) -o tcctest3 tcctest3.o
74 ./tcctest3 > test3.out
75 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
76 # static output
77 $(TCC) -static -o tcctest2 tcctest.c
78 ./tcctest2 > test2.out
79 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
80 # dynamic output + bound check
81 $(TCC) -b -o tcctest4 tcctest.c
82 ./tcctest4 > test4.out
83 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
85 # memory and bound check auto test
86 BOUNDS_OK = 1 4 8 10 14
87 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
89 btest: boundtest.c ../bcheck.o
90 @echo ------------ $@ ------------
91 @for i in $(BOUNDS_OK); do \
92 echo ; echo --- boundtest $$i ---; \
93 if $(TCC) -b -run boundtest.c $$i ; then \
94 echo succeded as expected; \
95 else\
96 echo Failed positive test $$i ; exit 1 ; \
97 fi ;\
98 done ;\
99 for i in $(BOUNDS_FAIL); do \
100 echo ; echo --- boundtest $$i ---; \
101 if $(TCC) -b -run boundtest.c $$i ; then \
102 echo Failed negative test $$i ; exit 1 ;\
103 else\
104 echo failed as expected; \
105 fi ;\
106 done ;\
107 echo; echo Bound test OK
109 # speed test
110 speedtest: ex2 ex3
111 @echo ------------ $@ ------------
112 time ./ex2 1238 2 3 4 10 13 4
113 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
114 time ./ex3 35
115 time $(TCC) -run ../examples/ex3.c 35
117 ex%: ../examples/ex%.c
118 $(CC) -o $@ $< $(CFLAGS)
120 # tiny assembler testing
121 asmtest.ref: asmtest.S
122 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
123 objdump -D asmtest.ref.o > asmtest.ref
125 asmtest: asmtest.ref
126 @echo ------------ $@ ------------
127 $(TCC) -c asmtest.S
128 objdump -D asmtest.o > asmtest.out
129 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
131 # targets for development
132 %.bin: %.c tcc
133 $(TCC) -g -o $@ $<
134 $(DISAS) $@
136 instr: instr.o
137 objdump -d instr.o
139 instr.o: instr.S
140 $(CC) -o $@ -c $< -O2 -Wall -g
142 cache: tcc_g
143 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
144 vg_annotate tcc.c > /tmp/linpack.cache.log
146 # clean
147 clean:
148 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
149 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h