summaryrefslogtreecommitdiff
path: root/tests/Makefile
blob: 61df559fcfb71d509379b65aeb9c9757d5aa37b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#
# Tiny C Compiler Makefile - tests
#

# what tests to run
TESTS = libtest test3

# these should work too
# TESTS += test1 test2 speed

# these don't work as they should
# TESTS += test4 btest asmtest


TOP = ..
include $(TOP)/Makefile

# run local version of tcc with local libraries and includes
TCC = ../tcc -B..
RUN_TCC = $(NATIVE_TARGET) -run ../tcc.c -B..
DISAS=objdump -d

all test : $(TESTS)

# make sure that tcc exists
$(TESTS) : ../tcc
../tcc ../libtcc.a :
	$(MAKE) -C ..

# libtcc test
libtest: libtcc_test$(EXESUF)
	@echo ------------ $@ ------------
	./libtcc_test lib_path=..

libtcc_test$(EXESUF): libtcc_test.c ../libtcc.a
	$(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS)

# test.ref - generate using gcc
test.ref: tcctest.c
	$(CC) -o tcctest.gcc $< -w -I.. -I../include $(CFLAGS)
	./tcctest.gcc > $@

# auto test
test1: test.ref
	@echo ------------ $@ ------------
	$(TCC) -run tcctest.c > test.out1
	@if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi

# iterated test2 (compile tcc then compile tcctest.c !)
test2: test.ref
	@echo ------------ $@ ------------
	$(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
	@if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi

# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
test3: test.ref
	@echo ------------ $@ ------------
	$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
	@if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi

# binary output test
test4: test.ref
	@echo ------------ $@ ------------
# dynamic output
	$(TCC) -o tcctest1 tcctest.c
	./tcctest1 > test1.out
	@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
# object + link output
	$(TCC) -c -o tcctest3.o tcctest.c
	$(TCC) -o tcctest3 tcctest3.o
	./tcctest3 > test3.out
	@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
# static output
	$(TCC) -static -o tcctest2 tcctest.c
	./tcctest2 > test2.out
	@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
# dynamic output + bound check
	$(TCC) -b -o tcctest4 tcctest.c
	./tcctest4 > test4.out
	@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi

# memory and bound check auto test
BOUNDS_OK  = 1 4 8 10
BOUNDS_FAIL= 2 5 7 9 11 12 13

btest: boundtest.c
	@echo ------------ $@ ------------
	@for i in $(BOUNDS_OK); do \
	   if $(TCC) -b -run boundtest.c $$i ; then \
	       /bin/true ; \
	   else\
	       echo Failed positive test $$i ; exit 1 ; \
	   fi ;\
	done ;\
	for i in $(BOUNDS_FAIL); do \
	   if $(TCC) -b -run boundtest.c $$i ; then \
	       echo Failed negative test $$i ; exit 1 ;\
	   else\
	       /bin/true ; \
	   fi ;\
	done ;\
	echo Bound test OK

# speed test
speed: ex2 ex3
	@echo ------------ $@ ------------
	time ./ex2 1238 2 3 4 10 13 4
	time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
	time ./ex3 35
	time $(TCC) -run ../examples/ex3.c 35

ex%: ../examples/ex%.c
	$(CC) -o $@ $< $(CFLAGS)

# tiny assembler testing
asmtest.ref: asmtest.S
	$(CC) -o asmtest.ref.o -c asmtest.S
	objdump -D asmtest.ref.o > $@

asmtest: asmtest.ref
	@echo ------------ $@ ------------
	$(TCC) -c asmtest.S
	objdump -D asmtest.o > $@
	@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi

# targets for development
%.bin: %.c tcc
	$(TCC) -g -o $@ $<
	$(DISAS) $@

instr: instr.o
	objdump -d instr.o

instr.o: instr.S
	$(CC) -o $@ -c $< -O2 -Wall -g

cache: tcc_g
	cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
	vg_annotate tcc.c > /tmp/linpack.cache.log

# clean
clean:
	rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
	   tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g