2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 VPATH
= $(TOPSRC
)/tests
$(TOPSRC
) $(TOP
)
8 CFLAGS
:= $(filter-out -g
% -O
%,$(CFLAGS
)) -I
$(TOPSRC
) $(LDFLAGS
)
26 # test4_static -- Not all relocation types are implemented yet.
27 # asmtest / asmtest2 -- minor differences with gcc
29 ifeq ($(CONFIG_backtrace
),no
)
30 TESTS
:= $(filter-out libtest_mt
, $(TESTS
))
31 else ifneq ($(CONFIG_bcheck
),no
)
32 TESTS
+= btest test1b tccb
34 ifeq ($(CONFIG_dll
),no
)
35 TESTS
:= $(filter-out dlltest
, $(TESTS
))
37 ifeq (-$(CONFIG_arm_eabi
)-$(CONFIG_arm_vfp
)-,-yes--
)
38 TESTS
:= $(filter-out test3 test1b
,$(TESTS
))
40 ifeq (,$(filter i386 x86_64
,$(ARCH
)))
41 TESTS
:= $(filter-out asm-c-connect-test
,$(TESTS
))
43 ifeq ($(OS
),Windows_NT
) # for libtcc_test to find libtcc.dll
44 PATH
:= $(CURDIR
)/$(TOP
)$(if
$(findstring ;,$(PATH
)),;,:)$(PATH
)
47 LIBS
+= $(LINK_LIBTCC
)
50 # tcctest refers to the alignment of functions, and with thumb mode
51 # the low bit of code addresses selects the mode, so the "alignment"
52 # of functions via bit masking comes out as 1. Just disable thumb.
53 test.ref
: CFLAGS
+=-marm
55 ifeq ($(ARCH
)$(CONFIG_WIN32
),i386
)
56 # tcctest.c:get_asm_string uses a construct that is checked too strictly
57 # by GCC in 32bit mode when PIC is enabled.
58 test.ref
: CFLAGS
+=-fno-PIC
-fno-PIE
-Wl
,-z
,notext
60 ifeq ($(CC_NAME
),msvc
)
61 test.ref abitest
: CC
= gcc
63 ifeq ($(TARGETOS
),OpenBSD
)
64 dlltest
: CFLAGS
+=-fno-stack-protector
66 ifneq (,$(filter FreeBSD NetBSD
,$(TARGETOS
)))
67 # test3 has dlsym problems
68 TESTS
:= $(filter-out test3
,$(TESTS
))
72 RUN_TCC
= $(NATIVE_DEFINES
) -run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
)
75 DUMPTCC
= (set
-x
; $(TOP
)/tcc
-vv
; otool
-L
$(TOP
)/tcc
; exit
1)
77 DUMPTCC
= (set
-x
; $(TOP
)/tcc
-vv
; ldd
$(TOP
)/tcc
; exit
1)
81 @echo
------------ version
------------
83 @
$(MAKE
) --no-print-directory
-s
clean
84 @
$(MAKE
) --no-print-directory
-s
-r _all
88 hello-exe
: ..
/examples
/ex1.c
89 @echo
------------ $@
------------
90 $(TCC
) $< -o hello
$(EXESUF
) && .
/hello
$(EXESUF
) ||
$(DUMPTCC
)
92 hello-run
: ..
/examples
/ex1.c
93 @echo
------------ $@
------------
94 $(TCC
) -run
$< ||
$(DUMPTCC
)
96 libtes
%: libtcc_tes
%$(EXESUF
)
97 @echo
------------ $@
------------
98 .
/libtcc_tes
$*$(EXESUF
) $(TOPSRC
)/tcc.c
$(TCCFLAGS
) $(NATIVE_DEFINES
)
100 libtcc_test
$(EXESUF
): libtcc_test.c
$(LIBTCC
)
101 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
103 libtcc_test_mt
$(EXESUF
): libtcc_test_mt.c
$(LIBTCC
)
104 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
107 @echo
------------ $@
------------
110 # test.ref - generate using cc
112 $(CC
) -o tcctest.gcc
$< $(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
116 test1 test1b
: tcctest.c
test.ref
117 @echo
------------ $@
------------
118 $(TCC
) $(RUN_TCC
) -w
-run
$< > test.out1
119 @diff
-u
test.ref
test.out1
&& echo
"$(AUTO_TEST) OK"
121 # iterated test2 (compile tcc then compile tcctest.c !)
122 test2 test2b
: tcctest.c
test.ref
123 @echo
------------ $@
------------
124 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -w
-run
$< > test.out2
125 @diff
-u
test.ref
test.out2
&& echo
"$(AUTO_TEST)2 OK"
127 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
128 test3 test3b
: tcctest.c
test.ref
129 @echo
------------ $@
------------
130 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -w
-run
$< > test.out3
131 @diff
-u
test.ref
test.out3
&& echo
"$(AUTO_TEST)3 OK"
133 AUTO_TEST
= Auto Test
134 test%b
: TCCFLAGS
+= -b
-bt1
135 test%b
: AUTO_TEST
= Auto Bound-Test
138 test4
: tcctest.c
test.ref
139 @echo
------------ $@
------------
140 # object + link output
141 $(TCC
) -c
-o tcctest3.o
$<
142 $(TCC
) -o tcctest3 tcctest3.o
143 .
/tcctest3
> test3.out
144 @if diff
-u
test.ref test3.out
; then echo
"Object $(AUTO_TEST) OK"; fi
146 $(TCC
) -o tcctest1
$<
147 .
/tcctest1
> test1.out
148 @if diff
-u
test.ref test1.out
; then echo
"Dynamic $(AUTO_TEST) OK"; fi
149 # dynamic output + bound check
150 $(TCC
) -b
-o tcctest4
$<
151 .
/tcctest4
> test4.out
152 @if diff
-u
test.ref test4.out
; then echo
"BCheck $(AUTO_TEST) OK"; fi
154 test4_static
: tcctest.c
test.ref
155 @echo
------------ $@
------------
157 $(TCC
) -static
-o tcctest2
$<
158 .
/tcctest2
> test2.out
159 @if diff
-u
test.ref test2.out
; then echo
"Static $(AUTO_TEST) OK"; fi
161 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
163 @echo
------------ $@
------------
164 $(TCC
) $(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
$(TOPSRC
)/libtcc.c
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
165 $(TCC
) $(NATIVE_DEFINES
) -DONE_SOURCE
=0 $(TOPSRC
)/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
166 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
167 ifeq (,$(filter Darwin WIN32
,$(TARGETOS
)))
168 @echo
------------ $@ with PIC
------------
169 $(CC
) $(CFLAGS
) -fPIC
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
-c
$(TOPSRC
)/libtcc.c
170 $(TCC
) libtcc.o
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
171 $(TCC
) $(NATIVE_DEFINES
) -DONE_SOURCE
=0 $(TOPSRC
)/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
172 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
174 @
rm tcc2
$(EXESUF
) libtcc2
$(DLLSUF
)
177 @echo
------------ $@
------------
178 $(CC
) $(CFLAGS
) $(NATIVE_DEFINES
) -DMEM_DEBUG
=2 $(TOPSRC
)/tcc.c
$(LIBS
) -o memtest-tcc
$(EXESUF
)
179 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) $(TOPSRC
)/tcc.c
$(LIBS
)
180 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) -run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
) -w
$(TOPSRC
)/tests
/tcctest.c
183 # memory and bound check auto test
184 BOUNDS_OK
= 1 4 8 10 14 16
185 BOUNDS_FAIL
= 2 5 6 7 9 11 12 13 15 17 18
188 @echo
------------ $@
------------
189 @for i in
$(BOUNDS_OK
); do \
190 if
$(TCC
) -b
-run
$< $$i >/dev
/null
2>&1 ; then \
191 echo
"Test $$i succeeded as expected" ; \
193 echo
"Failed positive test $$i" ; exit
1 ; \
196 for i in
$(BOUNDS_FAIL
); do \
197 if
$(TCC
) -b
-bt1
-run
$< $$i >/dev
/null
2>&1 ; then \
198 echo
"Failed negative test $$i" ; exit
1 ;\
200 echo
"Test $$i failed as expected" ; \
206 @echo
------------ $@
------------
207 $(TCC
) -b
$(TOPSRC
)/tcc.c
$(TCCFLAGS
) $(NATIVE_DEFINES
) -o tccb1.exe
208 mv tccb1.exe tccb2.exe
209 .
/tccb2.exe
-b
$(TOPSRC
)/tcc.c
$(TCCFLAGS
) $(NATIVE_DEFINES
) -o tccb1.exe
210 cmp
-s tccb1.exe tccb2.exe
&& echo
"Exe Bound-Test OK"
215 @echo
------------ $@
------------
216 time .
/ex2
1238 2 3 4 10 13 4
217 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex2.c
1238 2 3 4 10 13 4
219 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex3.c
35
221 weaktest
: tcctest.c
test.ref
222 @echo
------------ $@
------------
223 $(TCC
) -c
$< -o weaktest.tcc.o
224 $(CC
) -c
$< -o weaktest.gcc.o
$(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
225 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
226 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
227 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
229 ex
%: $(TOPSRC
)/examples
/ex
%.c
230 $(CC
) -o
$@
$< $(CFLAGS
)
232 # tiny assembler testing
233 asmtest.ref
: asmtest.S
234 $(CC
) -Wa
,-W
-Wa
,-mx86-used-note
=no
-o asmtest.ref.o
-c asmtest.S
235 objdump
-D asmtest.ref.o
> asmtest.ref
239 TCC
="${TCC}" .
/arm-asm-testsuite.sh
241 asmtest asmtest2
: asmtest.ref
242 @echo
------------ $@
------------
243 $(TCC
) $(MAYBE_RUN_TCC
) -c asmtest.S
244 objdump
-D asmtest.o
> asmtest.out
245 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
248 # test assembler with tcc compiled by itself
249 asmtest2
: MAYBE_RUN_TCC
= $(RUN_TCC
)
251 # Check that code generated by libtcc is binary compatible with
252 # that generated by CC
253 abitest-cc.exe
: abitest.c
$(LIBTCC
)
254 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
) -w
256 abitest-tcc.exe
: abitest.c libtcc.c
257 $(TCC
) -o
$@
$^
$(NATIVE_DEFINES
) $(LIBS
)
259 abitest-
% : abitest-
%.exe
260 @echo
------------ $@
------------
264 ifneq (-$(CONFIG_arm_eabi
)-$(CONFIG_arm_vfp
)-,-yes--
)
268 vla_test
$(EXESUF
): vla_test.c
271 vla_test-run
: vla_test
$(EXESUF
)
272 @echo
------------ $@
------------
275 .PHONY
: abitest vla_test tccb
277 asm-c-connect
$(EXESUF
): asm-c-connect-1.c asm-c-connect-2.c
280 asm-c-connect-
%.o
: asm-c-connect-
%.c
283 asm-c-connect-sep
$(EXESUF
): asm-c-connect-1.o asm-c-connect-2.o
286 asm-c-connect-test
: asm-c-connect
$(EXESUF
) asm-c-connect-sep
$(EXESUF
)
287 @echo
------------ $@
------------
288 .
/asm-c-connect
$(EXESUF
) > asm-c-connect.out1
&& cat asm-c-connect.out1
289 .
/asm-c-connect-sep
$(EXESUF
) > asm-c-connect.out2
&& cat asm-c-connect.out2
290 @diff
-u asm-c-connect.out1 asm-c-connect.out2 ||
(echo
"error"; exit
1)
292 # quick sanity check for cross-compilers
293 cross-test
: tcctest.c examples
/ex3.c
294 @echo
------------ $@
------------
295 $(foreach T
,$(CROSS-TGTS
),$(call CROSS-COMPILE
,$T))
321 $(TCC
) $(DEF-
$1) -DTCC_CROSS_TEST
-run
$(TOPSRC
)/tcc.c \
322 -c
$(if
$(findstring c67
,$1),$(filter %/ex3.c
,$^
),$<) -w
$(TCCFLAGS
)
326 # targets for development
335 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
338 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
339 vg_annotate tcc.c
> /tmp
/linpack.cache.log
343 rm -f
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc *.gcc
344 rm -f
*-cc *-gcc
*-tcc
*.exe hello libtcc_test vla_test tcctest
[1234]
345 rm -f asm-c-connect asm-c-connect-sep
346 rm -f ex? tcc_g weaktest.
*.txt
*.def
*.pdb
*.obj libtcc_test_mt
347 @
$(MAKE
) -C tests2
$@