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 ifneq ($(CONFIG_bcheck
),no
)
32 ifeq ($(CONFIG_dll
),no
)
33 TESTS
:= $(filter-out dlltest
, $(TESTS
))
35 ifeq (-$(CONFIG_arm_eabi
)-$(CONFIG_arm_vfp
)-,-yes--
)
36 TESTS
:= $(filter-out test3 test1b
,$(TESTS
))
38 ifeq (,$(filter i386 x86_64
,$(ARCH
)))
39 TESTS
:= $(filter-out asm-c-connect-test
,$(TESTS
))
41 ifeq ($(OS
),Windows_NT
) # for libtcc_test to find libtcc.dll
42 PATH
:= $(CURDIR
)/$(TOP
)$(if
$(findstring ;,$(PATH
)),;,:)$(PATH
)
45 LIBS
+= $(LINK_LIBTCC
)
48 # tcctest refers to the alignment of functions, and with thumb mode
49 # the low bit of code addresses selects the mode, so the "alignment"
50 # of functions via bit masking comes out as 1. Just disable thumb.
51 test.ref
: CFLAGS
+=-marm
53 ifeq ($(ARCH
)$(CONFIG_WIN32
),i386
)
54 # tcctest.c:get_asm_string uses a construct that is checked too strictly
55 # by GCC in 32bit mode when PIC is enabled.
56 test.ref
: CFLAGS
+=-fno-PIC
-fno-PIE
-Wl
,-z
,notext
58 ifeq ($(CC_NAME
),msvc
)
59 test.ref abitest
: CC
= gcc
61 ifeq ($(TARGETOS
),OpenBSD
)
62 dlltest
: CFLAGS
+=-fno-stack-protector
64 ifneq (,$(filter FreeBSD NetBSD
,$(TARGETOS
)))
65 # test3 has dlsym problems
66 TESTS
:= $(filter-out test3
,$(TESTS
))
70 RUN_TCC
= $(NATIVE_DEFINES
) -run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
)
73 DUMPTCC
= (set
-x
; $(TOP
)/tcc
-vv
; otool
-L
$(TOP
)/tcc
; exit
1)
75 DUMPTCC
= (set
-x
; $(TOP
)/tcc
-vv
; ldd
$(TOP
)/tcc
; exit
1)
79 @echo
------------ version
------------
81 @
$(MAKE
) --no-print-directory
-s
clean
82 @
$(MAKE
) --no-print-directory
-s
-r
$(TESTS
)
84 hello-exe
: ..
/examples
/ex1.c
85 @echo
------------ $@
------------
86 $(TCC
) $< -o hello
$(EXESUF
) && .
/hello
$(EXESUF
) ||
$(DUMPTCC
)
88 hello-run
: ..
/examples
/ex1.c
89 @echo
------------ $@
------------
90 $(TCC
) -run
$< ||
$(DUMPTCC
)
92 libtes
%: libtcc_tes
%$(EXESUF
)
93 @echo
------------ $@
------------
94 .
/libtcc_tes
$*$(EXESUF
) $(TOPSRC
)/tcc.c
$(TCCFLAGS
) $(NATIVE_DEFINES
)
96 libtcc_test
$(EXESUF
): libtcc_test.c
$(LIBTCC
)
97 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
99 libtcc_test_mt
$(EXESUF
): libtcc_test_mt.c
$(LIBTCC
)
100 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
103 @echo
------------ $@
------------
106 # test.ref - generate using cc
108 $(CC
) -o tcctest.gcc
$< $(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
112 test1 test1b
: tcctest.c
test.ref
113 @echo
------------ $@
------------
114 $(TCC
) $(RUN_TCC
) -w
-run
$< > test.out1
115 @diff
-u
test.ref
test.out1
&& echo
"$(AUTO_TEST) OK"
117 # iterated test2 (compile tcc then compile tcctest.c !)
118 test2 test2b
: tcctest.c
test.ref
119 @echo
------------ $@
------------
120 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -w
-run
$< > test.out2
121 @diff
-u
test.ref
test.out2
&& echo
"$(AUTO_TEST)2 OK"
123 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
124 test3 test3b
: tcctest.c
test.ref
125 @echo
------------ $@
------------
126 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -w
-run
$< > test.out3
127 @diff
-u
test.ref
test.out3
&& echo
"$(AUTO_TEST)3 OK"
129 AUTO_TEST
= Auto Test
130 test%b
: TCCFLAGS
+= -b
-bt1
131 test%b
: AUTO_TEST
= Auto Bound-Test
134 test4
: tcctest.c
test.ref
135 @echo
------------ $@
------------
136 # object + link output
137 $(TCC
) -c
-o tcctest3.o
$<
138 $(TCC
) -o tcctest3 tcctest3.o
139 .
/tcctest3
> test3.out
140 @if diff
-u
test.ref test3.out
; then echo
"Object $(AUTO_TEST) OK"; fi
142 $(TCC
) -o tcctest1
$<
143 .
/tcctest1
> test1.out
144 @if diff
-u
test.ref test1.out
; then echo
"Dynamic $(AUTO_TEST) OK"; fi
145 # dynamic output + bound check
146 $(TCC
) -b
-o tcctest4
$<
147 .
/tcctest4
> test4.out
148 @if diff
-u
test.ref test4.out
; then echo
"BCheck $(AUTO_TEST) OK"; fi
150 test4_static
: tcctest.c
test.ref
151 @echo
------------ $@
------------
153 $(TCC
) -static
-o tcctest2
$<
154 .
/tcctest2
> test2.out
155 @if diff
-u
test.ref test2.out
; then echo
"Static $(AUTO_TEST) OK"; fi
157 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
159 @echo
------------ $@
------------
160 $(TCC
) $(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
$(TOPSRC
)/libtcc.c
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
161 $(TCC
) $(NATIVE_DEFINES
) -DONE_SOURCE
=0 $(TOPSRC
)/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
162 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
163 ifeq (,$(filter Darwin WIN32
,$(TARGETOS
)))
164 @echo
------------ $@ with PIC
------------
165 $(CC
) $(CFLAGS
) -fPIC
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
-c
$(TOPSRC
)/libtcc.c
166 $(TCC
) libtcc.o
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
167 $(TCC
) $(NATIVE_DEFINES
) -DONE_SOURCE
=0 $(TOPSRC
)/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
168 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
170 @
rm tcc2
$(EXESUF
) libtcc2
$(DLLSUF
)
173 @echo
------------ $@
------------
174 $(CC
) $(CFLAGS
) $(NATIVE_DEFINES
) -DMEM_DEBUG
=2 $(TOPSRC
)/tcc.c
$(LIBS
) -o memtest-tcc
$(EXESUF
)
175 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) $(TOPSRC
)/tcc.c
$(LIBS
)
176 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) -run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
) -w
$(TOPSRC
)/tests
/tcctest.c
179 # memory and bound check auto test
180 BOUNDS_OK
= 1 4 8 10 14 16
181 BOUNDS_FAIL
= 2 5 6 7 9 11 12 13 15 17 18
184 @echo
------------ $@
------------
185 @for i in
$(BOUNDS_OK
); do \
186 if
$(TCC
) -b
-run
$< $$i >/dev
/null
2>&1 ; then \
187 echo
"Test $$i succeeded as expected" ; \
189 echo
"Failed positive test $$i" ; exit
1 ; \
192 for i in
$(BOUNDS_FAIL
); do \
193 if
$(TCC
) -b
-bt1
-run
$< $$i >/dev
/null
2>&1 ; then \
194 echo
"Failed negative test $$i" ; exit
1 ;\
196 echo
"Test $$i failed as expected" ; \
203 @echo
------------ $@
------------
204 time .
/ex2
1238 2 3 4 10 13 4
205 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex2.c
1238 2 3 4 10 13 4
207 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex3.c
35
209 weaktest
: tcctest.c
test.ref
210 @echo
------------ $@
------------
211 $(TCC
) -c
$< -o weaktest.tcc.o
212 $(CC
) -c
$< -o weaktest.gcc.o
$(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
213 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
214 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
215 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
217 ex
%: $(TOPSRC
)/examples
/ex
%.c
218 $(CC
) -o
$@
$< $(CFLAGS
)
220 # tiny assembler testing
221 asmtest.ref
: asmtest.S
222 $(CC
) -Wa
,-W
-Wa
,-mx86-used-note
=no
-o asmtest.ref.o
-c asmtest.S
223 objdump
-D asmtest.ref.o
> asmtest.ref
227 TCC
="${TCC}" .
/arm-asm-testsuite.sh
229 asmtest asmtest2
: asmtest.ref
230 @echo
------------ $@
------------
231 $(TCC
) $(MAYBE_RUN_TCC
) -c asmtest.S
232 objdump
-D asmtest.o
> asmtest.out
233 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
236 # test assembler with tcc compiled by itself
237 asmtest2
: MAYBE_RUN_TCC
= $(RUN_TCC
)
239 # Check that code generated by libtcc is binary compatible with
240 # that generated by CC
241 abitest-cc.exe
: abitest.c
$(LIBTCC
)
242 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
) -w
244 abitest-tcc.exe
: abitest.c libtcc.c
245 $(TCC
) -o
$@
$^
$(NATIVE_DEFINES
) $(LIBS
)
247 abitest-
% : abitest-
%.exe
248 @echo
------------ $@
------------
252 ifneq (-$(CONFIG_arm_eabi
)-$(CONFIG_arm_vfp
)-,-yes--
)
256 vla_test
$(EXESUF
): vla_test.c
259 vla_test-run
: vla_test
$(EXESUF
)
260 @echo
------------ $@
------------
263 .PHONY
: abitest vla_test
265 asm-c-connect
$(EXESUF
): asm-c-connect-1.c asm-c-connect-2.c
268 asm-c-connect-
%.o
: asm-c-connect-
%.c
271 asm-c-connect-sep
$(EXESUF
): asm-c-connect-1.o asm-c-connect-2.o
274 asm-c-connect-test
: asm-c-connect
$(EXESUF
) asm-c-connect-sep
$(EXESUF
)
275 @echo
------------ $@
------------
276 .
/asm-c-connect
$(EXESUF
) > asm-c-connect.out1
&& cat asm-c-connect.out1
277 .
/asm-c-connect-sep
$(EXESUF
) > asm-c-connect.out2
&& cat asm-c-connect.out2
278 @diff
-u asm-c-connect.out1 asm-c-connect.out2 ||
(echo
"error"; exit
1)
280 # quick sanity check for cross-compilers
281 cross-test
: tcctest.c examples
/ex3.c
282 @echo
------------ $@
------------
283 $(foreach T
,$(CROSS-TGTS
),$(call CROSS-COMPILE
,$T))
309 $(TCC
) $(DEF-
$1) -DTCC_CROSS_TEST
-run
$(TOPSRC
)/tcc.c \
310 -c
$(if
$(findstring c67
,$1),$(filter %/ex3.c
,$^
),$<) -w
$(TCCFLAGS
)
314 # targets for development
323 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
326 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
327 vg_annotate tcc.c
> /tmp
/linpack.cache.log
331 rm -f
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc *.gcc
332 rm -f
*-cc *-gcc
*-tcc
*.exe hello libtcc_test vla_test tcctest
[1234]
333 rm -f asm-c-connect
$(EXESUF
) asm-c-connect-sep
$(EXESUF
)
334 rm -f ex? tcc_g weaktest.
*.txt
*.def
*.pdb
*.obj libtcc_test_mt
335 @
$(MAKE
) -C tests2
$@