comparison src/capnproto-git-20161025/super-test.sh @ 48:9530b331f8c1

Add Cap'n Proto source
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 25 Oct 2016 11:17:01 +0100
parents
children
comparison
equal deleted inserted replaced
47:d93140aac40b 48:9530b331f8c1
1 #! /usr/bin/env bash
2
3 set -euo pipefail
4
5 doit() {
6 echo "@@@@ $@"
7 "$@"
8 }
9
10 QUICK=
11
12 while [ $# -gt 0 ]; do
13 case "$1" in
14 test )
15 ;; # nothing
16 quick )
17 QUICK=quick
18 ;;
19 caffeinate )
20 # Re-run preventing sleep.
21 shift
22 exec caffeinate -ims $0 $@
23 ;;
24 tmpdir )
25 # Clone to a temp directory.
26 if [ "$#" -lt 2 ]; then
27 echo "usage: $0 tmpdir NAME [COMMAND]" >&2
28 exit 1
29 fi
30 DIR=/tmp/$2
31 shift 2
32 if [ -e $DIR ]; then
33 if [ "${DIR/*..*}" = "" ]; then
34 echo "NO DO NOT PUT .. IN THERE IT'S GOING TO GO IN /tmp AND I'M GONNA DELETE IT" >&2
35 exit 1
36 fi
37 if [ ! -e "$DIR/super-test.sh" ]; then
38 echo "$DIR exists and it doesn't look like one of mine." >&2
39 exit 1
40 fi
41 # make distcheck leaves non-writable files when it fails, so we need to chmod to be safe.
42 chmod -R +w $DIR
43 rm -rf $DIR
44 fi
45 git clone . $DIR
46 cd $DIR
47 exec ./super-test.sh "$@"
48 ;;
49 remote )
50 if [ "$#" -lt 2 ]; then
51 echo "usage: $0 remote HOST [COMMAND]" >&2
52 exit 1
53 fi
54 HOST=$2
55 shift 2
56 echo "========================================================================="
57 echo "Pushing code to $HOST..."
58 echo "========================================================================="
59 BRANCH=$(git rev-parse --abbrev-ref HEAD)
60 ssh $HOST '(chmod -fR +w tmp-test-capnp || true) && rm -rf tmp-test-capnp && mkdir tmp-test-capnp && git init tmp-test-capnp'
61 git push ssh://$HOST/~/tmp-test-capnp "$BRANCH:test"
62 ssh $HOST "cd tmp-test-capnp && git checkout test"
63 exec ssh $HOST "cd tmp-test-capnp && ./super-test.sh $@ && cd .. && rm -rf tmp-test-capnp"
64 ;;
65 clang )
66 export CXX=clang++
67 ;;
68 gcc-4.9 )
69 export CXX=g++-4.9
70 ;;
71 gcc-4.8 )
72 export CXX=g++-4.8
73 ;;
74 gcc-4.7 )
75 export CXX=g++-4.7
76 ;;
77 mingw )
78 if [ "$#" -ne 2 ]; then
79 echo "usage: $0 mingw CROSS_HOST" >&2
80 exit 1
81 fi
82 CROSS_HOST=$2
83
84 cd c++
85 test -e configure || doit autoreconf -i
86 test ! -e Makefile || (echo "ERROR: Directory unclean!" >&2 && false)
87 doit ./configure --host="$CROSS_HOST" --disable-shared CXXFLAGS='-static-libgcc -static-libstdc++'
88 doit make -j6 capnp.exe capnpc-c++.exe
89
90 cp capnp.exe capnp-mingw.exe
91 cp capnpc-c++.exe capnpc-c++-mingw.exe
92
93 doit make distclean
94 doit ./configure --host="$CROSS_HOST" --with-external-capnp --disable-shared --disable-reflection CXXFLAGS='-static-libgcc -static-libstdc++' CAPNP=./capnp-mingw.exe CAPNPC_CXX=./capnpc-c++-mingw.exe
95
96 doit make -j6 check
97 doit make distclean
98 rm -f *-mingw.exe
99 exit 0
100 ;;
101 android )
102 if [ "$#" -ne 4 ]; then
103 echo "usage: $0 android SDK_HOME TOOLCHAIN_HOME CROSS_HOST" >&2
104 exit 1
105 fi
106 SDK_HOME=$2
107 TOOLCHAIN_HOME=$3
108 CROSS_HOST=$4
109
110 cd c++
111 test -e configure || doit autoreconf -i
112 test ! -e Makefile || (echo "ERROR: Directory unclean!" >&2 && false)
113 doit ./configure --disable-shared
114 doit make -j6 capnp capnpc-c++
115
116 cp capnp capnp-host
117 cp capnpc-c++ capnpc-c++-host
118
119 export PATH="$TOOLCHAIN_HOME/bin:$PATH"
120 doit make distclean
121 doit ./configure --host="$CROSS_HOST" --with-external-capnp --disable-shared CXXFLAGS='-pie -fPIE' CAPNP=./capnp-host CAPNPC_CXX=./capnpc-c++-host
122
123 doit make -j6
124 doit make -j6 capnp-test
125
126 echo "Starting emulator..."
127 trap 'kill $(jobs -p)' EXIT
128 $SDK_HOME/tools/emulator -avd n6 -no-window &
129 $SDK_HOME/platform-tools/adb wait-for-device
130 echo "Waiting for localhost to be resolvable..."
131 $SDK_HOME/platform-tools/adb shell 'while ! ping -c 1 localhost > /dev/null 2>&1; do sleep 1; done'
132 doit $SDK_HOME/platform-tools/adb push capnp-test /data/capnp-test
133 doit $SDK_HOME/platform-tools/adb shell 'cd /data && /data/capnp-test && echo ANDROID_""TESTS_PASSED' | tee android-test.log
134 grep -q ANDROID_TESTS_PASSED android-test.log
135
136 doit make distclean
137 rm -f capnp-host capnpc-c++-host
138 exit 0
139 ;;
140 cmake )
141 cd c++
142 rm -rf cmake-build
143 mkdir cmake-build
144 cd cmake-build
145 doit cmake -G "Unix Makefiles" ..
146 doit make -j6 check
147 exit 0
148 ;;
149 exotic )
150 echo "========================================================================="
151 echo "MinGW 64-bit"
152 echo "========================================================================="
153 "$0" mingw x86_64-w64-mingw32
154 echo "========================================================================="
155 echo "MinGW 32-bit"
156 echo "========================================================================="
157 "$0" mingw i686-w64-mingw32
158 echo "========================================================================="
159 echo "Android"
160 echo "========================================================================="
161 "$0" android /home/kenton/android/android-sdk-linux /home/kenton/android/android-16 arm-linux-androideabi
162 echo "========================================================================="
163 echo "CMake"
164 echo "========================================================================="
165 "$0" cmake
166 exit 0
167 ;;
168 clean )
169 rm -rf tmp-staging
170 cd c++
171 if [ -e Makefile ]; then
172 doit make maintainer-clean
173 fi
174 rm -f capnproto-*.tar.gz samples/addressbook samples/addressbook.capnp.c++ \
175 samples/addressbook.capnp.h
176 exit 0
177 ;;
178 help )
179 echo "usage: $0 [COMMAND]"
180 echo "commands:"
181 echo " test Runs tests (the default)."
182 echo " clang Runs tests using Clang compiler."
183 echo " gcc-4.7 Runs tests using gcc-4.7."
184 echo " gcc-4.8 Runs tests using gcc-4.8."
185 echo " gcc-4.9 Runs tests using gcc-4.9."
186 echo " remote HOST Runs tests on HOST via SSH."
187 echo " mingw Cross-compiles to MinGW and runs tests using WINE."
188 echo " android Cross-compiles to Android and runs tests using emulator."
189 echo " clean Delete temporary files that may be left after failure."
190 echo " help Prints this help text."
191 exit 0
192 ;;
193 * )
194 echo "unknown command: $1" >&2
195 echo "try: $0 help" >&2
196 exit 1
197 ;;
198 esac
199 shift
200 done
201
202 # Build optimized builds because they catch more problems, but also enable debugging macros.
203 # Enable lots of warnings and make sure the build breaks if they fire. Disable strict-aliasing
204 # because GCC warns about code that I know is OK. Disable sign-compare because I've fixed more
205 # sign-compare warnings than probably all other warnings combined and I've never seen it flag a
206 # real problem. Disable unused parameters because it's stupidly noisy and never a real problem.
207 export CXXFLAGS="-O2 -DDEBUG -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-sign-compare -Wno-unused-parameter"
208
209 STAGING=$PWD/tmp-staging
210
211 rm -rf "$STAGING"
212 mkdir "$STAGING"
213 mkdir "$STAGING/bin"
214 mkdir "$STAGING/lib"
215 export PATH=$STAGING/bin:$PATH
216 export LD_LIBRARY_PATH=$STAGING/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
217 export PKG_CONFIG_PATH=$STAGING/lib/pkgconfig
218
219 if [ "$QUICK" = quick ]; then
220 echo "************************** QUICK TEST ***********************************"
221 fi
222
223 echo "========================================================================="
224 echo "Building c++"
225 echo "========================================================================="
226
227 # Apple now aliases gcc to clang, so probe to find out what compiler we're really using.
228 if (${CXX:-g++} -dM -E -x c++ /dev/null 2>&1 | grep -q '__clang__'); then
229 IS_CLANG=yes
230 else
231 IS_CLANG=no
232 fi
233
234 if [ $IS_CLANG = yes ]; then
235 # Don't fail out on this ridiculous "argument unused during compilation" warning.
236 export CXXFLAGS="$CXXFLAGS -Wno-error=unused-command-line-argument"
237 else
238 # GCC emits uninitialized warnings all over and they seem bogus. We use valgrind to test for
239 # uninitialized memory usage later on.
240 CXXFLAGS="$CXXFLAGS -Wno-maybe-uninitialized"
241 fi
242
243 cd c++
244 doit autoreconf -i
245 doit ./configure --prefix="$STAGING"
246 doit make -j6 check
247
248 if [ $IS_CLANG = no ]; then
249 # Verify that generated code compiles with pedantic warnings. Make sure to treat capnp headers
250 # as system headers so warnings in them are ignored.
251 doit ${CXX:-g++} -isystem src -std=c++11 -fno-permissive -pedantic -Wall -Wextra -Werror \
252 -c src/capnp/test.capnp.c++ -o /dev/null
253 fi
254
255 echo "========================================================================="
256 echo "Testing c++ install"
257 echo "========================================================================="
258
259 doit make install
260
261 test "x$(which capnp)" = "x$STAGING/bin/capnp"
262 test "x$(which capnpc-c++)" = "x$STAGING/bin/capnpc-c++"
263
264 cd samples
265
266 doit capnp compile -oc++ addressbook.capnp -I"$STAGING"/include --no-standard-import
267 doit ${CXX:-g++} -std=c++11 addressbook.c++ addressbook.capnp.c++ -o addressbook \
268 $CXXFLAGS $(pkg-config --cflags --libs capnp)
269 echo "@@@@ ./addressbook (in various configurations)"
270 ./addressbook write | ./addressbook read
271 ./addressbook dwrite | ./addressbook dread
272 rm addressbook addressbook.capnp.c++ addressbook.capnp.h
273
274 doit capnp compile -oc++ calculator.capnp -I"$STAGING"/include --no-standard-import
275 doit ${CXX:-g++} -std=c++11 calculator-client.c++ calculator.capnp.c++ -o calculator-client \
276 $CXXFLAGS $(pkg-config --cflags --libs capnp-rpc)
277 doit ${CXX:-g++} -std=c++11 calculator-server.c++ calculator.capnp.c++ -o calculator-server \
278 $CXXFLAGS $(pkg-config --cflags --libs capnp-rpc)
279 rm -f /tmp/capnp-calculator-example-$$
280 ./calculator-server unix:/tmp/capnp-calculator-example-$$ &
281 sleep 0.1
282 ./calculator-client unix:/tmp/capnp-calculator-example-$$
283 kill %+
284 wait %+ || true
285 rm calculator-client calculator-server calculator.capnp.c++ calculator.capnp.h /tmp/capnp-calculator-example-$$
286
287 cd ..
288
289 if [ "$QUICK" = quick ]; then
290 doit make maintainer-clean
291 rm -rf "$STAGING"
292 exit 0
293 fi
294
295 echo "========================================================================="
296 echo "Testing --with-external-capnp"
297 echo "========================================================================="
298
299 doit make distclean
300 doit ./configure --prefix="$STAGING" --disable-shared \
301 --with-external-capnp CAPNP=$STAGING/bin/capnp
302 doit make -j6 check
303
304 echo "========================================================================="
305 echo "Testing --disable-reflection"
306 echo "========================================================================="
307
308 doit make distclean
309 doit ./configure --prefix="$STAGING" --disable-shared --disable-reflection \
310 --with-external-capnp CAPNP=$STAGING/bin/capnp
311 doit make -j6 check
312 doit make distclean
313
314 # Test 32-bit build now while we have $STAGING available for cross-compiling.
315 if [ "x`uname -m`" = "xx86_64" ]; then
316 echo "========================================================================="
317 echo "Testing 32-bit build"
318 echo "========================================================================="
319
320 if [[ "`uname`" =~ CYGWIN ]]; then
321 # It's just not possible to run cygwin32 binaries from within cygwin64.
322
323 # Build as if we are cross-compiling, using the capnp we installed to $STAGING.
324 doit ./configure --prefix="$STAGING" --disable-shared --host=i686-pc-cygwin \
325 --with-external-capnp CAPNP=$STAGING/bin/capnp
326 doit make -j6
327 doit make -j6 capnp-test.exe
328
329 # Expect a cygwin32 sshd to be listening at localhost port 2222, and use it
330 # to run the tests.
331 doit scp -P 2222 capnp-test.exe localhost:~/tmp-capnp-test.exe
332 doit ssh -p 2222 localhost './tmp-capnp-test.exe && rm tmp-capnp-test.exe'
333
334 doit make distclean
335
336 elif [ "x${CXX:-g++}" != "xg++-4.8" ]; then
337 doit ./configure CXX="${CXX:-g++} -m32" --disable-shared
338 doit make -j6 check
339 doit make distclean
340 fi
341 fi
342
343 echo "========================================================================="
344 echo "Testing c++ uninstall"
345 echo "========================================================================="
346
347 doit ./configure --prefix="$STAGING"
348 doit make uninstall
349
350 echo "========================================================================="
351 echo "Testing c++ dist"
352 echo "========================================================================="
353
354 doit make -j6 distcheck
355 doit make distclean
356 rm capnproto-*.tar.gz
357
358 if [ "x`uname`" = xLinux ]; then
359 echo "========================================================================="
360 echo "Testing generic Unix (no Linux-specific features)"
361 echo "========================================================================="
362
363 doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -DKJ_USE_FUTEX=0 -DKJ_USE_EPOLL=0"
364 doit make -j6 check
365 doit make distclean
366 fi
367
368 echo "========================================================================="
369 echo "Testing with -fno-rtti and -fno-exceptions"
370 echo "========================================================================="
371
372 doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-rtti"
373 doit make -j6 check
374 doit make distclean
375 doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-exceptions"
376 doit make -j6 check
377 doit make distclean
378 doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-rtti -fno-exceptions"
379 doit make -j6 check
380
381 # Valgrind is currently "experimental and mostly broken" on OSX and fails to run the full test
382 # suite, but I have it installed because it did manage to help me track down a bug or two. Anyway,
383 # skip it on OSX for now.
384 if [ "x`uname`" != xDarwin ] && which valgrind > /dev/null; then
385 doit make distclean
386
387 echo "========================================================================="
388 echo "Testing with valgrind"
389 echo "========================================================================="
390
391 doit ./configure --disable-shared CXXFLAGS="-g"
392 doit make -j6
393 doit make -j6 capnp-test
394 doit valgrind --leak-check=full --track-fds=yes --error-exitcode=1 ./capnp-test
395 fi
396
397 doit make maintainer-clean
398
399 rm -rf "$STAGING"