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
34 libtest
: libtcc_test
$(EXESUF
) ..
/libtcc1.a
35 @echo
------------ $@
------------
36 .
/libtcc_test
$(EXESUF
) lib_path
=..
38 libtcc_test
$(EXESUF
): libtcc_test.c ..
/$(LIBTCC
)
39 $(CC
) -o
$@
$^
-I..
$(CFLAGS
) $(LIBS
) $(LINK_LIBTCC
)
41 # test.ref - generate using gcc
42 # copy only tcclib.h so GCC's stddef and stdarg will be used
44 cp
-u ..
/include/tcclib.h .
45 $(CC
) -o tcctest.gcc
$< -I.
-w
$(CFLAGS
) -std
=gnu99
50 @echo
------------ $@
------------
51 $(TCC
) -run tcctest.c
> test.out1
52 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
54 # iterated test2 (compile tcc then compile tcctest.c !)
56 @echo
------------ $@
------------
57 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out2
58 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
60 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
62 @echo
------------ $@
------------
63 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out3
64 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
68 @echo
------------ $@
------------
70 $(TCC
) -o tcctest1 tcctest.c
71 .
/tcctest1
> test1.out
72 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
73 # object + link output
74 $(TCC
) -c
-o tcctest3.o tcctest.c
75 $(TCC
) -o tcctest3 tcctest3.o
76 .
/tcctest3
> test3.out
77 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
79 $(TCC
) -static
-o tcctest2 tcctest.c
80 .
/tcctest2
> test2.out
81 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
82 # dynamic output + bound check
83 $(TCC
) -b
-o tcctest4 tcctest.c
84 .
/tcctest4
> test4.out
85 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
87 # memory and bound check auto test
88 BOUNDS_OK
= 1 4 8 10 14
89 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
91 btest
: boundtest.c ..
/bcheck.o
92 @echo
------------ $@
------------
93 @for i in
$(BOUNDS_OK
); do \
94 echo
; echo
--- boundtest
$$i ---; \
95 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
96 echo succeded
as expected
; \
98 echo Failed positive
test $$i ; exit
1 ; \
101 for i in
$(BOUNDS_FAIL
); do \
102 echo
; echo
--- boundtest
$$i ---; \
103 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
104 echo Failed negative
test $$i ; exit
1 ;\
106 echo failed
as expected
; \
109 echo
; echo Bound
test OK
113 @echo
------------ $@
------------
114 time .
/ex2
1238 2 3 4 10 13 4
115 time
$(TCC
) -run ..
/examples
/ex2.c
1238 2 3 4 10 13 4
117 time
$(TCC
) -run ..
/examples
/ex3.c
35
120 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
121 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
-w
$(CFLAGS
)
122 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
123 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
124 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
126 ex
%: ..
/examples
/ex
%.c
127 $(CC
) -o
$@
$< $(CFLAGS
)
129 # tiny assembler testing
130 asmtest.ref
: asmtest.S
131 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
132 objdump
-D asmtest.ref.o
> asmtest.ref
135 @echo
------------ $@
------------
137 objdump
-D asmtest.o
> asmtest.out
138 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
140 # targets for development
149 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
152 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
153 vg_annotate tcc.c
> /tmp
/linpack.cache.log
157 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.gcc \
158 tcctest
[1234] ex? libtcc_test
$(EXESUF
) tcc_g tcclib.h