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 @
$(MAKE
) --no-print-directory
-s
clean
80 @
$(MAKE
) --no-print-directory
-s
-r
$(TESTS
)
82 hello-exe
: ..
/examples
/ex1.c
83 @echo
------------ $@
------------
84 $(TCC
) $< -o hello
$(EXESUF
) && .
/hello
$(EXESUF
) ||
$(DUMPTCC
)
86 hello-run
: ..
/examples
/ex1.c
87 @echo
------------ $@
------------
88 $(TCC
) -run
$< ||
$(DUMPTCC
)
90 libtes
%: libtcc_tes
%$(EXESUF
)
91 @echo
------------ $@
------------
92 .
/libtcc_tes
$*$(EXESUF
) $(TOPSRC
)/tcc.c
$(TCCFLAGS
) $(NATIVE_DEFINES
)
94 libtcc_test
$(EXESUF
): libtcc_test.c
$(LIBTCC
)
95 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
97 libtcc_test_mt
$(EXESUF
): libtcc_test_mt.c
$(LIBTCC
)
98 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
101 @echo
------------ $@
------------
104 # test.ref - generate using cc
106 $(CC
) -o tcctest.gcc
$< $(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
110 test1 test1b
: tcctest.c
test.ref
111 @echo
------------ $@
------------
112 $(TCC
) $(RUN_TCC
) -w
-run
$< > test.out1
113 @diff
-u
test.ref
test.out1
&& echo
"$(AUTO_TEST) OK"
115 # iterated test2 (compile tcc then compile tcctest.c !)
116 test2 test2b
: tcctest.c
test.ref
117 @echo
------------ $@
------------
118 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -w
-run
$< > test.out2
119 @diff
-u
test.ref
test.out2
&& echo
"$(AUTO_TEST)2 OK"
121 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
122 test3 test3b
: tcctest.c
test.ref
123 @echo
------------ $@
------------
124 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -w
-run
$< > test.out3
125 @diff
-u
test.ref
test.out3
&& echo
"$(AUTO_TEST)3 OK"
127 AUTO_TEST
= Auto Test
128 test%b
: TCCFLAGS
+= -b
-bt1
129 test%b
: AUTO_TEST
= Auto Bound-Test
132 test4
: tcctest.c
test.ref
133 @echo
------------ $@
------------
134 # object + link output
135 $(TCC
) -c
-o tcctest3.o
$<
136 $(TCC
) -o tcctest3 tcctest3.o
137 .
/tcctest3
> test3.out
138 @if diff
-u
test.ref test3.out
; then echo
"Object $(AUTO_TEST) OK"; fi
140 $(TCC
) -o tcctest1
$<
141 .
/tcctest1
> test1.out
142 @if diff
-u
test.ref test1.out
; then echo
"Dynamic $(AUTO_TEST) OK"; fi
143 # dynamic output + bound check
144 $(TCC
) -b
-o tcctest4
$<
145 .
/tcctest4
> test4.out
146 @if diff
-u
test.ref test4.out
; then echo
"BCheck $(AUTO_TEST) OK"; fi
148 test4_static
: tcctest.c
test.ref
149 @echo
------------ $@
------------
151 $(TCC
) -static
-o tcctest2
$<
152 .
/tcctest2
> test2.out
153 @if diff
-u
test.ref test2.out
; then echo
"Static $(AUTO_TEST) OK"; fi
155 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
157 @echo
------------ $@
------------
158 $(TCC
) $(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
$(TOPSRC
)/libtcc.c
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
159 $(TCC
) $(NATIVE_DEFINES
) -DONE_SOURCE
=0 $(TOPSRC
)/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
160 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
161 ifeq (,$(filter Darwin WIN32
,$(TARGETOS
)))
162 @echo
------------ $@ with PIC
------------
163 $(CC
) $(CFLAGS
) -fPIC
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
-c
$(TOPSRC
)/libtcc.c
164 $(TCC
) libtcc.o
$(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
168 @
rm tcc2
$(EXESUF
) libtcc2
$(DLLSUF
)
171 @echo
------------ $@
------------
172 $(CC
) $(CFLAGS
) $(NATIVE_DEFINES
) -DMEM_DEBUG
=2 $(TOPSRC
)/tcc.c
$(LIBS
) -o memtest-tcc
$(EXESUF
)
173 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) $(TOPSRC
)/tcc.c
$(LIBS
)
174 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) -run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
) -w
$(TOPSRC
)/tests
/tcctest.c
177 # memory and bound check auto test
178 BOUNDS_OK
= 1 4 8 10 14 16
179 BOUNDS_FAIL
= 2 5 6 7 9 11 12 13 15 17 18
182 @echo
------------ $@
------------
183 @for i in
$(BOUNDS_OK
); do \
184 if
$(TCC
) -b
-run
$< $$i >/dev
/null
2>&1 ; then \
185 echo
"Test $$i succeeded as expected" ; \
187 echo
"Failed positive test $$i" ; exit
1 ; \
190 for i in
$(BOUNDS_FAIL
); do \
191 if
$(TCC
) -b
-bt1
-run
$< $$i >/dev
/null
2>&1 ; then \
192 echo
"Failed negative test $$i" ; exit
1 ;\
194 echo
"Test $$i failed as expected" ; \
201 @echo
------------ $@
------------
202 time .
/ex2
1238 2 3 4 10 13 4
203 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex2.c
1238 2 3 4 10 13 4
205 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex3.c
35
207 weaktest
: tcctest.c
test.ref
208 @echo
------------ $@
------------
209 $(TCC
) -c
$< -o weaktest.tcc.o
210 $(CC
) -c
$< -o weaktest.gcc.o
$(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
211 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
212 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
213 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
215 ex
%: $(TOPSRC
)/examples
/ex
%.c
216 $(CC
) -o
$@
$< $(CFLAGS
)
218 # tiny assembler testing
219 asmtest.ref
: asmtest.S
220 $(CC
) -Wa
,-W
-Wa
,-mx86-used-note
=no
-o asmtest.ref.o
-c asmtest.S
221 objdump
-D asmtest.ref.o
> asmtest.ref
225 TCC
="${TCC}" .
/arm-asm-testsuite.sh
227 asmtest asmtest2
: asmtest.ref
228 @echo
------------ $@
------------
229 $(TCC
) $(MAYBE_RUN_TCC
) -c asmtest.S
230 objdump
-D asmtest.o
> asmtest.out
231 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
234 # test assembler with tcc compiled by itself
235 asmtest2
: MAYBE_RUN_TCC
= $(RUN_TCC
)
237 # Check that code generated by libtcc is binary compatible with
238 # that generated by CC
239 abitest-cc.exe
: abitest.c
$(LIBTCC
)
240 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
) -w
242 abitest-tcc.exe
: abitest.c libtcc.c
243 $(TCC
) -o
$@
$^
$(NATIVE_DEFINES
) $(LIBS
)
245 abitest-
% : abitest-
%.exe
246 @echo
------------ $@
------------
250 ifneq (-$(CONFIG_arm_eabi
)-$(CONFIG_arm_vfp
)-,-yes--
)
254 vla_test
$(EXESUF
): vla_test.c
257 vla_test-run
: vla_test
$(EXESUF
)
258 @echo
------------ $@
------------
261 .PHONY
: abitest vla_test
263 asm-c-connect
$(EXESUF
): asm-c-connect-1.c asm-c-connect-2.c
266 asm-c-connect-
%.o
: asm-c-connect-
%.c
269 asm-c-connect-sep
$(EXESUF
): asm-c-connect-1.o asm-c-connect-2.o
272 asm-c-connect-test
: asm-c-connect
$(EXESUF
) asm-c-connect-sep
$(EXESUF
)
273 @echo
------------ $@
------------
274 .
/asm-c-connect
$(EXESUF
) > asm-c-connect.out1
&& cat asm-c-connect.out1
275 .
/asm-c-connect-sep
$(EXESUF
) > asm-c-connect.out2
&& cat asm-c-connect.out2
276 @diff
-u asm-c-connect.out1 asm-c-connect.out2 ||
(echo
"error"; exit
1)
278 # quick sanity check for cross-compilers
279 cross-test
: tcctest.c examples
/ex3.c
280 @echo
------------ $@
------------
281 $(foreach T
,$(CROSS-TGTS
),$(call CROSS-COMPILE
,$T))
307 $(TCC
) $(DEF-
$1) -DTCC_CROSS_TEST
-run
$(TOPSRC
)/tcc.c \
308 -c
$(if
$(findstring c67
,$1),$(filter %/ex3.c
,$^
),$<) -w
$(TCCFLAGS
)
312 # targets for development
321 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
324 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
325 vg_annotate tcc.c
> /tmp
/linpack.cache.log
329 rm -f
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc *.gcc
330 rm -f
*-cc *-gcc
*-tcc
*.exe hello libtcc_test vla_test tcctest
[1234]
331 rm -f asm-c-connect
$(EXESUF
) asm-c-connect-sep
$(EXESUF
)
332 rm -f ex? tcc_g weaktest.
*.txt
*.def
*.pdb
*.obj libtcc_test_mt
333 @
$(MAKE
) -C tests2
$@