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