2 # Tiny C Compiler Makefile - tests
8 # these should work too
9 # TESTS += test1 test2 speedtest btest weaktest
11 # these don't work as they should
12 # TESTS += test4 asmtest
15 include $(TOP
)/Makefile
18 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
21 # run local version of tcc with local libraries and includes
23 RUN_TCC
= $(NATIVE_DEFINES
) -run ..
/tcc.c
-B..
28 # make sure that tcc exists
29 test1 test2 test3 test4 btest speedtest asmtest weaktest
: ..
/tcc
35 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
38 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
39 @echo
------------ $@
------------
40 .
/libtcc_test
$(EXESUF
) lib_path
=..
42 libtcc_test
$(EXESUF
): libtcc_test.c ..
/$(LIBTCC
)
43 $(CC
) -o
$@
$^
-I..
$(CFLAGS
) $(LIBS
) $(LINK_LIBTCC
)
45 # test.ref - generate using gcc
46 # copy only tcclib.h so GCC's stddef and stdarg will be used
48 cp
-u ..
/include/tcclib.h .
49 $(CC
) -o tcctest.gcc
$< -I.
-w
$(CFLAGS
) -std
=gnu99
54 @echo
------------ $@
------------
55 $(TCC
) -run tcctest.c
> test.out1
56 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
58 # iterated test2 (compile tcc then compile tcctest.c !)
60 @echo
------------ $@
------------
61 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out2
62 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
64 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
66 @echo
------------ $@
------------
67 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out3
68 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
72 @echo
------------ $@
------------
74 $(TCC
) -o tcctest1 tcctest.c
75 .
/tcctest1
> test1.out
76 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
77 # object + link output
78 $(TCC
) -c
-o tcctest3.o tcctest.c
79 $(TCC
) -o tcctest3 tcctest3.o
80 .
/tcctest3
> test3.out
81 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
83 $(TCC
) -static
-o tcctest2 tcctest.c
84 .
/tcctest2
> test2.out
85 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
86 # dynamic output + bound check
87 $(TCC
) -b
-o tcctest4 tcctest.c
88 .
/tcctest4
> test4.out
89 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
91 # memory and bound check auto test
92 BOUNDS_OK
= 1 4 8 10 14
93 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
95 btest
: boundtest.c ..
/bcheck.o
96 @echo
------------ $@
------------
97 @for i in
$(BOUNDS_OK
); do \
98 echo
; echo
--- boundtest
$$i ---; \
99 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
100 echo succeded
as expected
; \
102 echo Failed positive
test $$i ; exit
1 ; \
105 for i in
$(BOUNDS_FAIL
); do \
106 echo
; echo
--- boundtest
$$i ---; \
107 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
108 echo Failed negative
test $$i ; exit
1 ;\
110 echo failed
as expected
; \
113 echo
; echo Bound
test OK
117 @echo
------------ $@
------------
118 time .
/ex2
1238 2 3 4 10 13 4
119 time
$(TCC
) -run ..
/examples
/ex2.c
1238 2 3 4 10 13 4
121 time
$(TCC
) -run ..
/examples
/ex3.c
35
124 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
125 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
-w
$(CFLAGS
)
126 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
127 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
128 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
130 ex
%: ..
/examples
/ex
%.c
131 $(CC
) -o
$@
$< $(CFLAGS
)
133 # tiny assembler testing
134 asmtest.ref
: asmtest.S
135 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
136 objdump
-D asmtest.ref.o
> asmtest.ref
139 @echo
------------ $@
------------
141 objdump
-D asmtest.o
> asmtest.out
142 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
144 # targets for development
153 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
156 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
157 vg_annotate tcc.c
> /tmp
/linpack.cache.log
161 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.gcc \
162 tcctest
[1234] ex? libtcc_test
$(EXESUF
) tcc_g tcclib.h