buildlib: supply -fPIC or -fpic if supported
[blocksruntime.git] / checktests
bloba8617d35c911425051ce5216a9d19e82bcf11a08
1 #!/bin/sh
3 # This file produces TAP compliant output
5 # NOTE:
6 # This file can be run directly or with "prove" like this:
7 # prove checktests
8 # Or like this:
9 # prove -v checktests
10 # Do not forget to set the compiler if needed like so:
11 # CC=my-clang-build prove -v checktests
13 : ${CC:=clang}
14 : ${CXX:=$CC}
15 : ${CFLAGS:=}
16 LC_ALL=C
17 export LC_ALL
18 CPPFLAGS='-O -Wno-unused -include testprefix.h -IBlocksRuntime'
19 CCFLAGS='-std=c99 -Wimplicit-function-declaration'
20 LIB=libBlocksRuntime.a
21 TESTDIR=testbin
22 rm -rf $TESTDIR
23 mkdir $TESTDIR
24 diag () {
25 while [ $# != 0 ]; do
26 echo '# '"$1"
27 shift
28 done
30 diagfilt() {
31 while read -r LINE; do
32 echo '# '"$LINE"
33 done
35 usedashs=
36 diag 'blocksruntime tests' ''
37 if ! ccver="$("$CC" --version 2>&1)"; then
38 echo 'Bail out! '"\"$CC\" not installed (did you forget to set \$CC?)"
39 exit 1
40 else
41 out="$( ("$CC" -fblocks -c -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1)"
42 case "$out" in *"-fblocks"*)
43 out="$( ("$CC" -fblocks -S -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1)"
44 case "$out" in *"-fblocks"*)
45 echo 'Bail out! '"\"$CC\" does not support the -fblocks option"
46 exit 1
47 esac
48 usedashs=1
49 diag "WARNING: -S required for -fblocks with $CC"
50 esac
51 ccmach="$("$CC" -dumpmachine 2>/dev/null)"
53 warnskipcxx=
54 if cxxver="$("$CXX" --version 2>&1)"; then
55 dopp=1
56 out="$( ("$CXX" -fblocks -c -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1)"
57 case "$out" in *"-fblocks"*)
58 out="$( ("$CXX" -fblocks -S -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1)"
59 case "$out" in
60 *"-fblocks"*)
61 warnskipcxx="\"$CXX\" does not support the -fblocks option; skipping C++ tests"
62 dopp=
65 usedashs=1
67 esac
68 if [ "$CC" != "$CXX" ]; then
69 diag "WARNING: -S required for -fblocks with $CXX"
71 esac
72 if [ -n "$dopp" ]; then
73 cxxmach="$("$CXX" -dumpmachine 2>/dev/null)"
74 cxxdver="$("$CXX" -dumpversion 2>/dev/null)"
76 else
77 warnskipcxx="\"$CXX\" not installed; skipping C++ tests"
79 if [ -n "$usedashs" ]; then
80 diag ""
82 if [ -n "$warnskipcxx" ]; then
83 diag "$warnskipcxx" ""
85 if [ ! -r "$LIB" ]; then
86 echo 'Bail out! '"No \"$LIB\" file found, try running \"$(dirname "$0")/buildlib\" first"
87 exit 1
89 iscc_clang=
90 iscxx_clang=
91 case "$ccver" in *[Cc][Ll][Aa][Nn][Gg]*)
92 iscc_clang=1
93 esac
94 case "$cxxver" in *[Cc][Ll][Aa][Nn][Gg]*)
95 iscxx_clang=1
96 esac
97 if [ -n "$iscxx_clang" ]; then case "$cxxdver" in
98 "1.1")
99 skiprefC=1
100 esac; fi
101 iscc_armhf=
102 iscxx_armhf=
103 case "$ccmach" in arm-*)
104 case "$ccmach" in *abihf)
105 iscc_armhf=1
106 esac
107 esac
108 case "$cxxmach" in arm-*)
109 case "$cxxmach" in *abihf)
110 iscxx_armhf=1
111 esac
112 esac
113 diag "CC${iscc_clang:+(clang)}: $CC --version"
114 echo "$ccver" | diagfilt
115 diag ''
116 if [ -n "$dopp" -a z"$CXX" != z"$CC" ]; then
117 diag "CXX${iscxx_clang:+(clang)}: $CXX --version"
118 echo "$cxxver" | diagfilt
119 diag ''
121 testcount=0
122 failcount=0
123 xfailcount=0
124 bonuscount=0
125 skipcount=0
126 skipcpp=0
127 passcount=0
128 testsfailed=
129 for test in BlocksRuntime/tests/*.[cC]; do
130 testname="${test#BlocksRuntime/tests/}"
131 skip=
132 skipdoze=
133 extra=
134 stub=
135 xfail=
136 reason=
137 showxfail=
138 testcount=$(($testcount + 1))
139 case $testname in
140 rdar6405500.c | \
141 rdar6414583.c | \
142 objectRRGC.c | \
143 dispatch_async.c) skip=1;;
144 fail.c) skipdoze=1;;
145 macro.c) stub='void foo(); int main(){foo(); printf("success");}';;
146 varargs-bad-assign.c | \
147 rettypepromotion.c | \
148 shorthandexpression.c | \
149 k-and-r.c | \
150 sizeof.c | \
151 orbars.c | \
152 constassign.c) xfail=1;;
153 copy-block-literal-rdar6439600.c) reason='compiler bug'; showxfail=1; xfail=1;;
154 ${iscc_clang}cast.c) reason='gcc compiler bug'; showxfail=1; xfail=1;;
155 ${iscxx_clang}josh.C) reason='g++ compiler bug'; showxfail=1; xfail=1;;
156 reference.C)
157 if [ -n "$skiprefC" ]; then
158 reason="\"$CXX\" version too old"
159 xfail=1
160 fi;;
161 variadic.c)
162 if [ -n "$iscc_armhf" ]; then
163 reason='incorrect clang armhf block float vararg implementation'
164 showxfail=1
165 xfail=1
166 fi;;
167 esac
168 ext=.c
169 cpp=
170 USECC="$CC"
171 USEFLAGS="$CCFLAGS $CPPFLAGS"
172 USELIB="$LIB"
173 case $test in
174 *.C) cpp=1; ext=.C;;
175 *.cpp) cpp=1; ext=.cpp;;
176 *.cp) cpp=1; ext=.cp;;
177 *.c++) cpp=1; ext=.c++;;
178 esac
179 if [ -n "$cpp" ]; then
180 USECC="$CXX"
181 USEFLAGS="$CPPFLAGS"
182 USELIB="$LIB -lstdc++"
184 if [ -n "$COMSPEC" -a -n "$skipdoze" ]; then
185 skip=1
187 if [ -z "$skip" -a -n "$cpp" -a -z "$dopp" ]; then
188 echo "ok $testcount - $testname # skipped: C++ with blocks not available"
189 skipcpp=$(($skipcpp + 1))
190 skipcount=$(($skipcount + 1))
191 else
192 if [ -n "$skip" ]; then
193 if [ -n "$skipdoze" ]; then
194 echo "ok $testcount - $testname # skipped: not supported on this platform"
195 else
196 echo "ok $testcount - $testname # skipped: not supported"
198 skipcount=$(($skipcount + 1))
199 else
200 if [ -n "$stub" ]; then
201 out="$( (
202 if [ -z "$usedashs" ]; then
203 "$USECC" -c $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).o -fblocks $test && \
204 echo "$stub" | "$USECC" $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext) -fblocks \
205 $TESTDIR/$(basename $test $ext).o $USELIB -x c - && \
206 cd $TESTDIR && ./$(basename $test $ext)
207 else
208 "$USECC" -S $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).s -fblocks $test && \
209 "$USECC" -c $CFLAGS $extra -o $TESTDIR/$(basename $test $ext).o \
210 $TESTDIR/$(basename $test $ext).s && \
211 echo "$stub" | "$USECC" $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext) \
212 $TESTDIR/$(basename $test $ext).o $USELIB -x c - && \
213 cd $TESTDIR && ./$(basename $test $ext)
215 ) 2>&1)"
216 else
217 out="$( (
218 if [ -z "$usedashs" ]; then
219 "$USECC" -c $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).o -fblocks $test && \
220 "$USECC" $CFLAGS -o $TESTDIR/$(basename $test $ext) -fblocks $TESTDIR/$(basename $test $ext).o $USELIB && \
221 cd $TESTDIR && ./$(basename $test $ext)
222 else
223 "$USECC" -S $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).s -fblocks $test && \
224 "$USECC" -c $CFLAGS $extra -o $TESTDIR/$(basename $test $ext).o \
225 $TESTDIR/$(basename $test $ext).s && \
226 "$USECC" $CFLAGS -o $TESTDIR/$(basename $test $ext) $TESTDIR/$(basename $test $ext).o $USELIB && \
227 cd $TESTDIR && ./$(basename $test $ext)
229 ) 2>&1)"
231 result=$?
232 if [ -n "$xfail" ]; then
233 xfailcount=$(($xfailcount + 1))
234 : ${reason:=expected to fail}
235 if [ $result = 0 ]; then
236 bonuscount=$(($bonuscount + 1))
237 passcount=$(($passcount + 1))
238 echo "ok $testcount - $testname # TODO: $reason"
239 else
240 echo "not ok $testcount - $testname # TODO: $reason"
241 if [ -n "$showxfail" ]; then
242 echo "$out" | diagfilt
245 else
246 if [ $result != 0 ]; then
247 testsfailed=1
248 failcount=$(($failcount + 1))
249 echo "not ok $testcount - $testname"
250 echo "$out" | diagfilt
251 else
252 echo "ok $testcount - $testname"
253 passcount=$(($passcount + 1))
258 done
259 diag "" "test count: $testcount"
260 if [ $bonuscount != 0 ]; then
261 diag " passed: $passcount (todo=$bonuscount)"
262 else
263 diag " passed: $passcount"
265 if [ $xfailcount != 0 ]; then
266 if [ $bonuscount != 0 ]; then
267 diag " xfail: $xfailcount (passed=$bonuscount)"
268 else
269 diag " xfail: $xfailcount"
272 if [ $skipcount != 0 ]; then
273 if [ $skipcpp != 0 ]; then
274 diag " skipped: $skipcount (C++=$skipcpp)"
275 else
276 diag " skipped: $skipcount"
279 if [ $failcount != 0 ]; then
280 diag " failed: $failcount"
282 if [ -n "$testsfailed" ]; then
283 diag "test failures occurred"
284 else
285 diag "all tests passed"
287 diag ""
288 echo "1..$testcount"
289 [ -z "$testsfailed" ] || exit 1
290 exit 0