2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 VPATH
= $(TOPSRC
)/tests
$(TOPSRC
) $(TOP
)
8 CFLAGS
:= $(filter-out -W
% -g
% -O
%,$(CFLAGS
)) -I
$(TOPSRC
) $(LDFLAGS
)
27 # test4_static -- Not all relocation types are implemented yet.
28 # asmtest / asmtest2 -- minor differences with gcc
30 # bounds-checking is supported on i386 and x86_64 on linux and windows
31 ifeq (-$(CONFIG_musl
)-, --)
44 ifeq ($(ARCH
),riscv64
)
48 ifdef CONFIG_OSX
# -run only
49 TESTS
:= hello-run libtest tests2-dir pp-dir
51 ifeq (,$(filter arm64 i386 x86_64
,$(ARCH
)))
52 TESTS
:= $(filter-out vla_test-run
,$(TESTS
))
54 ifeq ($(CONFIG_arm_eabi
),yes
)
55 TESTS
:= $(filter-out test3
,$(TESTS
))
57 ifeq (,$(filter i386 x86_64
,$(ARCH
)))
58 TESTS
:= $(filter-out dlltest asm-c-connect-test
,$(TESTS
))
61 ifeq ($(OS
),Windows_NT
) # for libtcc_test to find libtcc.dll
62 PATH
:= $(CURDIR
)/$(TOP
)$(if
$(findstring ;,$(PATH
)),;,:)$(PATH
)
66 # tcctest refers to the alignment of functions, and with thumb mode
67 # the low bit of code addresses selects the mode, so the "alignment"
68 # of functions via bit masking comes out as 1. Just disable thumb.
69 test.ref
: CFLAGS
+=-marm
72 # tcctest.c:get_asm_string uses a construct that is checked too strictly
73 # by GCC in 32bit mode when PIC is enabled.
74 test.ref
: CFLAGS
+=-fno-PIC
-fno-PIE
77 RUN_TCC
= $(NATIVE_DEFINES
) -run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
)
79 DUMPTCC
= (set
-x
; $(TOP
)/tcc
-vv
; ldd
$(TOP
)/tcc
; exit
1)
82 @
$(MAKE
) --no-print-directory
-s
clean
83 @
$(MAKE
) --no-print-directory
-s
-r
$(TESTS
)
85 hello-exe
: ..
/examples
/ex1.c
86 @echo
------------ $@
------------
87 $(TCC
) $< -o hello
$(EXESUF
) && .
/hello
$(EXESUF
) ||
$(DUMPTCC
)
89 hello-run
: ..
/examples
/ex1.c
90 @echo
------------ $@
------------
91 $(TCC
) -run
$< ||
$(DUMPTCC
)
93 libtes
%: libtcc_tes
%$(EXESUF
)
94 @echo
------------ $@
------------
95 .
/libtcc_tes
$*$(EXESUF
) $(TOPSRC
)/tcc.c
$(TCCFLAGS
) $(NATIVE_DEFINES
)
97 libtcc_test
$(EXESUF
): libtcc_test.c
$(LIBTCC
)
98 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
100 libtcc_test_mt
$(EXESUF
): libtcc_test_mt.c
$(LIBTCC
)
101 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
104 @echo
------------ $@
------------
107 # test.ref - generate using cc
109 $(CC
) -o tcctest.gcc
$< $(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
113 test1 test1b
: tcctest.c
test.ref
114 @echo
------------ $@
------------
115 $(TCC
) $(RUN_TCC
) -w
-run
$< > test.out1
116 @diff
-u
test.ref
test.out1
&& echo
"$(AUTO_TEST) OK"
118 # iterated test2 (compile tcc then compile tcctest.c !)
119 test2 test2b
: tcctest.c
test.ref
120 @echo
------------ $@
------------
121 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -w
-run
$< > test.out2
122 @diff
-u
test.ref
test.out2
&& echo
"$(AUTO_TEST)2 OK"
124 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
125 test3 test3b
: tcctest.c
test.ref
126 @echo
------------ $@
------------
127 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -w
-run
$< > test.out3
128 @diff
-u
test.ref
test.out3
&& echo
"$(AUTO_TEST)3 OK"
130 AUTO_TEST
= Auto Test
131 test%b
: TCCFLAGS
+= -b
-bt1
132 test%b
: AUTO_TEST
= Auto Bound-Test
135 test4
: tcctest.c
test.ref
136 @echo
------------ $@
------------
137 # object + link output
138 $(TCC
) -c
-o tcctest3.o
$<
139 $(TCC
) -o tcctest3 tcctest3.o
140 .
/tcctest3
> test3.out
141 @if diff
-u
test.ref test3.out
; then echo
"Object $(AUTO_TEST) OK"; fi
143 $(TCC
) -o tcctest1
$<
144 .
/tcctest1
> test1.out
145 @if diff
-u
test.ref test1.out
; then echo
"Dynamic $(AUTO_TEST) OK"; fi
146 # dynamic output + bound check
147 $(TCC
) -b
-o tcctest4
$<
148 .
/tcctest4
> test4.out
149 @if diff
-u
test.ref test4.out
; then echo
"BCheck $(AUTO_TEST) OK"; fi
151 test4_static
: tcctest.c
test.ref
152 @echo
------------ $@
------------
154 $(TCC
) -static
-o tcctest2
$<
155 .
/tcctest2
> test2.out
156 @if diff
-u
test.ref test2.out
; then echo
"Static $(AUTO_TEST) OK"; fi
158 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
160 @echo
------------ $@
------------
161 $(TCC
) $(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
$(TOPSRC
)/libtcc.c
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
162 $(TCC
) $(NATIVE_DEFINES
) -DONE_SOURCE
=0 $(TOPSRC
)/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
163 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
165 @echo
------------ $@ with PIC
------------
166 $(CC
) $(CFLAGS
) -fPIC
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
-c
$(TOPSRC
)/libtcc.c
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
)
169 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
171 @
rm tcc2
$(EXESUF
) libtcc2
$(DLLSUF
)
174 @echo
------------ $@
------------
175 $(CC
) $(CFLAGS
) $(NATIVE_DEFINES
) -DMEM_DEBUG
=2 $(TOPSRC
)/tcc.c
$(LIBS
) -o memtest-tcc
$(EXESUF
)
176 .
/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
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 18
185 @echo
------------ $@
------------
186 @for i in
$(BOUNDS_OK
); do \
187 if
$(TCC
) -b
-run
$< $$i >/dev
/null
2>&1 ; then \
188 echo
"Test $$i succeeded as expected" ; \
190 echo
"Failed positive test $$i" ; exit
1 ; \
193 for i in
$(BOUNDS_FAIL
); do \
194 if
$(TCC
) -b
-bt1
-run
$< $$i >/dev
/null
2>&1 ; then \
195 echo
"Failed negative test $$i" ; exit
1 ;\
197 echo
"Test $$i failed as expected" ; \
204 @echo
------------ $@
------------
205 time .
/ex2
1238 2 3 4 10 13 4
206 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex2.c
1238 2 3 4 10 13 4
208 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex3.c
35
210 weaktest
: tcctest.c
test.ref
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 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
216 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
218 ex
%: $(TOPSRC
)/examples
/ex
%.c
219 $(CC
) -o
$@
$< $(CFLAGS
)
221 # tiny assembler testing
222 asmtest.ref
: asmtest.S
223 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
224 objdump
-D asmtest.ref.o
> asmtest.ref
226 asmtest asmtest2
: asmtest.ref
227 @echo
------------ $@
------------
228 $(TCC
) $(MAYBE_RUN_TCC
) -c asmtest.S
229 objdump
-D asmtest.o
> asmtest.out
230 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
232 # test assembler with tcc compiled by itself
233 asmtest2
: MAYBE_RUN_TCC
= $(RUN_TCC
)
235 # Check that code generated by libtcc is binary compatible with
236 # that generated by CC
237 abitest-cc.exe
: abitest.c
$(LIBTCC
)
238 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
) -w
240 abitest-tcc.exe
: abitest.c libtcc.c
241 $(TCC
) -o
$@
$^
$(NATIVE_DEFINES
) $(LIBS
)
243 abitest-
% : abitest-
%.exe
244 @echo
------------ $@
------------
248 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
252 vla_test
$(EXESUF
): vla_test.c
255 vla_test-run
: vla_test
$(EXESUF
)
256 @echo
------------ $@
------------
259 asm-c-connect
$(EXESUF
): asm-c-connect-1.c asm-c-connect-2.c
262 asm-c-connect-
%.o
: asm-c-connect-
%.c
265 asm-c-connect-sep
$(EXESUF
): asm-c-connect-1.o asm-c-connect-2.o
268 asm-c-connect-test
: asm-c-connect
$(EXESUF
) asm-c-connect-sep
$(EXESUF
)
269 @echo
------------ $@
------------
270 .
/asm-c-connect
$(EXESUF
) > asm-c-connect.out1
&& cat asm-c-connect.out1
271 .
/asm-c-connect-sep
$(EXESUF
) > asm-c-connect.out2
&& cat asm-c-connect.out2
272 @diff
-u asm-c-connect.out1 asm-c-connect.out2 ||
(echo
"error"; exit
1)
274 TCC_YY
= $(foreach T
,$(TCC_X
),$(if
$(wildcard $(TOP
)/$T-tcc
$(EXESUF
)),$T))
277 $(if
$(strip $(TCC_YY
)),\
278 $(MAKE
) $(foreach T
,$(TCC_YY
),cross-
$T.
test) --no-print-directory
,:)
281 @echo
------------ $@
------------
282 $(TOP
)/$*-tcc
$(EXESUF
) -v
$(TCCFLAGS-
$(if
$(findstring win
,$*),win
,unx
))\
283 -c
$(TOPSRC
)/examples
/ex3.c
285 # targets for development
294 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
297 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
298 vg_annotate tcc.c
> /tmp
/linpack.cache.log
302 rm -f
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc *.gcc
303 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
306 @
$(MAKE
) -C tests2
$@