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.
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
14 export PNACL_VERBOSE=true
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
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.
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"
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 \
41 run_malloc_realloc_calloc_free_test_irt \
43 run_syscall_test_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
51 readonly SCONS_NONSFI_TC="\
55 run_hello_world_test \
61 # subset of tests used on toolchain builders
62 readonly SCONS_TC_TESTS="small_tests medium_tests"
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"
71 tc-build-translator() {
72 echo @@@BUILD_STEP compile_translator@@@
73 ${PNACL_BUILD} translator-clean-all
74 ${PNACL_BUILD} translator-all
77 tc-prune-translator-pexes() {
78 echo @@@BUILD_STEP prune_translator_pexe@@@
79 ${PNACL_BUILD} translator-prune
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
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
93 ${NATIVE_PYTHON} build/package_version/package_version.py --annotate upload \
94 --upload-package=pnacl_translator --revision=${BUILDBOT_GOT_REVISION}
98 # extract the relevant scons flags for reporting
102 use_sandboxed_translator=1)
108 pnacl_generate_pexe=0)
121 # called when a scons invocation fails
124 echo "@@@STEP_FAILURE@@@"
125 if ${FAIL_FAST} ; then
126 echo "FAIL_FAST enabled"
131 # Clear out object, and temporary directories.
133 echo "@@@BUILD_STEP clobber@@@"
134 rm -rf scons-out ../xcodebuild ../out
137 # Generate filenames for arm bot uploads and downloads
139 echo -n "${BUILDBOT_BUILDERNAME}/${BUILDBOT_GOT_REVISION}"
142 NAME_ARM_DOWNLOAD() {
143 echo -n "${BUILDBOT_TRIGGERED_BY_BUILDERNAME}/${BUILDBOT_GOT_REVISION}"
146 NAME_ARM_TRY_UPLOAD() {
147 echo -n "${BUILDBOT_BUILDERNAME}/"
148 echo -n "${BUILDBOT_SLAVENAME}/"
149 echo -n "${BUILDBOT_BUILDNUMBER}"
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}"
160 \( -name '*.o' -o -name '*.bc' -o -name 'test_results' \) \
161 -print0 | xargs -0 rm -rf
164 # Tar up the executables which are shipped to the arm HW bots
165 archive-for-hw-bots() {
169 echo "@@@BUILD_STEP tar_generated_binaries@@@"
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*
177 echo "@@@BUILD_STEP archive_binaries@@@"
178 if [[ ${try} == "try" ]] ; then
179 ${UP_DOWN_LOAD} UploadArmBinariesForHWBotsTry ${name} arm-scons.tgz
181 ${UP_DOWN_LOAD} UploadArmBinariesForHWBots ${name} arm-scons.tgz
185 # Untar archived executables for HW bots
186 unarchive-for-hw-bots() {
190 echo "@@@BUILD_STEP fetch_binaries@@@"
191 if [[ ${try} == "try" ]] ; then
192 ${UP_DOWN_LOAD} DownloadArmBinariesForHWBotsTry ${name} arm-scons.tgz
194 ${UP_DOWN_LOAD} DownloadArmBinariesForHWBots ${name} arm-scons.tgz
197 echo "@@@BUILD_STEP untar_binaries@@@"
199 tar xvfz arm-scons.tgz --no-same-owner
202 # Build with gyp - this only exercises the trusted TC and hence this only
203 # makes sense to run for ARM.
205 local gypmode="Release"
206 if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
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.
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
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
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
234 echo "@@@BUILD_STEP gyp_configure [${gypmode}]@@@"
236 native_client/build/gyp_nacl native_client/build/all.gyp
239 echo "@@@BUILD_STEP gyp_compile [${gypmode}]@@@"
240 make -C .. -k -j8 V=1 BUILDTYPE=${gypmode}
243 build-sbtc-prerequisites() {
245 # Sandboxed translators currently only require irt_core since they do not
247 ${SCONS_COMMON} platform=${platform} sel_ldr sel_universal irt_core
250 # Run a single invocation of scons as its own buildbot stage and handle errors
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"
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
265 echo "@@@BUILD_STEP scons-irt [${platform}] [${test:0:100}] [${info}]@@@"
266 ${SCONS_COMMON} ${extra} ${mode} platform=${platform} ${test} || handle-error
269 # Run a single invocation of scons as its own buildbot stage and handle errors
270 scons-stage-noirt() {
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"
280 echo "@@@BUILD_STEP scons [${platform}] [${test}] [${info}]@@@"
281 ${SCONS_COMMON} ${extra} ${mode} platform=${platform} ${test} || handle-error
287 echo "@@@BUILD_STEP driver_tests ${arch}@@@"
288 ${DRIVER_TESTS} --platform="${arch}" || handle-error
292 # QEMU upload bot runs this function, and the hardware download bot runs
293 # mode-buildbot-arm-hw
294 mode-buildbot-arm() {
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="
305 scons-stage-noirt "arm" "-j8" "run_hello_world_test"
307 # Don't run the rest of the tests on qemu, only build them.
308 # QEMU is too flaky for the main waterfall
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"
319 # also run some tests with the irt
320 scons-stage-irt "arm" "${qemuflags}" "${SCONS_S_M_IRT}"
322 # non-pexe-mode tests
323 scons-stage-noirt "arm" "${qemuflags} pnacl_generate_pexe=0" "nonpexe_tests"
325 build-sbtc-prerequisites "arm"
327 scons-stage-irt "arm" \
328 "${qemuflags} use_sandboxed_translator=1 translate_in_build_step=0" \
330 scons-stage-irt "arm" \
331 "${qemuflags} use_sandboxed_translator=1 translate_fast=1 \
332 translate_in_build_step=0" \
336 scons-stage-irt "arm" "${qemuflags}" "${SCONS_NONSFI}"
339 mode-buildbot-arm-hw() {
341 local hwflags="-j2 -k naclsdk_validate=0 built_elsewhere=1"
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"
347 # also run some tests with the irt
348 scons-stage-irt "arm" "${hwflags}" "${SCONS_S_M_IRT}"
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" \
354 scons-stage-irt "arm" \
355 "${hwflags} use_sandboxed_translator=1 translate_fast=1 \
356 translate_in_build_step=0" \
360 scons-stage-irt "arm" "${hwflags}" "${SCONS_NONSFI}"
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.
368 local qemuflags="-j4 -k"
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"
376 # also run some tests with the irt
377 scons-stage-irt "arm" "${qemuflags}" "${SCONS_S_M_IRT}"
380 scons-stage-noirt "arm" "${qemuflags} pnacl_generate_pexe=0" "nonpexe_tests"
383 scons-stage-irt "arm" "${qemuflags}" "${SCONS_NONSFI}"
386 mode-buildbot-arm-dbg() {
387 BUILD_MODE_HOST=DEDUG
389 archive-for-hw-bots $(NAME_ARM_UPLOAD) regular
392 mode-buildbot-arm-opt() {
394 archive-for-hw-bots $(NAME_ARM_UPLOAD) regular
397 mode-buildbot-arm-try() {
399 archive-for-hw-bots $(NAME_ARM_TRY_UPLOAD) try
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
410 mode-buildbot-arm-hw-opt() {
411 unarchive-for-hw-bots $(NAME_ARM_DOWNLOAD) regular
415 mode-buildbot-arm-hw-try() {
416 unarchive-for-hw-bots $(NAME_ARM_TRY_DOWNLOAD) try
420 # These 2 functions are also suitable for local TC sanity testing.
424 local label="pnacl_newlib_dir=toolchain/${PNACL_TOOLCHAIN_DIR}"
425 local scons_flags="-k skip_trusted_tests=1 -j8 ${label}"
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" \
437 # Small set of sbtc tests w/ and without translate_fast=1.
438 scons-stage-irt "x86-32" "${scons_flags} use_sandboxed_translator=1" \
440 scons-stage-irt "x86-32" \
441 "${scons_flags} use_sandboxed_translator=1 translate_fast=1" \
443 scons-stage-irt "x86-64" "${scons_flags} use_sandboxed_translator=1" \
445 scons-stage-irt "x86-64" \
446 "${scons_flags} use_sandboxed_translator=1 translate_fast=1" \
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"
456 scons-stage-irt "x86-32" "${scons_flags}" "${SCONS_NONSFI_TC}"
457 scons-stage-irt "arm" "${scons_flags}" "${SCONS_NONSFI_TC}"
459 # Test unsandboxed mode.
460 scons-stage-irt "x86-32" "${scons_flags}" "pnacl_unsandboxed=1" \
461 "run_hello_world_test_irt"
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 @@@"
473 echo "@@@BUILD_STEP torture_tests x86-32 @@@"
474 tools/toolchain_tester/torture_test.py pnacl x86-32 --verbose \
475 --concurrency=8 || handle-error
480 local scons_flags="-k skip_trusted_tests=1"
482 driver-tests "${arch}"
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" \
491 mode-buildbot-tc-x8664-linux() {
494 export PNACL_TOOLCHAIN_DIR=linux_x86/pnacl_newlib
495 export PNACL_PRUNE=true
498 if ! ${is_try} ; then
499 tc-prune-translator-pexes
500 tc-archive-translator
502 HOST_ARCH=x86_64 tc-tests-all ${is_try}
505 mode-buildbot-tc-x8632-linux() {
508 export PNACL_TOOLCHAIN_DIR=linux_x86/pnacl_newlib
510 # For now, just use this bot to test a pure 32 bit build.
511 HOST_ARCH=x86_32 tc-tests-fast "x86-32"
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.
521 # Script assumed to be run in native_client/
522 if [[ $(pwd) != */native_client ]]; then
523 echo "ERROR: must be run in native_client!"
528 if [[ $# -eq 0 ]] ; then
529 echo "you must specify a mode on the commandline:"
533 if [ "$(type -t $1)" != "function" ]; then
535 echo "ERROR: unknown mode '$1'." >&2
541 if [[ ${RETCODE} != 0 ]]; then
542 echo "@@@BUILD_STEP summary@@@"
543 echo There were failed stages.