Makefile 9.17 KB
Newer Older
grischka's avatar
grischka committed
1
2
3
4
#
# Tiny C Compiler Makefile - tests
#

5
TOP = ..
6
include $(TOP)/Makefile
grischka's avatar
grischka committed
7
VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
grischka's avatar
grischka committed
8
CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
9

grischka's avatar
grischka committed
10
# what tests to run
grischka's avatar
grischka committed
11
TESTS = \
12
13
 hello-exe \
 hello-run \
grischka's avatar
grischka committed
14
 libtest \
15
 libtest_mt \
grischka's avatar
grischka committed
16
 test3 \
grischka's avatar
grischka committed
17
 memtest \
grischka's avatar
grischka committed
18
 dlltest \
19
 abitest \
20
 asm-c-connect-test \
21
 vla_test-run \
22
 cross-test \
23
24
 tests2-dir \
 pp-dir
25

grischka's avatar
grischka committed
26
BTESTS = btest test1b
27
# test4_static -- Not all relocation types are implemented yet.
28
# asmtest / asmtest2 -- minor differences with gcc
grischka's avatar
grischka committed
29

30
# bounds-checking is supported on i386 and x86_64 on linux and windows
Michael Matz's avatar
Michael Matz committed
31
ifeq (-$(CONFIG_musl)-, --)
32
33
34
35
36
ifeq ($(ARCH),i386)
 TESTS += $(BTESTS)
endif
ifeq ($(ARCH),x86_64)
 TESTS += $(BTESTS)
37
endif
38
39
40
41
42
43
44
45
46
ifeq ($(ARCH),arm)
 TESTS += $(BTESTS)
endif
ifeq ($(ARCH),arm64)
 TESTS += $(BTESTS)
endif
ifeq ($(ARCH),riscv64)
 TESTS += $(BTESTS)
endif
Michael Matz's avatar
Michael Matz committed
47
endif
grischka's avatar
grischka committed
48
49
ifdef CONFIG_OSX # -run only
 TESTS := hello-run libtest tests2-dir pp-dir
50
endif
51
ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
52
53
 TESTS := $(filter-out vla_test-run,$(TESTS))
endif
54
55
56
ifeq ($(CONFIG_arm_eabi),yes)
 TESTS := $(filter-out test3,$(TESTS))
endif
57
ifeq (,$(filter i386 x86_64,$(ARCH)))
58
 TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS))
grischka's avatar
grischka committed
59
endif
grischka's avatar
grischka committed
60

grischka's avatar
grischka committed
61
ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
grischka's avatar
grischka committed
62
 PATH := $(CURDIR)/$(TOP)$(if $(findstring ;,$(PATH)),;,:)$(PATH)
63
64
endif

65
66
67
68
69
70
ifeq ($(ARCH),arm)
# tcctest refers to the alignment of functions, and with thumb mode
# the low bit of code addresses selects the mode, so the "alignment"
# of functions via bit masking comes out as 1.  Just disable thumb.
test.ref: CFLAGS+=-marm
endif
71
72
73
74
75
ifeq ($(ARCH),i386)
# tcctest.c:get_asm_string uses a construct that is checked too strictly
# by GCC in 32bit mode when PIC is enabled.
test.ref: CFLAGS+=-fno-PIC -fno-PIE
endif
76

77
RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
78
DISAS = objdump -d
grischka's avatar
grischka committed
79
DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
80

Vincent Lefevre's avatar
Vincent Lefevre committed
81
all test :
grischka's avatar
grischka committed
82
83
	@$(MAKE) --no-print-directory -s clean
	@$(MAKE) --no-print-directory -s -r $(TESTS)
grischka's avatar
grischka committed
84

85
86
hello-exe: ../examples/ex1.c
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
87
	$(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
88
89

hello-run: ../examples/ex1.c
grischka's avatar
grischka committed
90
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
91
	$(TCC) -run $< || $(DUMPTCC)
grischka's avatar
grischka committed
92

93
libtes%: libtcc_tes%$(EXESUF)
grischka's avatar
grischka committed
94
	@echo ------------ $@ ------------
95
	./libtcc_tes$*$(EXESUF) $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES)
grischka's avatar
grischka committed
96

grischka's avatar
grischka committed
97
98
99
100
libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

libtcc_test_mt$(EXESUF): libtcc_test_mt.c $(LIBTCC)
101
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
grischka's avatar
grischka committed
102

grischka's avatar
grischka committed
103
%-dir:
grischka's avatar
grischka committed
104
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
105
	$(MAKE) -k -C $*
grischka's avatar
grischka committed
106

107
# test.ref - generate using cc
grischka's avatar
grischka committed
108
test.ref: tcctest.c
109
110
	$(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
	./tcctest.gcc > $@
grischka's avatar
grischka committed
111
112

# auto test
113
test1 test1b: tcctest.c test.ref
grischka's avatar
grischka committed
114
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
115
	$(TCC) $(RUN_TCC) -w -run $< > test.out1
116
	@diff -u test.ref test.out1 && echo "$(AUTO_TEST) OK"
grischka's avatar
grischka committed
117
118

# iterated test2 (compile tcc then compile tcctest.c !)
119
test2 test2b: tcctest.c test.ref
grischka's avatar
grischka committed
120
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
121
	$(TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out2
122
	@diff -u test.ref test.out2 && echo "$(AUTO_TEST)2 OK"
grischka's avatar
grischka committed
123
124

# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
125
test3 test3b: tcctest.c test.ref
grischka's avatar
grischka committed
126
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
127
	$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out3
128
	@diff -u test.ref test.out3 && echo "$(AUTO_TEST)3 OK"
129

130
131
132
AUTO_TEST = Auto Test
test%b : TCCFLAGS += -b -bt1
test%b : AUTO_TEST = Auto Bound-Test
grischka's avatar
grischka committed
133
134

# binary output test
grischka's avatar
grischka committed
135
test4: tcctest.c test.ref
grischka's avatar
grischka committed
136
137
	@echo ------------ $@ ------------
# object + link output
grischka's avatar
grischka committed
138
	$(TCC) -c -o tcctest3.o $<
grischka's avatar
grischka committed
139
140
	$(TCC) -o tcctest3 tcctest3.o
	./tcctest3 > test3.out
141
	@if diff -u test.ref test3.out ; then echo "Object $(AUTO_TEST) OK"; fi
grischka's avatar
grischka committed
142
# dynamic output
grischka's avatar
grischka committed
143
	$(TCC) -o tcctest1 $<
grischka's avatar
grischka committed
144
	./tcctest1 > test1.out
145
	@if diff -u test.ref test1.out ; then echo "Dynamic $(AUTO_TEST) OK"; fi
grischka's avatar
grischka committed
146
# dynamic output + bound check
grischka's avatar
grischka committed
147
	$(TCC) -b -o tcctest4 $<
grischka's avatar
grischka committed
148
	./tcctest4 > test4.out
149
	@if diff -u test.ref test4.out ; then echo "BCheck $(AUTO_TEST) OK"; fi
150
151

test4_static: tcctest.c test.ref
grischka's avatar
grischka committed
152
	@echo ------------ $@ ------------
153
# static output.
grischka's avatar
grischka committed
154
	$(TCC) -static -o tcctest2 $<
grischka's avatar
grischka committed
155
	./tcctest2 > test2.out
156
	@if diff -u test.ref test2.out ; then echo "Static $(AUTO_TEST) OK"; fi
grischka's avatar
grischka committed
157

grischka's avatar
grischka committed
158
159
160
# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
dlltest:
	@echo ------------ $@ ------------
161
162
	$(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
	$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
grischka's avatar
grischka committed
163
	./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
grischka's avatar
grischka committed
164
165
ifndef CONFIG_WIN32
	@echo ------------ $@ with PIC ------------
166
	$(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
grischka's avatar
grischka committed
167
	$(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
168
	$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
grischka's avatar
grischka committed
169
	./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
grischka's avatar
grischka committed
170
171
172
endif
	@rm tcc2$(EXESUF) libtcc2$(DLLSUF)

grischka's avatar
grischka committed
173
174
memtest:
	@echo ------------ $@ ------------
175
176
	$(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
	./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
177
	./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) -w $(TOPSRC)/tests/tcctest.c
grischka's avatar
grischka committed
178
	@echo OK
grischka's avatar
grischka committed
179

grischka's avatar
grischka committed
180
# memory and bound check auto test
181
BOUNDS_OK  = 1 4 8 10 14 16
182
BOUNDS_FAIL= 2 5 6 7 9 11 12 13 15 17
grischka's avatar
grischka committed
183

grischka's avatar
grischka committed
184
btest: boundtest.c
grischka's avatar
grischka committed
185
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
186
	@for i in $(BOUNDS_OK); do \
grischka's avatar
grischka committed
187
188
	   if $(TCC) -b -run $< $$i >/dev/null 2>&1 ; then \
	       echo "Test $$i succeeded as expected" ; \
grischka's avatar
grischka committed
189
	   else\
grischka's avatar
grischka committed
190
	       echo "Failed positive test $$i" ; exit 1 ; \
grischka's avatar
grischka committed
191
192
193
	   fi ;\
	done ;\
	for i in $(BOUNDS_FAIL); do \
grischka's avatar
grischka committed
194
195
	   if $(TCC) -b -bt1 -run $< $$i >/dev/null 2>&1 ; then \
	       echo "Failed negative test $$i" ; exit 1 ;\
grischka's avatar
grischka committed
196
	   else\
grischka's avatar
grischka committed
197
	       echo "Test $$i failed as expected" ; \
grischka's avatar
grischka committed
198
199
	   fi ;\
	done ;\
200
	echo Bound test OK
grischka's avatar
grischka committed
201
202

# speed test
203
speedtest: ex2 ex3
grischka's avatar
grischka committed
204
205
	@echo ------------ $@ ------------
	time ./ex2 1238 2 3 4 10 13 4
grischka's avatar
grischka committed
206
	time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
grischka's avatar
grischka committed
207
	time ./ex3 35
grischka's avatar
grischka committed
208
	time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
grischka's avatar
grischka committed
209

grischka's avatar
grischka committed
210
weaktest: tcctest.c test.ref
grischka's avatar
grischka committed
211
	@echo ------------ $@ ------------
212
	$(TCC) -c $< -o weaktest.tcc.o
213
	$(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
214
	objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
215
216
	objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
	diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
217

grischka's avatar
grischka committed
218
ex%: $(TOPSRC)/examples/ex%.c
219
	$(CC) -o $@ $< $(CFLAGS)
grischka's avatar
grischka committed
220
221
222

# tiny assembler testing
asmtest.ref: asmtest.S
223
	$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
224
	objdump -D asmtest.ref.o > asmtest.ref
grischka's avatar
grischka committed
225

226
asmtest asmtest2: asmtest.ref
grischka's avatar
grischka committed
227
	@echo ------------ $@ ------------
228
	$(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
229
	objdump -D asmtest.o > asmtest.out
grischka's avatar
grischka committed
230
231
	@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi

232
233
234
# test assembler with tcc compiled by itself
asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)

235
236
# Check that code generated by libtcc is binary compatible with
# that generated by CC
grischka's avatar
grischka committed
237
abitest-cc.exe: abitest.c $(LIBTCC)
238
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
239

grischka's avatar
grischka committed
240
abitest-tcc.exe: abitest.c libtcc.c
241
	$(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
242

grischka's avatar
grischka committed
243
abitest-% : abitest-%.exe
244
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
245
246
247
	./$< $(TCCFLAGS)

abitest: abitest-cc
248
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
grischka's avatar
grischka committed
249
abitest: abitest-tcc
250
endif
251

252
vla_test$(EXESUF): vla_test.c
253
254
	$(TCC) -o $@ $^

255
256
257
258
vla_test-run: vla_test$(EXESUF)
	@echo ------------ $@ ------------
	./vla_test$(EXESUF)

259
260
261
asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
	$(TCC) -o $@ $^

262
263
264
265
266
267
268
asm-c-connect-%.o: asm-c-connect-%.c
	$(TCC) -c -o $@ $<

asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
	$(TCC) -o $@ $^

asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
269
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
270
271
	./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
	./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
grischka's avatar
grischka committed
272
273
274
	@diff -u asm-c-connect.out1 asm-c-connect.out2 || (echo "error"; exit 1)

TCC_YY = $(foreach T,$(TCC_X),$(if $(wildcard $(TOP)/$T-tcc$(EXESUF)),$T))
275

276
cross-test :
grischka's avatar
grischka committed
277
278
279
280
	$(if $(strip $(TCC_YY)),\
	    $(MAKE) $(foreach T,$(TCC_YY),cross-$T.test) --no-print-directory,:)

cross-%.test :
281
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
282
283
	$(TOP)/$*-tcc$(EXESUF) -v $(TCCFLAGS-$(if $(findstring win,$*),win,unx))\
	    -c $(TOPSRC)/examples/ex3.c
284

grischka's avatar
grischka committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# 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:
grischka's avatar
grischka committed
302
303
	rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
	rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
304
	rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
305
	rm -f ex? tcc_g weaktest.*.txt *.def libtcc_test_mt
grischka's avatar
grischka committed
306
307
	@$(MAKE) -C tests2 $@
	@$(MAKE) -C pp $@
308