fix asmtest (somehow), update Makefiles
[tinycc/k1w1.git] / tests / Makefile
blobf91e4fd9af5927eac1d25684e7a83ec143b6e2a5
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 # run local version of tcc with local libraries and includes
18 TCC = ../tcc -B..
19 RUN_TCC = $(NATIVE_TARGET) -run ../tcc.c -B..
20 DISAS=objdump -d
22 all test : $(TESTS)
24 # make sure that tcc exists
25 $(TESTS) : ../tcc
27 ../tcc ../libtcc.a :
28 $(MAKE) -C ..
30 # libtcc test
31 libtest: libtcc_test$(EXESUF)
32 @echo ------------ $@ ------------
33 ./libtcc_test lib_path=..
35 libtcc_test$(EXESUF): libtcc_test.c ../libtcc.a
36 $(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS)
38 # test.ref - generate using gcc
39 test.ref: tcctest.c
40 cp -u ../include/tcclib.h .
41 $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS)
42 ./tcctest.gcc > $@
44 # auto test
45 test1: test.ref
46 @echo ------------ $@ ------------
47 $(TCC) -run tcctest.c > test.out1
48 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
50 # iterated test2 (compile tcc then compile tcctest.c !)
51 test2: test.ref
52 @echo ------------ $@ ------------
53 $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
54 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
56 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
57 test3: test.ref
58 @echo ------------ $@ ------------
59 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
60 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
62 # binary output test
63 test4: test.ref
64 @echo ------------ $@ ------------
65 # dynamic output
66 $(TCC) -o tcctest1 tcctest.c
67 ./tcctest1 > test1.out
68 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
69 # object + link output
70 $(TCC) -c -o tcctest3.o tcctest.c
71 $(TCC) -o tcctest3 tcctest3.o
72 ./tcctest3 > test3.out
73 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
74 # static output
75 $(TCC) -static -o tcctest2 tcctest.c
76 ./tcctest2 > test2.out
77 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
78 # dynamic output + bound check
79 $(TCC) -b -o tcctest4 tcctest.c
80 ./tcctest4 > test4.out
81 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
83 # memory and bound check auto test
84 BOUNDS_OK = 1 4 8 10
85 BOUNDS_FAIL= 2 5 7 9 11 12 13
87 btest: boundtest.c
88 @echo ------------ $@ ------------
89 @for i in $(BOUNDS_OK); do \
90 echo ; echo --- boundtest $$i ---; \
91 if $(TCC) -b -run boundtest.c $$i ; then \
92 echo succeded as expected; \
93 else\
94 echo Failed positive test $$i ; exit 1 ; \
95 fi ;\
96 done ;\
97 for i in $(BOUNDS_FAIL); do \
98 echo ; echo --- boundtest $$i ---; \
99 if $(TCC) -b -run boundtest.c $$i ; then \
100 echo Failed negative test $$i ; exit 1 ;\
101 else\
102 echo failed as expected; \
103 fi ;\
104 done ;\
105 echo; echo Bound test OK
107 # speed test
108 speedtest: ex2 ex3
109 @echo ------------ $@ ------------
110 time ./ex2 1238 2 3 4 10 13 4
111 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
112 time ./ex3 35
113 time $(TCC) -run ../examples/ex3.c 35
115 ex%: ../examples/ex%.c
116 $(CC) -o $@ $< $(CFLAGS)
118 # tiny assembler testing
119 asmtest.ref: asmtest.S
120 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
121 objdump -D asmtest.ref.o > asmtest.ref
123 asmtest: asmtest.ref
124 @echo ------------ $@ ------------
125 $(TCC) -c asmtest.S
126 objdump -D asmtest.o > asmtest.out
127 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
129 # targets for development
130 %.bin: %.c tcc
131 $(TCC) -g -o $@ $<
132 $(DISAS) $@
134 instr: instr.o
135 objdump -d instr.o
137 instr.o: instr.S
138 $(CC) -o $@ -c $< -O2 -Wall -g
140 cache: tcc_g
141 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
142 vg_annotate tcc.c > /tmp/linpack.cache.log
144 # clean
145 clean:
146 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
147 tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h