- add third_party src.
[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 # subset of tests used on toolchain builders
33 readonly SCONS_TC_TESTS="small_tests medium_tests"
34
35 readonly SCONS_COMMON="./scons --verbose bitcode=1"
36 readonly UP_DOWN_LOAD="buildbot/file_up_down_load.sh"
37 # This script is used by toolchain bots (i.e. tc-xxx functions)
38 readonly PNACL_BUILD="pnacl/build.sh"
39 readonly LLVM_TEST="pnacl/scripts/llvm-test.py"
40 readonly DRIVER_TESTS="pnacl/driver/tests/driver_tests.py"
41 readonly ACCEPTABLE_TOOLCHAIN_SIZE_MB=55
42
43 setup-goma() {
44   echo "@@@BUILD_STEP goma_setup@@@"
45   if /b/build/goma/goma_ctl.sh ensure_start ; then
46     PATH=/b/build/goma:$PATH
47     export PNACL_CONCURRENCY_HOST=100
48   else
49     # For now, don't make the bot go red if goma fails to start, just fall back
50     echo "@@@STEP_WARNINGS@@@"
51   fi
52 }
53
54 tc-clobber() {
55   local label=$1
56   local clobber_translators=$2
57
58   echo @@@BUILD_STEP tc_clobber@@@
59   rm -rf toolchain/${label}
60   rm -rf toolchain/test-log
61   rm -rf pnacl*.tgz pnacl/pnacl*.tgz
62   if ${clobber_translators} ; then
63       rm -rf toolchain/pnacl_translator
64   fi
65 }
66
67 tc-show-config() {
68   echo @@@BUILD_STEP show_config@@@
69   ${PNACL_BUILD} show-config
70 }
71
72 tc-compile-toolchain() {
73   local build_fat=$1
74   echo @@@BUILD_STEP compile_toolchain@@@
75   ${PNACL_BUILD} clean
76   ${PNACL_BUILD} sync-sources
77   ${PNACL_BUILD} checkout-git-bundles-for-trybot
78   if ${build_fat}; then
79     HOST_ARCH=x86_32 ${PNACL_BUILD} build-all
80     HOST_ARCH=x86_64 ${PNACL_BUILD} build-host
81     HOST_ARCH=x86_64 ${PNACL_BUILD} driver
82   else
83     ${PNACL_BUILD} build-all
84   fi
85   ${PNACL_BUILD} tarball pnacl-toolchain.tgz
86   chmod a+r pnacl-toolchain.tgz
87
88   # Size sanity check
89   local byte_size=$(wc -c < pnacl-toolchain.tgz)
90   local max_size=$((1024 * 1024 * ${ACCEPTABLE_TOOLCHAIN_SIZE_MB}))
91   if ${build_fat}; then
92     # Allow an extra 33% tarball size for fat toolchains
93     max_size=$((1024 * 1024 * ${ACCEPTABLE_TOOLCHAIN_SIZE_MB} * 4 / 3))
94   fi
95
96   if [[ ${byte_size} -gt ${max_size} ]] ; then
97       echo "ERROR: toolchain tarball is too large: ${byte_size} > ${max_size}"
98       handle-error
99   fi
100 }
101
102 tc-untar-toolchain() {
103   local label=$1
104   echo @@@BUILD_STEP untar_toolchain@@@
105   # Untar to ensure we can and to place the toolchain where the main build
106   # expects it to be.
107   rm -rf toolchain/${label}
108   mkdir -p toolchain/${label}
109   pushd toolchain/${label}
110   tar xfz ../../pnacl-toolchain.tgz
111   popd
112 }
113
114 tc-build-translator() {
115   echo @@@BUILD_STEP compile_translator@@@
116   ${PNACL_BUILD} translator-clean-all
117   ${PNACL_BUILD} translator-all
118 }
119
120 tc-archive() {
121   local label=$1
122   echo @@@BUILD_STEP archive_toolchain@@@
123   ${UP_DOWN_LOAD} UploadPnaclToolchains ${BUILDBOT_GOT_REVISION} \
124     ${label} pnacl-toolchain.tgz
125 }
126
127 tc-archive-translator-pexes() {
128   echo @@@BUILD_STEP archive_translator_pexe@@@
129   # NOTE: the build script needs an absolute pathname
130   local tarball="$(pwd)/pnacl-translator-pexe.tar.bz2"
131   ${PNACL_BUILD} translator-archive-pexes ${tarball}
132   ${UP_DOWN_LOAD} UploadArchivedPexesTranslator \
133       ${BUILDBOT_GOT_REVISION} ${tarball}
134 }
135
136 tc-prune-translator-pexes() {
137   echo @@@BUILD_STEP prune_translator_pexe@@@
138   ${PNACL_BUILD} translator-prune
139 }
140
141 tc-archive-translator() {
142   echo @@@BUILD_STEP archive_translator@@@
143   ${PNACL_BUILD} translator-tarball pnacl-translator.tgz
144   ${UP_DOWN_LOAD} UploadPnaclToolchains ${BUILDBOT_GOT_REVISION} \
145       pnacl_translator pnacl-translator.tgz
146 }
147
148 tc-build-all() {
149   local label=$1
150   local is_try=$2
151   local build_translator=$3
152
153   # Tell build.sh and test.sh that we're a bot.
154   export PNACL_BUILDBOT=true
155   # Tells build.sh to prune the install directory (for release).
156   export PNACL_PRUNE=true
157
158   clobber
159   tc-clobber ${label} ${build_translator}
160
161   # Run checkdeps so that the PNaCl toolchain trybots catch mistakes
162   # that would cause the normal NaCl bots to fail.
163   echo "@@@BUILD_STEP checkdeps @@@"
164   python tools/checkdeps/checkdeps.py
165
166   tc-show-config
167   # For now only linux64 (which also builds the translator) builds a fat
168   # toolchain, so just use build_translator to control fat toolchain build
169   tc-compile-toolchain ${build_translator}
170   tc-untar-toolchain ${label}
171   if ! ${is_try} ; then
172     tc-archive ${label}
173   fi
174
175   # NOTE: only one bot needs to do this
176   if ${build_translator} ; then
177     tc-build-translator
178     if ! ${is_try} ; then
179       tc-archive-translator-pexes
180       tc-prune-translator-pexes
181       tc-archive-translator
182     fi
183   fi
184
185 }
186
187
188 # extract the relevant scons flags for reporting
189 relevant() {
190   for i in "$@" ; do
191     case $i in
192       use_sandboxed_translator=1)
193         echo -n "sbtc "
194         ;;
195       do_not_run_tests=1)
196         echo -n "no_tests "
197         ;;
198       pnacl_generate_pexe=0)
199         echo -n "no_pexe "
200         ;;
201       translate_fast=1)
202         echo -n "fast "
203         ;;
204       --nacl_glibc)
205         echo -n "glibc "
206         ;;
207     esac
208   done
209 }
210
211 # called when a scons invocation fails
212 handle-error() {
213   RETCODE=1
214   echo "@@@STEP_FAILURE@@@"
215   if ${FAIL_FAST} ; then
216     echo "FAIL_FAST enabled"
217     exit 1
218   fi
219 }
220
221 # Clear out object, and temporary directories.
222 clobber() {
223   echo "@@@BUILD_STEP clobber@@@"
224   rm -rf scons-out ../xcodebuild ../out
225 }
226
227 # Generate filenames for arm bot uploads and downloads
228 NAME_ARM_UPLOAD() {
229   echo -n "${BUILDBOT_BUILDERNAME}/${BUILDBOT_GOT_REVISION}"
230 }
231
232 NAME_ARM_DOWNLOAD() {
233   echo -n "${BUILDBOT_TRIGGERED_BY_BUILDERNAME}/${BUILDBOT_GOT_REVISION}"
234 }
235
236 NAME_ARM_TRY_UPLOAD() {
237   echo -n "${BUILDBOT_BUILDERNAME}/"
238   echo -n "${BUILDBOT_SLAVENAME}/"
239   echo -n "${BUILDBOT_BUILDNUMBER}"
240 }
241 NAME_ARM_TRY_DOWNLOAD() {
242   echo -n "${BUILDBOT_TRIGGERED_BY_BUILDERNAME}/"
243   echo -n "${BUILDBOT_TRIGGERED_BY_SLAVENAME}/"
244   echo -n "${BUILDBOT_TRIGGERED_BY_BUILDNUMBER}"
245 }
246
247
248 prune-scons-out() {
249   find scons-out/ \
250     \( -name '*.o' -o -name '*.bc' -o -name 'test_results' \) \
251     -print0 | xargs -0 rm -rf
252 }
253
254 # Tar up the executables which are shipped to the arm HW bots
255 archive-for-hw-bots() {
256   local name=$1
257   local try=$2
258
259   echo "@@@BUILD_STEP tar_generated_binaries@@@"
260   prune-scons-out
261
262   # delete nexes from pexe mode directories to force translation
263   # TODO(dschuff) enable this once we can translate on the hw bots
264   #find scons-out/*pexe*/ -name '*.nexe' -print0 | xargs -0 rm -f
265   tar cvfz arm-scons.tgz scons-out/*arm*
266
267   echo "@@@BUILD_STEP archive_binaries@@@"
268   if [[ ${try} == "try" ]] ; then
269     ${UP_DOWN_LOAD} UploadArmBinariesForHWBotsTry ${name} arm-scons.tgz
270   else
271     ${UP_DOWN_LOAD} UploadArmBinariesForHWBots ${name} arm-scons.tgz
272   fi
273 }
274
275 # Untar archived executables for HW bots
276 unarchive-for-hw-bots() {
277   local name=$1
278   local try=$2
279
280   echo "@@@BUILD_STEP fetch_binaries@@@"
281   if [[ ${try} == "try" ]] ; then
282     ${UP_DOWN_LOAD} DownloadArmBinariesForHWBotsTry ${name} arm-scons.tgz
283   else
284     ${UP_DOWN_LOAD} DownloadArmBinariesForHWBots ${name} arm-scons.tgz
285   fi
286
287   echo "@@@BUILD_STEP untar_binaries@@@"
288   rm -rf scons-out/
289   tar xvfz arm-scons.tgz --no-same-owner
290 }
291
292 # Build with gyp - this only exercises the trusted TC and hence this only
293 # makes sense to run for ARM.
294 gyp-arm-build() {
295   local gypmode="Release"
296   if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
297       gypmode="Debug"
298   fi
299   local toolchain_dir=native_client/toolchain/linux_arm-trusted
300   local extra="-isystem ${toolchain_dir}/usr/include \
301                -Wl,-rpath-link=${toolchain_dir}/lib/arm-linux-gnueabi \
302                -L${toolchain_dir}/lib \
303                -L${toolchain_dir}/lib/arm-linux-gnueabi \
304                -L${toolchain_dir}/usr/lib \
305                -L${toolchain_dir}/usr/lib/arm-linux-gnueabi"
306   # Setup environment for arm.
307
308   export AR=arm-linux-gnueabi-ar
309   export AS=arm-linux-gnueabi-as
310   export CC="arm-linux-gnueabi-gcc-4.5 ${extra} "
311   export CXX="arm-linux-gnueabi-g++-4.5 ${extra} "
312   export LD="arm-linux-gnueabi-g++-4.5 ${extra} "
313   export RANLIB=arm-linux-gnueabi-ranlib
314   export SYSROOT
315   export GYP_DEFINES="target_arch=arm \
316     sysroot=${toolchain_dir} \
317     linux_use_tcmalloc=0 armv7=1 arm_thumb=1"
318   export GYP_GENERATORS=make
319
320   # NOTE: this step is also run implicitly as part of
321   #        gclient runhooks --force
322   #       it uses the exported env vars so we have to run it again
323   #
324   echo "@@@BUILD_STEP gyp_configure [${gypmode}]@@@"
325   cd ..
326   native_client/build/gyp_nacl native_client/build/all.gyp
327   cd native_client
328
329   echo "@@@BUILD_STEP gyp_compile [${gypmode}]@@@"
330   make -C .. -k -j8 V=1 BUILDTYPE=${gypmode}
331 }
332
333 build-sbtc-prerequisites() {
334   local platform=$1
335   # Sandboxed translators currently only require irt_core since they do not
336   # use PPAPI.
337   ${SCONS_COMMON} platform=${platform} sel_ldr sel_universal irt_core
338 }
339
340 # Run a single invocation of scons as its own buildbot stage and handle errors
341 scons-stage-irt() {
342   local platform=$1
343   local extra=$2
344   local test=$3
345   local info="$(relevant ${extra})"
346   # TODO(robertm): do we really need both nacl and nacl_irt_test
347   local mode="--mode=opt-host,nacl,nacl_irt_test"
348   if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
349       mode="--mode=dbg-host,nacl,nacl_irt_test"
350   fi
351
352   echo "@@@BUILD_STEP scons-irt [${platform}] [${test}] [${info}]@@@"
353   ${SCONS_COMMON} ${extra} ${mode} platform=${platform} ${test} || handle-error
354 }
355
356 # Run a single invocation of scons as its own buildbot stage and handle errors
357 scons-stage-noirt() {
358   local platform=$1
359   local extra=$2
360   local test=$3
361   local info="$(relevant ${extra})"
362   local mode="--mode=opt-host,nacl"
363   if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
364       mode="--mode=dbg-host,nacl"
365   fi
366
367   echo "@@@BUILD_STEP scons [${platform}] [${test}] [${info}]@@@"
368   ${SCONS_COMMON} ${extra} ${mode} platform=${platform} ${test} || handle-error
369 }
370
371 llvm-regression() {
372   echo "@@@BUILD_STEP llvm_regression@@@"
373   ${LLVM_TEST} --llvm-regression --check-excludes || handle-error
374 }
375
376 # This function is shared between x86-32 and x86-64. All building and testing
377 # is done on the same bot. Try runs are identical to buildbot runs
378 #
379 # Note: unlike its arm counterparts we do not run trusted tests on these bots.
380 # Trusted tests get plenty of coverage by other bots, e.g. nacl-gcc bots.
381 # We make the assumption here that there are no "exotic tests" which
382 # are trusted in nature but are somehow depedent on the untrusted TC.
383 mode-buildbot-x86() {
384   local arch="x86-$1"
385   FAIL_FAST=false
386   clobber
387
388   local flags_build="skip_trusted_tests=1 -k -j8 do_not_run_tests=1"
389   local flags_run="skip_trusted_tests=1 -k -j4"
390   # Normal pexe tests. Build all targets, then run (-j4 is a compromise to try
391   # to reduce cycle times without making output too difficult to follow)
392   # We also intentionally build more than we run for "coverage".
393   # specifying "" as the target which means "build everything"
394
395   scons-stage-noirt "${arch}" "${flags_build}" "${SCONS_EVERYTHING}"
396   scons-stage-noirt "${arch}" "${flags_run}"   "${SCONS_S_M}"
397   # Large tests cannot be run in parallel
398   scons-stage-noirt "${arch}" "${flags_run} -j1"  "large_tests"
399
400   # non-pexe tests (Do the build-everything step just to make sure it all still
401   # builds as non-pexe)
402   scons-stage-noirt "${arch}" "${flags_build} pnacl_generate_pexe=0" \
403       "${SCONS_EVERYTHING}"
404   scons-stage-noirt "${arch}" "${flags_run} pnacl_generate_pexe=0" \
405       "nonpexe_tests"
406
407   # also run some tests with the irt
408   scons-stage-irt "${arch}" "${flags_run}" "${SCONS_S_M_IRT}"
409
410   # sandboxed translation
411   build-sbtc-prerequisites ${arch}
412   scons-stage-irt "${arch}" "${flags_build} use_sandboxed_translator=1" \
413     "${SCONS_EVERYTHING}"
414   scons-stage-irt "${arch}" "${flags_run} use_sandboxed_translator=1" \
415     "${SCONS_S_M_IRT}"
416   scons-stage-irt "${arch}" \
417     "${flags_run} use_sandboxed_translator=1 translate_fast=1" \
418     "toolchain_tests"
419
420   # translator memory consumption regression test
421   scons-stage-irt "${arch}" "${flags_run} use_sandboxed_translator=1" \
422       "large_code"
423 }
424
425 # QEMU upload bot runs this function, and the hardware download bot runs
426 # mode-buildbot-arm-hw
427 mode-buildbot-arm() {
428   FAIL_FAST=false
429   # "force_emulator=" disables use of QEMU, which enables building
430   # tests which don't work under QEMU.
431   local qemuflags="-j8 -k do_not_run_tests=1 force_emulator="
432
433   clobber
434
435   gyp-arm-build
436
437   # Sanity check
438   scons-stage-noirt "arm" "-j8" "run_hello_world_test"
439
440   # Don't run the rest of the tests on qemu, only build them.
441   # QEMU is too flaky for the main waterfall
442
443   # Normal pexe mode tests
444   scons-stage-noirt "arm" "${qemuflags}" "${SCONS_EVERYTHING}"
445   # This extra step is required to translate the pexes (because translation
446   # happens as part of CommandSelLdrTestNacl and not part of the
447   # build-everything step)
448   scons-stage-noirt "arm" "${qemuflags}" "${SCONS_S_M}"
449   # Large tests cannot be run in parallel
450   scons-stage-noirt "arm" "${qemuflags} -j1" "large_tests"
451
452   # also run some tests with the irt
453   scons-stage-irt "arm" "${qemuflags}" "${SCONS_S_M_IRT}"
454
455   # non-pexe-mode tests
456   scons-stage-noirt "arm" "${qemuflags} pnacl_generate_pexe=0" "nonpexe_tests"
457
458   build-sbtc-prerequisites "arm"
459
460   scons-stage-irt "arm" \
461     "${qemuflags} use_sandboxed_translator=1 translate_in_build_step=0" \
462     "toolchain_tests"
463   scons-stage-irt "arm" \
464     "${qemuflags} use_sandboxed_translator=1 translate_fast=1 \
465        translate_in_build_step=0" \
466     "toolchain_tests"
467 }
468
469 mode-buildbot-arm-hw() {
470   FAIL_FAST=false
471   local hwflags="-j2 -k naclsdk_validate=0 built_elsewhere=1"
472
473   scons-stage-noirt "arm" "${hwflags}" "${SCONS_S_M}"
474   # Large tests cannot be run in parallel
475   scons-stage-noirt "arm" "${hwflags} -j1" "large_tests"
476
477   # also run some tests with the irt
478   scons-stage-irt "arm" "${hwflags}" "${SCONS_S_M_IRT}"
479
480   scons-stage-noirt "arm" "${hwflags} pnacl_generate_pexe=0" "nonpexe_tests"
481   scons-stage-irt "arm" \
482     "${hwflags} use_sandboxed_translator=1 translate_in_build_step=0" \
483     "toolchain_tests"
484   scons-stage-irt "arm" \
485     "${hwflags} use_sandboxed_translator=1 translate_fast=1 \
486        translate_in_build_step=0" \
487     "toolchain_tests"
488 }
489
490 mode-trybot-qemu() {
491   # Build and actually run the arm tests under qemu, except
492   # sandboxed translation. Hopefully that's a good tradeoff between
493   # flakiness and cycle time.
494   FAIL_FAST=false
495   local qemuflags="-j4 -k"
496   clobber
497   gyp-arm-build
498
499   scons-stage-noirt "arm" "${qemuflags}" "${SCONS_EVERYTHING}"
500   # Large tests cannot be run in parallel
501   scons-stage-noirt "arm" "${qemuflags} -j1" "${SCONS_S_M} large_tests"
502
503   # also run some tests with the irt
504   scons-stage-irt "arm" "${qemuflags}" "${SCONS_S_M_IRT}"
505
506   # non-pexe tests
507   scons-stage-noirt "arm" "${qemuflags} pnacl_generate_pexe=0" "nonpexe_tests"
508 }
509
510 mode-buildbot-arm-dbg() {
511   BUILD_MODE_HOST=DEDUG
512   mode-buildbot-arm
513   archive-for-hw-bots $(NAME_ARM_UPLOAD) regular
514 }
515
516 mode-buildbot-arm-opt() {
517   mode-buildbot-arm
518   archive-for-hw-bots $(NAME_ARM_UPLOAD) regular
519 }
520
521 mode-buildbot-arm-try() {
522   mode-buildbot-arm
523   archive-for-hw-bots $(NAME_ARM_TRY_UPLOAD) try
524 }
525
526 # NOTE: the hw bots are too slow to build stuff on so we just
527 #       use pre-built executables
528 mode-buildbot-arm-hw-dbg() {
529   BUILD_MODE_HOST=DEDUG
530   unarchive-for-hw-bots $(NAME_ARM_DOWNLOAD)  regular
531   mode-buildbot-arm-hw
532 }
533
534 mode-buildbot-arm-hw-opt() {
535   unarchive-for-hw-bots $(NAME_ARM_DOWNLOAD)  regular
536   mode-buildbot-arm-hw
537 }
538
539 mode-buildbot-arm-hw-try() {
540   unarchive-for-hw-bots $(NAME_ARM_TRY_DOWNLOAD)  try
541   mode-buildbot-arm-hw
542 }
543
544 # These 2 functions are also suitable for local TC sanity testing.
545 tc-tests-all() {
546   local is_try=$1
547
548   local label="pnaclsdk_mode=custom:toolchain/${PNACL_TOOLCHAIN_LABEL}"
549   local scons_flags="-k skip_trusted_tests=1 -j8 ${label}"
550
551   llvm-regression
552
553   # newlib
554   for arch in x86-32 x86-64 arm; do
555     ${DRIVER_TESTS} --platform="$arch"
556     scons-stage-noirt "$arch" "${scons_flags}" "${SCONS_TC_TESTS}"
557     # Large tests cannot be run in parallel
558     scons-stage-noirt "$arch" "${scons_flags} -j1" "large_tests"
559     scons-stage-noirt "$arch" "${scons_flags} pnacl_generate_pexe=0" \
560         "nonpexe_tests"
561   done
562
563   # Small set of sbtc tests w/ and without translate_fast=1.
564   scons-stage-irt "x86-32" "${scons_flags} use_sandboxed_translator=1" \
565     "toolchain_tests"
566   scons-stage-irt "x86-32" \
567     "${scons_flags} use_sandboxed_translator=1 translate_fast=1" \
568     "toolchain_tests"
569   scons-stage-irt "x86-64" "${scons_flags} use_sandboxed_translator=1" \
570     "toolchain_tests"
571   scons-stage-irt "x86-64" \
572     "${scons_flags} use_sandboxed_translator=1 translate_fast=1" \
573     "toolchain_tests"
574   # Smaller set of sbtc tests for ARM because qemu is flaky.
575   scons-stage-irt "arm" "${scons_flags} use_sandboxed_translator=1" \
576     "run_hello_world_test"
577   scons-stage-irt "arm" \
578     "${scons_flags} use_sandboxed_translator=1 translate_fast=1" \
579     "run_hello_world_test"
580
581   # Run the GCC torture tests just for x86-32.  Testing a single
582   # architecture gives good coverage without taking too long.  We
583   # don't test x86-64 here because some of the torture tests fail on
584   # the x86-64 toolchain trybot (though not the buildbots, apparently
585   # due to a hardware difference:
586   # https://code.google.com/p/nativeclient/issues/detail?id=3697).
587   echo "@@@BUILD_STEP torture_tests x86-32 @@@"
588   tools/toolchain_tester/torture_test.py pnacl x86-32 --verbose \
589       --concurrency=8 || handle-error
590 }
591
592 tc-tests-fast() {
593   local arch="$1"
594   local scons_flags="-j8 -k skip_trusted_tests=1"
595
596   llvm-regression
597   ${DRIVER_TESTS} --platform="$arch"
598
599   scons-stage-noirt "${arch}" "${scons_flags}" "${SCONS_TC_TESTS}"
600   # Large tests cannot be run in parallel
601   scons-stage-noirt "${arch}" "-j1 -k skip_trusted_tests=1" "large_tests"
602   scons-stage-noirt "${arch}" "${scons_flags} pnacl_generate_pexe=0" \
603     "nonpexe_tests"
604 }
605
606 mode-buildbot-tc-x8664-linux() {
607   setup-goma
608   local is_try=$1
609   FAIL_FAST=false
610   export PNACL_TOOLCHAIN_LABEL=pnacl_linux_x86
611   tc-build-all ${PNACL_TOOLCHAIN_LABEL} ${is_try} true
612   tc-tests-all ${is_try}
613 }
614
615 mode-buildbot-tc-x8632-linux() {
616   setup-goma
617   local is_try=$1
618   FAIL_FAST=false
619   export PNACL_TOOLCHAIN_LABEL=pnacl_linux_x86
620   # For now, just use this bot to test a pure 32 bit build but don't upload
621   tc-build-all ${PNACL_TOOLCHAIN_LABEL} true false
622   tc-tests-fast "x86-32"
623
624   echo "@@@BUILD_STEP test unsandboxed mode@@@"
625   # Test translation to an unsandboxed executable.
626   # TODO(mseaborn): Run more tests here when they pass.
627   ./scons bitcode=1 pnacl_unsandboxed=1 \
628     --mode=nacl_irt_test platform=x86-32 -j8 \
629     run_hello_world_test_irt \
630     run_irt_futex_test_irt \
631     run_thread_test_irt \
632     run_float_test_irt \
633     run_malloc_realloc_calloc_free_test_irt \
634     run_dup_test_irt \
635     run_cond_timedwait_test_irt
636 }
637
638 mode-buildbot-tc-x8632-mac() {
639   local is_try=$1
640   FAIL_FAST=false
641   export PNACL_TOOLCHAIN_LABEL=pnacl_mac_x86
642   # We can't test ARM because we do not have QEMU for Mac.
643   # We can't test X86-64 because NaCl X86-64 Mac support is not in good shape.
644   tc-build-all ${PNACL_TOOLCHAIN_LABEL} ${is_try} false
645   tc-tests-fast "x86-32"
646 }
647
648 mode-buildbot-tc-x8664-win() {
649   local is_try=$1
650   FAIL_FAST=false
651   # NOTE: this is a 64bit bot but the TC generated is 32bit
652   export PNACL_TOOLCHAIN_LABEL=pnacl_win_x86
653   tc-build-all ${PNACL_TOOLCHAIN_LABEL} ${is_try} false
654
655   # We can't test ARM because we do not have QEMU for Win.
656   tc-tests-fast "x86-64"
657 }
658
659
660
661 mode-test-all() {
662   test-all-newlib "$@"
663   test-all-glibc "$@"
664 }
665
666 # NOTE: clobber and toolchain setup to be done manually, since this is for
667 # testing a locally built toolchain.
668 # This runs tests concurrently, so may be more difficult to parse logs.
669 test-all-newlib() {
670   local concur=$1
671
672   # turn verbose mode off
673   set +o xtrace
674
675   llvm-regression
676   ${DRIVER_TESTS} --platform=x86-32
677   ${DRIVER_TESTS} --platform=x86-64
678   ${DRIVER_TESTS} --platform=arm
679
680   # At least clobber scons-out before building and running the tests though.
681   echo "@@@BUILD_STEP clobber@@@"
682   rm -rf scons-out
683
684   # First build everything.
685   echo "@@@BUILD_STEP scons build @@@"
686   local scons_flags="skip_trusted_tests=1 -j${concur}"
687   scons-stage-noirt "arm"    "${scons_flags}" "${SCONS_EVERYTHING}"
688   scons-stage-noirt "x86-32" "${scons_flags}" "${SCONS_EVERYTHING}"
689   scons-stage-noirt "x86-64" "${scons_flags}" "${SCONS_EVERYTHING}"
690   # Then run the tests. smoke_tests can be run in parallel but not large_tests
691   echo "@@@BUILD_STEP scons smoke_tests @@@"
692   scons-stage-noirt "arm"    "${scons_flags}" "smoke_tests"
693   scons-stage-noirt "arm"    "${scons_flags} -j1" "large_tests"
694   scons-stage-noirt "x86-32" "${scons_flags}" "smoke_tests"
695   scons-stage-noirt "x86-32"    "${scons_flags} -j1" "large_tests"
696   scons-stage-noirt "x86-64" "${scons_flags}" "smoke_tests"
697   scons-stage-noirt "x86-64"    "${scons_flags} -j1" "large_tests"
698   # Do some sandboxed translator tests as well.
699   scons-stage-irt "x86-32" "${scons_flags} use_sandboxed_translator=1" \
700     "toolchain_tests"
701   scons-stage-irt "x86-32" \
702     "${scons_flags} use_sandboxed_translator=1 translate_fast=1" \
703     "toolchain_tests"
704   scons-stage-irt "x86-64" "${scons_flags} use_sandboxed_translator=1" \
705     "toolchain_tests"
706   scons-stage-irt "x86-64" \
707     "${scons_flags} use_sandboxed_translator=1 translate_fast=1" \
708     "toolchain_tests"
709   # Smaller set of sbtc tests for ARM because qemu is flaky.
710   scons-stage-irt "arm" "${scons_flags} use_sandboxed_translator=1" \
711     "run_hello_world_test"
712   scons-stage-irt "arm" \
713     "${scons_flags} use_sandboxed_translator=1 translate_fast=1" \
714     "run_hello_world_test"
715 }
716
717 test-all-glibc() {
718   echo "TODO(pdox): Add GlibC tests"
719 }
720
721 ######################################################################
722 # On Windows, this script is invoked from a batch file.
723 # The inherited PWD environmental variable is a Windows-style path.
724 # This can cause problems with pwd and bash. This line fixes it.
725 cd -P .
726
727 # Script assumed to be run in native_client/
728 if [[ $(pwd) != */native_client ]]; then
729   echo "ERROR: must be run in native_client!"
730   exit 1
731 fi
732
733
734 if [[ $# -eq 0 ]] ; then
735   echo "you must specify a mode on the commandline:"
736   exit 1
737 fi
738
739 if [ "$(type -t $1)" != "function" ]; then
740   Usage
741   echo "ERROR: unknown mode '$1'." >&2
742   exit 1
743 fi
744
745 "$@"
746
747 if [[ ${RETCODE} != 0 ]]; then
748   echo "@@@BUILD_STEP summary@@@"
749   echo There were failed stages.
750   exit ${RETCODE}
751 fi