Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / buildbot / buildbot_pnacl.sh
1 #!/bin/bash
2 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 set -o xtrace
7 set -o nounset
8 set -o errexit
9
10 # Tell build.sh and test.sh that we're a bot.
11 export PNACL_BUILDBOT=true
12 # Make TC bots print all log output to console (this variable only affects
13 # build.sh output)
14 export PNACL_VERBOSE=true
15
16 # This affects trusted components of gyp and scons builds.
17 # The setting OPT reuslts in optimized/release trusted executables,
18 # the setting DEBUG results in unoptimized/debug trusted executables
19 BUILD_MODE_HOST=OPT
20 # If true, terminate script when first scons error is encountered.
21 FAIL_FAST=${FAIL_FAST:-true}
22 # This remembers when any build steps failed, but we ended up continuing.
23 RETCODE=0
24 # For scons builds an empty target indicates all targets should be built.
25 # This does not run any tests, though.
26 # Large tests are not included in this group because they cannot be run
27 # in parallel (they can do things like bind to local TCP ports). Large
28 # tests are run separately in the functions below.
29 readonly SCONS_EVERYTHING=""
30 readonly SCONS_S_M="small_tests medium_tests"
31 readonly SCONS_S_M_IRT="small_tests_irt medium_tests_irt"
32
33 # This uses the newlib-based nonsfi_loader.
34 readonly SCONS_NONSFI_NEWLIB="\
35     nonsfi_nacl=1 \
36     nonsfi_tests_irt"
37 # This uses the host-libc-based nonsfi_loader.
38 # Using skip_nonstable_bitcode=1 here disables the tests for zero-cost C++
39 # exception handling, which don't pass for Non-SFI mode yet because we
40 # don't build libgcc_eh for Non-SFI mode.
41 readonly SCONS_NONSFI="\
42     nonsfi_nacl=1 \
43     nonsfi_tests \
44     nonsfi_tests_irt \
45     toolchain_tests_irt \
46     skip_nonstable_bitcode=1 \
47     use_newlib_nonsfi_loader=0"
48
49 # subset of tests used on toolchain builders
50 readonly SCONS_TC_TESTS="small_tests medium_tests"
51
52 readonly SCONS_COMMON="./scons --verbose bitcode=1"
53 readonly UP_DOWN_LOAD="buildbot/file_up_down_load.sh"
54 # This script is used by toolchain bots (i.e. tc-xxx functions)
55 readonly PNACL_BUILD="pnacl/build.sh"
56 readonly DRIVER_TESTS="pnacl/driver/tests/driver_tests.py"
57
58
59 tc-build-translator() {
60   echo @@@BUILD_STEP compile_translator@@@
61   ${PNACL_BUILD} translator-clean-all
62   ${PNACL_BUILD} translator-all
63 }
64
65 tc-prune-translator-pexes() {
66   echo @@@BUILD_STEP prune_translator_pexe@@@
67   ${PNACL_BUILD} translator-prune
68 }
69
70 tc-archive-translator() {
71   echo @@@BUILD_STEP archive_translator@@@
72   ${PNACL_BUILD} translator-tarball pnacl-translator.tgz
73   ${UP_DOWN_LOAD} UploadToolchainTarball ${BUILDBOT_GOT_REVISION} \
74       pnacl_translator pnacl-translator.tgz
75
76   echo @@@BUILD_STEP upload_translator_package_info@@@
77   ${NATIVE_PYTHON} build/package_version/package_version.py archive \
78       --archive-package=pnacl_translator \
79       pnacl-translator.tgz@https://storage.googleapis.com/nativeclient-archive2/toolchain/${BUILDBOT_GOT_REVISION}/naclsdk_pnacl_translator.tgz
80
81   ${NATIVE_PYTHON} build/package_version/package_version.py --annotate upload \
82       --upload-package=pnacl_translator --revision=${BUILDBOT_GOT_REVISION}
83 }
84
85
86 # extract the relevant scons flags for reporting
87 relevant() {
88   for i in "$@" ; do
89     case $i in
90       use_sandboxed_translator=1)
91         echo -n "sbtc "
92         ;;
93       do_not_run_tests=1)
94         echo -n "no_tests "
95         ;;
96       pnacl_generate_pexe=0)
97         echo -n "no_pexe "
98         ;;
99       translate_fast=1)
100         echo -n "fast "
101         ;;
102       --nacl_glibc)
103         echo -n "glibc "
104         ;;
105     esac
106   done
107 }
108
109 # called when a scons invocation fails
110 handle-error() {
111   RETCODE=1
112   echo "@@@STEP_FAILURE@@@"
113   if ${FAIL_FAST} ; then
114     echo "FAIL_FAST enabled"
115     exit 1
116   fi
117 }
118
119 # Clear out object, and temporary directories.
120 clobber() {
121   echo "@@@BUILD_STEP clobber@@@"
122   rm -rf scons-out ../xcodebuild ../out
123 }
124
125 # Generate filenames for arm bot uploads and downloads
126 NAME_ARM_UPLOAD() {
127   echo -n "${BUILDBOT_BUILDERNAME}/${BUILDBOT_GOT_REVISION}"
128 }
129
130 NAME_ARM_DOWNLOAD() {
131   echo -n "${BUILDBOT_TRIGGERED_BY_BUILDERNAME}/${BUILDBOT_GOT_REVISION}"
132 }
133
134 NAME_ARM_TRY_UPLOAD() {
135   echo -n "${BUILDBOT_BUILDERNAME}/"
136   echo -n "${BUILDBOT_SLAVENAME}/"
137   echo -n "${BUILDBOT_BUILDNUMBER}"
138 }
139 NAME_ARM_TRY_DOWNLOAD() {
140   echo -n "${BUILDBOT_TRIGGERED_BY_BUILDERNAME}/"
141   echo -n "${BUILDBOT_TRIGGERED_BY_SLAVENAME}/"
142   echo -n "${BUILDBOT_TRIGGERED_BY_BUILDNUMBER}"
143 }
144
145
146 prune-scons-out() {
147   find scons-out/ \
148     \( -name '*.o' -o -name '*.bc' -o -name 'test_results' \) \
149     -print0 | xargs -0 rm -rf
150 }
151
152 # Tar up the executables which are shipped to the arm HW bots
153 archive-for-hw-bots() {
154   local name=$1
155   local try=$2
156
157   echo "@@@BUILD_STEP tar_generated_binaries@@@"
158   prune-scons-out
159
160   # delete nexes from pexe mode directories to force translation
161   # TODO(dschuff) enable this once we can translate on the hw bots
162   #find scons-out/*pexe*/ -name '*.nexe' -print0 | xargs -0 rm -f
163   tar cvfz arm-scons.tgz scons-out/*arm*
164
165   echo "@@@BUILD_STEP archive_binaries@@@"
166   if [[ ${try} == "try" ]] ; then
167     ${UP_DOWN_LOAD} UploadArmBinariesForHWBotsTry ${name} arm-scons.tgz
168   else
169     ${UP_DOWN_LOAD} UploadArmBinariesForHWBots ${name} arm-scons.tgz
170   fi
171 }
172
173 # Untar archived executables for HW bots
174 unarchive-for-hw-bots() {
175   local name=$1
176   local try=$2
177
178   echo "@@@BUILD_STEP fetch_binaries@@@"
179   if [[ ${try} == "try" ]] ; then
180     ${UP_DOWN_LOAD} DownloadArmBinariesForHWBotsTry ${name} arm-scons.tgz
181   else
182     ${UP_DOWN_LOAD} DownloadArmBinariesForHWBots ${name} arm-scons.tgz
183   fi
184
185   echo "@@@BUILD_STEP untar_binaries@@@"
186   rm -rf scons-out/
187   tar xvfz arm-scons.tgz --no-same-owner
188 }
189
190 # Build with gyp - this only exercises the trusted TC and hence this only
191 # makes sense to run for ARM.
192 gyp-arm-build() {
193   local gypmode="Release"
194   if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
195       gypmode="Debug"
196   fi
197   local toolchain_dir=native_client/toolchain/linux_x86/arm_trusted
198   local extra="-isystem ${toolchain_dir}/usr/include \
199                -Wl,-rpath-link=${toolchain_dir}/lib/arm-linux-gnueabihf \
200                -L${toolchain_dir}/lib \
201                -L${toolchain_dir}/lib/arm-linux-gnueabihf \
202                -L${toolchain_dir}/usr/lib \
203                -L${toolchain_dir}/usr/lib/arm-linux-gnueabihf"
204   # Setup environment for arm.
205
206   export AR=arm-linux-gnueabihf-ar
207   export AS=arm-linux-gnueabihf-as
208   export CC="arm-linux-gnueabihf-gcc ${extra} "
209   export CXX="arm-linux-gnueabihf-g++ ${extra} "
210   export LD="arm-linux-gnueabihf-g++ ${extra} "
211   export RANLIB=arm-linux-gnueabihf-ranlib
212   export SYSROOT
213   export GYP_DEFINES="target_arch=arm \
214     sysroot=${toolchain_dir} \
215     linux_use_tcmalloc=0 armv7=1 arm_thumb=1"
216   export GYP_GENERATORS=make
217
218   # NOTE: this step is also run implicitly as part of
219   #        gclient runhooks --force
220   #       it uses the exported env vars so we have to run it again
221   #
222   echo "@@@BUILD_STEP gyp_configure [${gypmode}]@@@"
223   cd ..
224   native_client/build/gyp_nacl native_client/build/all.gyp
225   cd native_client
226
227   echo "@@@BUILD_STEP gyp_compile [${gypmode}]@@@"
228   make -C .. -k -j8 V=1 BUILDTYPE=${gypmode}
229 }
230
231 build-sbtc-prerequisites() {
232   local platform=$1
233   # Sandboxed translators currently only require irt_core since they do not
234   # use PPAPI.
235   ${SCONS_COMMON} platform=${platform} sel_ldr sel_universal irt_core
236 }
237
238 # Run a single invocation of scons as its own buildbot stage and handle errors
239 scons-stage-irt() {
240   local platform=$1
241   local extra=$2
242   local test=$3
243   local info="$(relevant ${extra})"
244   # TODO(robertm): do we really need both nacl and nacl_irt_test
245   local mode="--mode=opt-host,nacl,nacl_irt_test"
246   if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
247       mode="--mode=dbg-host,nacl,nacl_irt_test"
248   fi
249
250   # We truncate the test list ($test) because long BUILD_STEP strings cause
251   # Buildbot to fail (because the Buildbot master tries to use the string
252   # as a filename).
253   echo "@@@BUILD_STEP scons-irt [${platform}] [${test:0:100}] [${info}]@@@"
254   ${SCONS_COMMON} ${extra} ${mode} platform=${platform} ${test} || handle-error
255 }
256
257 # Run a single invocation of scons as its own buildbot stage and handle errors
258 scons-stage-noirt() {
259   local platform=$1
260   local extra=$2
261   local test=$3
262   local info="$(relevant ${extra})"
263   local mode="--mode=opt-host,nacl"
264   if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
265       mode="--mode=dbg-host,nacl"
266   fi
267
268   echo "@@@BUILD_STEP scons [${platform}] [${test}] [${info}]@@@"
269   ${SCONS_COMMON} ${extra} ${mode} platform=${platform} ${test} || handle-error
270 }
271
272
273 driver-tests() {
274   local arch=$1
275   echo "@@@BUILD_STEP driver_tests ${arch}@@@"
276   ${DRIVER_TESTS} --platform="${arch}" || handle-error
277 }
278
279
280 # QEMU upload bot runs this function, and the hardware download bot runs
281 # mode-buildbot-arm-hw
282 mode-buildbot-arm() {
283   FAIL_FAST=false
284   # "force_emulator=" disables use of QEMU, which enables building
285   # tests which don't work under QEMU.
286   local qemuflags="-j8 -k do_not_run_tests=1 force_emulator="
287
288   clobber
289
290   gyp-arm-build
291
292   # Sanity check
293   scons-stage-noirt "arm" "-j8" "run_hello_world_test"
294
295   # Don't run the rest of the tests on qemu, only build them.
296   # QEMU is too flaky for the main waterfall
297
298   # Normal pexe mode tests
299   scons-stage-noirt "arm" "${qemuflags}" "${SCONS_EVERYTHING}"
300   # This extra step is required to translate the pexes (because translation
301   # happens as part of CommandSelLdrTestNacl and not part of the
302   # build-everything step)
303   scons-stage-noirt "arm" "${qemuflags}" "${SCONS_S_M}"
304   # Large tests cannot be run in parallel
305   scons-stage-noirt "arm" "${qemuflags} -j1" "large_tests"
306
307   # also run some tests with the irt
308   scons-stage-irt "arm" "${qemuflags}" "${SCONS_S_M_IRT}"
309
310   # non-pexe-mode tests
311   scons-stage-noirt "arm" "${qemuflags} pnacl_generate_pexe=0" "nonpexe_tests"
312
313   build-sbtc-prerequisites "arm"
314
315   scons-stage-irt "arm" \
316     "${qemuflags} use_sandboxed_translator=1 translate_in_build_step=0" \
317     "toolchain_tests"
318   scons-stage-irt "arm" \
319     "${qemuflags} use_sandboxed_translator=1 translate_fast=1 \
320        translate_in_build_step=0" \
321     "toolchain_tests"
322
323   # Test Non-SFI Mode.
324   scons-stage-irt "arm" "${qemuflags}" "${SCONS_NONSFI_NEWLIB}"
325   scons-stage-irt "arm" "${qemuflags}" "${SCONS_NONSFI}"
326 }
327
328 mode-buildbot-arm-hw() {
329   FAIL_FAST=false
330   local hwflags="-j2 -k naclsdk_validate=0 built_elsewhere=1"
331
332   scons-stage-noirt "arm" "${hwflags}" "${SCONS_S_M}"
333   # Large tests cannot be run in parallel
334   scons-stage-noirt "arm" "${hwflags} -j1" "large_tests"
335
336   # also run some tests with the irt
337   scons-stage-irt "arm" "${hwflags}" "${SCONS_S_M_IRT}"
338
339   scons-stage-noirt "arm" "${hwflags} pnacl_generate_pexe=0" "nonpexe_tests"
340   scons-stage-irt "arm" \
341     "${hwflags} use_sandboxed_translator=1 translate_in_build_step=0" \
342     "toolchain_tests"
343   scons-stage-irt "arm" \
344     "${hwflags} use_sandboxed_translator=1 translate_fast=1 \
345        translate_in_build_step=0" \
346     "toolchain_tests"
347
348   # Test Non-SFI Mode.
349   scons-stage-irt "arm" "${hwflags}" "${SCONS_NONSFI_NEWLIB}"
350   scons-stage-irt "arm" "${hwflags}" "${SCONS_NONSFI}"
351 }
352
353 mode-trybot-qemu() {
354   clobber
355   # TODO(dschuff): move the gyp build to buildbot_pnacl.py
356   gyp-arm-build
357
358   buildbot/buildbot_pnacl.py opt arm pnacl
359 }
360
361 mode-buildbot-arm-dbg() {
362   BUILD_MODE_HOST=DEDUG
363   mode-buildbot-arm
364   archive-for-hw-bots $(NAME_ARM_UPLOAD) regular
365 }
366
367 mode-buildbot-arm-opt() {
368   mode-buildbot-arm
369   archive-for-hw-bots $(NAME_ARM_UPLOAD) regular
370 }
371
372 mode-buildbot-arm-try() {
373   mode-buildbot-arm
374   archive-for-hw-bots $(NAME_ARM_TRY_UPLOAD) try
375 }
376
377 # NOTE: the hw bots are too slow to build stuff on so we just
378 #       use pre-built executables
379 mode-buildbot-arm-hw-dbg() {
380   BUILD_MODE_HOST=DEDUG
381   unarchive-for-hw-bots $(NAME_ARM_DOWNLOAD)  regular
382   mode-buildbot-arm-hw
383 }
384
385 mode-buildbot-arm-hw-opt() {
386   unarchive-for-hw-bots $(NAME_ARM_DOWNLOAD)  regular
387   mode-buildbot-arm-hw
388 }
389
390 mode-buildbot-arm-hw-try() {
391   unarchive-for-hw-bots $(NAME_ARM_TRY_DOWNLOAD)  try
392   mode-buildbot-arm-hw
393 }
394
395 # These 2 functions are also suitable for local TC sanity testing.
396 tc-tests-all() {
397   local is_try=$1
398
399   local label="pnacl_newlib_dir=toolchain/${PNACL_TOOLCHAIN_DIR}"
400   local scons_flags="-k skip_trusted_tests=1 -j8 ${label}"
401
402   # newlib
403   for arch in x86-32 x86-64 arm; do
404     driver-tests "${arch}"
405   done
406
407   # All the SCons tests (the same ones run by the main waterfall bot)
408   for arch in 32 64 arm; do
409     buildbot/buildbot_pnacl.py opt "${arch}" pnacl
410   done
411
412   # Run the GCC torture tests just for x86-32.  Testing a single
413   # architecture gives good coverage without taking too long.  We
414   # don't test x86-64 here because some of the torture tests fail on
415   # the x86-64 toolchain trybot (though not the buildbots, apparently
416   # due to a hardware difference:
417   # https://code.google.com/p/nativeclient/issues/detail?id=3697).
418
419   # Build the SDK libs first so that linking will succeed.
420   echo "@@@BUILD_STEP sdk libs @@@"
421   ${PNACL_BUILD} sdk
422   ./scons --verbose platform=x86-32 -j8 sel_ldr irt_core
423
424   echo "@@@BUILD_STEP torture_tests x86-32 @@@"
425   tools/toolchain_tester/torture_test.py pnacl x86-32 --verbose \
426       --concurrency=8 || handle-error
427 }
428
429 tc-tests-fast() {
430   local arch="$1"
431   local scons_flags="-k skip_trusted_tests=1"
432
433   driver-tests "${arch}"
434
435   scons-stage-noirt "${arch}" "${scons_flags} -j8" "${SCONS_TC_TESTS}"
436   # Large tests cannot be run in parallel
437   scons-stage-noirt "${arch}" "${scons_flags} -j1" "large_tests"
438   scons-stage-noirt "${arch}" "${scons_flags} -j8 pnacl_generate_pexe=0" \
439     "nonpexe_tests"
440 }
441
442 mode-buildbot-tc-x8664-linux() {
443   local is_try=$1
444   FAIL_FAST=false
445   export PNACL_TOOLCHAIN_DIR=linux_x86/pnacl_newlib
446   export PNACL_PRUNE=true
447
448   tc-build-translator
449   if ! ${is_try} ; then
450     tc-prune-translator-pexes
451     tc-archive-translator
452   fi
453   HOST_ARCH=x86_64 tc-tests-all ${is_try}
454 }
455
456 mode-buildbot-tc-x8632-linux() {
457   local is_try=$1
458   FAIL_FAST=false
459   export PNACL_TOOLCHAIN_DIR=linux_x86/pnacl_newlib
460
461   # For now, just use this bot to test a pure 32 bit build.
462   HOST_ARCH=x86_32 tc-tests-fast "x86-32"
463 }
464
465
466 ######################################################################
467 # On Windows, this script is invoked from a batch file.
468 # The inherited PWD environmental variable is a Windows-style path.
469 # This can cause problems with pwd and bash. This line fixes it.
470 cd -P .
471
472 # Script assumed to be run in native_client/
473 if [[ $(pwd) != */native_client ]]; then
474   echo "ERROR: must be run in native_client!"
475   exit 1
476 fi
477
478
479 if [[ $# -eq 0 ]] ; then
480   echo "you must specify a mode on the commandline:"
481   exit 1
482 fi
483
484 if [ "$(type -t $1)" != "function" ]; then
485   Usage
486   echo "ERROR: unknown mode '$1'." >&2
487   exit 1
488 fi
489
490 "$@"
491
492 if [[ ${RETCODE} != 0 ]]; then
493   echo "@@@BUILD_STEP summary@@@"
494   echo There were failed stages.
495   exit ${RETCODE}
496 fi