Makefile 9.85 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 test2b
27

28
# test4_static -- Not all relocation types are implemented yet.
29
# asmtest / asmtest2 -- minor differences with gcc
grischka's avatar
grischka committed
30

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

grischka's avatar
grischka committed
57
58
ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
 PATH := $(CURDIR)/$(TOP)$(if $(findstring :\,$(PATH)),;,:)$(PATH)
59
60
endif

61
62
63
64
65
66
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
67
68
69
70
71
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
72

73
RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
74
DISAS = objdump -d
grischka's avatar
grischka committed
75
DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
76
Q = # >/dev/null 2>&1
77

Vincent Lefevre's avatar
Vincent Lefevre committed
78
79
80
all test :
	$(MAKE) clean-s
	$(MAKE) $(TESTS)
grischka's avatar
grischka committed
81

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

hello-run: ../examples/ex1.c
grischka's avatar
grischka committed
87
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
88
	$(TCC) -run $< || $(DUMPTCC)
grischka's avatar
grischka committed
89

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

94
libtcc_tes%$(EXESUF): libtcc_tes%.c $(LIBTCC)
95
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
grischka's avatar
grischka committed
96

grischka's avatar
grischka committed
97
%-dir:
grischka's avatar
grischka committed
98
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
99
	$(MAKE) -k -C $*
grischka's avatar
grischka committed
100

101
# test.ref - generate using cc
grischka's avatar
grischka committed
102
test.ref: tcctest.c
103
104
	$(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
	./tcctest.gcc > $@
grischka's avatar
grischka committed
105
106

# auto test
107
test1 test1b: tcctest.c test.ref
grischka's avatar
grischka committed
108
	@echo ------------ $@ ------------
109
110
	$(TCC) -w -run $< > test.out1 $Q
	@diff -u test.ref test.out1 && echo "$(AUTO_TEST) OK"
grischka's avatar
grischka committed
111
112

# iterated test2 (compile tcc then compile tcctest.c !)
113
test2 test2b: tcctest.c test.ref
grischka's avatar
grischka committed
114
	@echo ------------ $@ ------------
115
116
	$(TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out2 $Q
	@diff -u test.ref test.out2 && echo "$(AUTO_TEST)2 OK"
grischka's avatar
grischka committed
117
118

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

124
125
126
AUTO_TEST = Auto Test
test%b : TCCFLAGS += -b -bt1
test%b : AUTO_TEST = Auto Bound-Test
grischka's avatar
grischka committed
127
128

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

test4_static: tcctest.c test.ref
# static output.
grischka's avatar
grischka committed
147
	$(TCC) -static -o tcctest2 $<
grischka's avatar
grischka committed
148
	./tcctest2 > test2.out
149
	@if diff -u test.ref test2.out ; then echo "Static $(AUTO_TEST) OK"; fi
grischka's avatar
grischka committed
150

grischka's avatar
grischka committed
151
152
153
# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
dlltest:
	@echo ------------ $@ ------------
154
155
	$(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
156
	./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
grischka's avatar
grischka committed
157
158
ifndef CONFIG_WIN32
	@echo ------------ $@ with PIC ------------
159
	$(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
grischka's avatar
grischka committed
160
	$(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
161
	$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
grischka's avatar
grischka committed
162
	./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
grischka's avatar
grischka committed
163
164
165
endif
	@rm tcc2$(EXESUF) libtcc2$(DLLSUF)

grischka's avatar
grischka committed
166
167
memtest:
	@echo ------------ $@ ------------
168
169
	$(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)
170
	./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) -w $(TOPSRC)/tests/tcctest.c
grischka's avatar
grischka committed
171

grischka's avatar
grischka committed
172
# memory and bound check auto test
173
BOUNDS_OK  = 1 4 8 10 14 16
174
BOUNDS_FAIL= 2 5 6 7 9 11 12 13 15 17
grischka's avatar
grischka committed
175

grischka's avatar
grischka committed
176
btest: boundtest.c
grischka's avatar
grischka committed
177
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
178
179
	@for i in $(BOUNDS_OK); do \
	   if $(TCC) -b -run $< $$i ; then \
180
	       echo "- Test $$i succeeded as expected" ; \
grischka's avatar
grischka committed
181
	   else\
182
	       echo "- Failed positive test $$i" ; exit 1 ; \
grischka's avatar
grischka committed
183
184
185
	   fi ;\
	done ;\
	for i in $(BOUNDS_FAIL); do \
186
187
	   if $(TCC) -b -bt1 -run $< $$i ; then \
	       echo "- Failed negative test $$i" ; exit 1 ;\
grischka's avatar
grischka committed
188
	   else\
189
	       echo "- Test $$i failed as expected" ; \
grischka's avatar
grischka committed
190
191
	   fi ;\
	done ;\
192
	echo Bound test OK
grischka's avatar
grischka committed
193
194

# speed test
195
speedtest: ex2 ex3
grischka's avatar
grischka committed
196
197
	@echo ------------ $@ ------------
	time ./ex2 1238 2 3 4 10 13 4
grischka's avatar
grischka committed
198
	time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
grischka's avatar
grischka committed
199
	time ./ex3 35
grischka's avatar
grischka committed
200
	time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
grischka's avatar
grischka committed
201

grischka's avatar
grischka committed
202
weaktest: tcctest.c test.ref
203
	$(TCC) -c $< -o weaktest.tcc.o
204
	$(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
205
	objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
206
207
	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"
208

grischka's avatar
grischka committed
209
ex%: $(TOPSRC)/examples/ex%.c
210
	$(CC) -o $@ $< $(CFLAGS)
grischka's avatar
grischka committed
211
212
213

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

217
asmtest asmtest2: asmtest.ref
grischka's avatar
grischka committed
218
	@echo ------------ $@ ------------
219
	$(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
220
	objdump -D asmtest.o > asmtest.out
grischka's avatar
grischka committed
221
222
	@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi

223
224
225
# test assembler with tcc compiled by itself
asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)

226
227
# Check that code generated by libtcc is binary compatible with
# that generated by CC
228
229
abitest-cc$(EXESUF): abitest.c $(LIBTCC)
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
230

231
abitest-tcc$(EXESUF): abitest.c libtcc.c
232
	$(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
233

234
235
ABITESTS := abitest-cc$(EXESUF)
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
236
 ABITESTS += abitest-tcc$(EXESUF)
237
238
239
endif

abitest: $(ABITESTS)
240
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
241
	./abitest-cc$(EXESUF) $(TCCFLAGS)
242
243
244
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
	./abitest-tcc$(EXESUF) $(TCCFLAGS)
endif
245

246
vla_test$(EXESUF): vla_test.c
247
248
	$(TCC) -o $@ $^

249
250
251
252
vla_test-run: vla_test$(EXESUF)
	@echo ------------ $@ ------------
	./vla_test$(EXESUF)

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

256
257
258
259
260
261
262
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)
263
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
264
265
266
	./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
	@diff -u asm-c-connect.out1 asm-c-connect.out2 && echo "ok"
267

268
269
270
cross-test :
	@echo ------------ $@ ------------
	$(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
grischka's avatar
grischka committed
271
	$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
272
	$(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
grischka's avatar
grischka committed
273
	$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
274
	$(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
grischka's avatar
grischka committed
275
276
	$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok"
	$(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
grischka's avatar
grischka committed
277
	$(TOP)/riscv64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
278
279
280
281
282
	$(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
	$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
	$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
	$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"

grischka's avatar
grischka committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# 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
300
301
	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]
302
	rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
303
	rm -f ex? tcc_g weaktest.*.txt *.def libtcc_test_mt
grischka's avatar
grischka committed
304
305
	@$(MAKE) -C tests2 $@
	@$(MAKE) -C pp $@
306
307
308
309

# silent clean, used before running tests
clean-s:
	@$(MAKE) -s --no-print-directory clean