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.
6 # Run toolchain torture tests and llvm testsuite tests.
7 # For now, run on linux64, build and run unsandboxed newlib tests
8 # for all 3 architectures.
9 # Note: This script builds the toolchain from scratch but does
10 # not build the translators and hence the translators
11 # are from an older revision, see comment below.
18 # The pexes which are referred to below, and the pexes generated by the
19 # archived frontend below will be translated with translators from DEPS.
20 # The motivation is to ensure that newer translators can still handle
23 # This hopefully needs to be updated rarely, it contains pexe from
24 # the sandboxed llc/gold builds
25 ARCHIVED_PEXE_TRANSLATOR_REV=12177
27 # The frontend from this rev will generate pexes for the archived frontend
28 # test. The toolchain downloader expects this information in a specially
29 # formatted file. We generate that file in this script from this information,
30 # to keep all our versions in one place
31 ARCHIVED_TOOLCHAIN_REV=12276
33 readonly PNACL_BUILD="pnacl/build.sh"
34 readonly UP_DOWN_LOAD="buildbot/file_up_down_load.sh"
35 readonly TORTURE_TEST="tools/toolchain_tester/torture_test.py"
36 readonly LLVM_TESTSUITE="pnacl/scripts/llvm-test.py"
38 # build.sh, llvm test suite and torture tests all use this value
39 export PNACL_CONCURRENCY=${PNACL_CONCURRENCY:-4}
41 # Change the toolchain build script (PNACL_BUILD) behavior slightly
42 # wrt to error logging and mecurial retry delays.
43 # TODO(robertm): if this special casing is still needed,
44 # make this into separate vars
45 export PNACL_BUILDBOT=true
46 # Make the toolchain build script (PNACL_BUILD) more verbose.
47 # This will also prevent bot timeouts which otherwise gets triggered
48 # by long periods without console output.
49 export PNACL_VERBOSE=true
51 # For now this script runs on linux x86-64.
52 # It is possible to force the PNACL_BUILD to build host binaries with "-m32",
53 # by uncommenting below:
54 # export BUILD_ARCH="x86_32"
55 # export HOST_ARCH="x86_32"
56 # TODO(pnacl-team): Figure out what to do about this.
57 # Export this so that the test scripts know where to find the toolchain.
58 export PNACL_TOOLCHAIN_LABEL=pnacl_linux_x86
59 # This picks the TC which we just built, even if scons doesn't know
60 # how to find a 64-bit host toolchain.
61 readonly SCONS_PICK_TC="pnaclsdk_mode=custom:toolchain/${PNACL_TOOLCHAIN_LABEL}"
64 # Download the archived frontend toolchain, if we haven't already
68 if [[ -f "${dst}/${ARCHIVED_TOOLCHAIN_REV}.stamp" ]]; then
69 echo "Using existing tarball for archived frontend"
73 ${UP_DOWN_LOAD} DownloadPnaclToolchains ${ARCHIVED_TOOLCHAIN_REV} \
74 ${PNACL_TOOLCHAIN_LABEL} \
75 ${dst}/${PNACL_TOOLCHAIN_LABEL}.tgz
76 mkdir -p ${dst}/${PNACL_TOOLCHAIN_LABEL}
77 tar xz -C ${dst}/${PNACL_TOOLCHAIN_LABEL} \
78 -f ${dst}/${PNACL_TOOLCHAIN_LABEL}.tgz
79 touch "${dst}/${ARCHIVED_TOOLCHAIN_REV}.stamp"
85 echo @@@BUILD_STEP clobber@@@
87 # Don't clobber toolchain/pnacl_translator; these bots currently don't build
88 # it, but they use the DEPSed-in version.
89 rm -rf toolchain/pnacl_linux* toolchain/pnacl_mac* toolchain/pnacl_win*
93 echo "@@@STEP_FAILURE@@@"
97 echo "@== IGNORING AN ERROR ==@"
100 #### Support for running arm sbtc tests on this bot, since we have
101 # less coverage on the main waterfall now:
102 # http://code.google.com/p/nativeclient/issues/detail?id=2581
103 readonly SCONS_COMMON="./scons --verbose bitcode=1 -j${PNACL_CONCURRENCY}"
104 readonly SCONS_COMMON_SLOW="./scons --verbose bitcode=1 -j2"
106 build-sbtc-prerequisites() {
108 ${SCONS_COMMON} ${SCONS_PICK_TC} platform=${platform} \
109 sel_ldr sel_universal irt_core
113 scons-tests-translator() {
116 echo "@@@BUILD_STEP scons-sb-trans [${platform}] [prereq]@@@"
117 build-sbtc-prerequisites ${platform}
119 local flags="--mode=opt-host,nacl use_sandboxed_translator=1 \
120 platform=${platform} -k"
121 local targets="small_tests medium_tests large_tests"
123 # ROUND 1: regular builds
124 # generate pexes with full parallelism
125 echo "@@@BUILD_STEP scons-sb-trans-pexe [${platform}] [${targets}]@@@"
126 ${SCONS_COMMON} ${SCONS_PICK_TC} ${flags} ${targets} \
127 translate_in_build_step=0 do_not_run_tests=1 || handle-error
130 echo "@@@BUILD_STEP scons-sb-trans-trans [${platform}] [${targets}]@@@"
131 if [[ ${platform} = arm ]] ; then
132 # For ARM we use less parallelism to avoid mysterious QEMU crashes.
133 # We also force a timeout for translation only.
134 export QEMU_PREFIX_HOOK="timeout 120"
135 # Run sb translation twice in case we failed to translate some of the
136 # pexes. If there was an error in the first run this shouldn't
137 # trigger a buildbot error. Only the second run can make the bot red.
138 ${SCONS_COMMON_SLOW} ${SCONS_PICK_TC} ${flags} ${targets} \
139 do_not_run_tests=1 || ignore-error
140 ${SCONS_COMMON_SLOW} ${SCONS_PICK_TC} ${flags} ${targets} \
141 do_not_run_tests=1 || handle-error
142 # Do not use the prefix hook for running actual tests as
143 # it will break some of them due to exit code sign inversion.
144 unset QEMU_PREFIX_HOOK
146 ${SCONS_COMMON} ${SCONS_PICK_TC} ${flags} ${targets} \
147 do_not_run_tests=1 || handle-error
149 # finally run the tests
150 echo "@@@BUILD_STEP scons-sb-trans-run [${platform}] [${targets}]@@@"
151 ${SCONS_COMMON_SLOW} ${SCONS_PICK_TC} ${flags} ${targets} || handle-error
153 # ROUND 2: builds with "fast translation"
154 flags="${flags} translate_fast=1"
155 echo "@@@BUILD_STEP scons-sb-trans-pexe [fast] [${platform}] [${targets}]@@@"
156 ${SCONS_COMMON} ${SCONS_PICK_TC} ${flags} ${targets} \
157 translate_in_build_step=0 do_not_run_tests=1 || handle-error
159 echo "@@@BUILD_STEP scons-sb-trans-trans [fast] [${platform}] [${targets}]@@@"
160 if [[ ${platform} = arm ]] ; then
161 # For ARM we use less parallelism to avoid mysterious QEMU crashes.
162 # We also force a timeout for translation only.
163 export QEMU_PREFIX_HOOK="timeout 120"
164 # Run sb translation twice in case we failed to translate some of the
165 # pexes. If there was an error in the first run this shouldn't
166 # trigger a buildbot error. Only the second run can make the bot red.
167 ${SCONS_COMMON_SLOW} ${SCONS_PICK_TC} ${flags} ${targets} \
168 do_not_run_tests=1 || ignore-error
169 ${SCONS_COMMON_SLOW} ${SCONS_PICK_TC} ${flags} ${targets} \
170 do_not_run_tests=1 || handle-error
171 # Do not use the prefix hook for running actual tests as
172 # it will break some of them due to exit code sign inversion.
173 unset QEMU_PREFIX_HOOK
175 ${SCONS_COMMON} ${SCONS_PICK_TC} ${flags} ${targets} \
176 do_not_run_tests=1 || handle-error
178 echo "@@@BUILD_STEP scons-sb-trans-run [fast] [${platform}] [${targets}]@@@"
179 ${SCONS_COMMON_SLOW} ${SCONS_PICK_TC} ${flags} ${targets} || handle-error
182 scons-tests-x86-64-zero-based-sandbox() {
183 echo "@@@BUILD_STEP hello_world (x86-64 zero-based sandbox)@@@"
184 local flags="--mode=opt-host,nacl platform=x86-64 \
185 x86_64_zero_based_sandbox=1"
186 ${SCONS_COMMON} ${SCONS_PICK_TC} ${flags} "run_hello_world_test"
189 # This test is a bitcode stability test, which builds pexes for all the tests
190 # using an old version of the toolchain frontend, and then translates those
191 # pexes using the current version of the translator. It's simpler than using
192 # archived pexes, because archived pexes for old scons tests may not match the
193 # current scons tests (e.g. if the expected output changes or if a new test
194 # is added). The only thing that would break this approach is if a new test
195 # is added that is incompatible with the old frontend. For this case there
196 # simply needs to be a mechanism to disable that test (which could be as simple
197 # as using disable_tests here on the scons command line).
198 # Note: If this test is manually interrupted or killed during the run, the
199 # toolchain install might end up missing or replaced with the old one.
200 # To fix, copy the current one from toolchains/current_tc or blow it away
201 # and re-run gclient runhooks.
202 archived-frontend-test() {
204 # Build the IRT with the latest toolchain before building user
205 # pexes with the archived toolchain.
206 echo "@@@BUILD_STEP archived_frontend [${arch}]\
207 rev ${ARCHIVED_TOOLCHAIN_REV} BUILD IRT@@@"
208 ${SCONS_COMMON} ${SCONS_PICK_TC} --mode=opt-host,nacl platform=${arch} \
209 irt_core || handle-error
212 echo "@@@BUILD_STEP archived_frontend [${arch}]\
213 rev ${ARCHIVED_TOOLCHAIN_REV} BUILD@@@"
214 local targets="small_tests medium_tests large_tests"
215 local flags="--mode=opt-host,nacl platform=${arch} \
216 translate_in_build_step=0 skip_trusted_tests=1 \
217 skip_nonstable_bitcode=1"
219 rm -rf scons-out/nacl-${arch}*
221 # Get the archived frontend.
222 # If the correct cached frontend is in place, the hash will match and the
223 # download will be a no-op. Otherwise the downloader will fix it.
224 download-old-tc toolchain/archived_tc
226 # Save the current toolchain.
227 mkdir -p toolchain/current_tc
228 rm -rf toolchain/current_tc/*
229 mv toolchain/${PNACL_TOOLCHAIN_LABEL} \
230 toolchain/current_tc/${PNACL_TOOLCHAIN_LABEL}
232 # Link the old frontend into place. If we just use pnaclsdk_mode to select a
233 # different toolchain, SCons will attempt to rebuild the IRT.
234 ln -s archived_tc/${PNACL_TOOLCHAIN_LABEL} toolchain/${PNACL_TOOLCHAIN_LABEL}
236 # Build the pexes with the old frontend.
237 ${SCONS_COMMON} ${SCONS_PICK_TC} \
238 do_not_run_tests=1 ${flags} ${targets} || handle-error
240 # Put the current toolchain back in place.
241 rm toolchain/${PNACL_TOOLCHAIN_LABEL}
242 mv toolchain/current_tc/${PNACL_TOOLCHAIN_LABEL} \
243 toolchain/${PNACL_TOOLCHAIN_LABEL}
245 # Translate them with the new translator, and run the tests.
246 # Use the sandboxed translator, which runs the newer ABI verifier
247 # (building w/ the old frontend only runs the old ABI verifier).
248 flags="${flags} use_sandboxed_translator=1"
249 # The pexes for sandboxed and fast translation tests are identical but scons
250 # uses a different directory.
251 local pexe_dir="scons-out/nacl-${arch}-pnacl-pexe-clang"
252 cp -a ${pexe_dir} "scons-out/nacl-${arch}-pnacl-sbtc-pexe-clang"
253 cp -a ${pexe_dir} "scons-out/nacl-${arch}-pnacl-fast-sbtc-pexe-clang"
255 echo "@@@BUILD_STEP archived_frontend [${arch}]\
256 rev ${ARCHIVED_TOOLCHAIN_REV} RUN@@@"
257 # For QEMU limit parallelism to avoid flake.
258 if [[ ${arch} = arm ]] ; then
259 ${SCONS_COMMON_SLOW} ${SCONS_PICK_TC} \
260 ${flags} ${targets} built_elsewhere=1 || handle-error
261 # Also test the fast-translation option
262 echo "@@@BUILD_STEP archived_frontend [${arch} translate-fast]\
263 rev ${ARCHIVED_TOOLCHAIN_REV} RUN@@@"
264 ${SCONS_COMMON_SLOW} ${SCONS_PICK_TC} ${flags} translate_fast=1 \
265 built_elsewhere=1 ${targets} || handle-error
267 ${SCONS_COMMON} ${SCONS_PICK_TC} \
268 ${flags} ${targets} built_elsewhere=1 || handle-error
269 # Also test the fast-translation option
270 echo "@@@BUILD_STEP archived_frontend [${arch} translate-fast]\
271 rev ${ARCHIVED_TOOLCHAIN_REV} RUN@@@"
272 ${SCONS_COMMON} ${SCONS_PICK_TC} ${flags} translate_fast=1 \
273 built_elsewhere=1 ${targets} || handle-error
277 archived-pexe-translator-test() {
279 echo "@@@BUILD_STEP archived_pexe_translator \
280 $arch rev ${ARCHIVED_PEXE_TRANSLATOR_REV} @@@"
281 local dir="$(pwd)/pexe_archive"
282 local tarball="${dir}/pexes.tar.bz2"
283 local measure_cmd="/usr/bin/time -v"
284 local sb_translator="${measure_cmd} \
285 toolchain/pnacl_translator/bin/pnacl-translate"
289 ${UP_DOWN_LOAD} DownloadArchivedPexesTranslator \
290 ${ARCHIVED_PEXE_TRANSLATOR_REV} ${tarball}
291 tar jxf ${tarball} --directory ${dir}
295 # Pexes are arch specific.
298 ld_ext=".armv7.final.pexe"
299 llc_ext=".armv7.final.pexe"
302 ld_ext=".i686.final.pexe"
303 llc_ext=".i686.final.pexe"
306 ld_ext=".x86_64.final.pexe"
307 llc_ext=".i686.final.pexe" # One llc pexe handles both x86-32 and x86-64.
309 *) echo "unknown arch!" && handle-error ;;
312 # Note, that the arch flag has two functions:
313 # 1) it selects the target arch for the translator
314 # 2) combined with --pnacl-sb it selects the host arch for the
315 # sandboxed translators
316 local flags="-arch ${arch} --pnacl-sb --pnacl-driver-verbose \
317 -pnaclabi-allow-dev-intrinsics"
318 if [[ ${arch} = arm ]] ; then
319 # We need to enable qemu magic for arm
320 flags="${flags} --pnacl-use-emulator"
322 local fast_trans_flags="${flags} -translate-fast"
324 # Driver flags for overriding *just* the LLC and LD from
325 # the translator, to test that the LLC and LD generated
326 # from archived pexes may work. Note that this does not override the
327 # libaries or the driver that are part of the translator,
328 # so it is not a full override and will not work if the interface
330 local override_flags="\
331 --pnacl-driver-set-LLC_SB=${dir}/pnacl-llc-${arch}.nexe \
332 --pnacl-driver-set-LD_SB=${dir}/ld-${arch}.nexe"
333 local fast_override_flags="\
334 --pnacl-driver-set-LLC_SB=${dir}/pnacl-llc-${arch}.fast_trans.nexe \
335 --pnacl-driver-set-LD_SB=${dir}/ld-${arch}.fast_trans.nexe"
337 echo "=== Translating the archived translator."
338 echo "=== Compiling Old Gold (normal mode) ==="
339 ${sb_translator} ${flags} ${dir}/ld${ld_ext} \
340 -o ${dir}/ld-${arch}.nexe
341 echo "=== Compiling Old Gold (fast mode) ==="
342 ${sb_translator} ${fast_trans_flags} ${dir}/ld${ld_ext} \
343 -o ${dir}/ld-${arch}.fast_trans.nexe
345 # Yikes: This takes about 17min on arm with qemu
346 echo "=== Compiling Old pnacl-llc (normal mode) ==="
347 ${sb_translator} ${flags} ${dir}/pnacl-llc${llc_ext} \
348 -o ${dir}/pnacl-llc-${arch}.nexe
349 echo "=== Compiling Old pnacl-llc (fast mode) ==="
350 ${sb_translator} ${fast_trans_flags} ${dir}/pnacl-llc${llc_ext} \
351 -o ${dir}/pnacl-llc-${arch}.fast_trans.nexe
356 echo "=== Running the translated archived translator to test."
357 ${sb_translator} ${flags} ${override_flags} ${dir}/ld${ld_ext} \
358 -o ${dir}/ld-${arch}.2.nexe
359 ${sb_translator} ${flags} ${fast_override_flags} ${dir}/ld${ld_ext} \
360 -o ${dir}/ld-${arch}.3.nexe
362 # TODO(robertm): Ideally we would compare the result of translation like so
363 # ${dir}/ld-${arch}.2.nexe == ${dir}/ld-${arch}.3.nexe
364 # but this requires the translator to be deterministic which is not
365 # quite true at the moment - probably due to due hashing inside of
366 # llc based on pointer values.
374 # Only build MIPS stuff on mips bots
375 if [[ ${archset} == "mips" ]]; then
376 export PNACL_BUILD_MIPS=true
377 # Don't run any of the tests yet
378 echo "MIPS bot: Only running build, and not tests"
382 echo "@@@BUILD_STEP show-config@@@"
383 ${PNACL_BUILD} show-config
385 # Build the un-sandboxed toolchain
386 echo "@@@BUILD_STEP compile_toolchain@@@"
388 HOST_ARCH=x86_32 ${PNACL_BUILD} all
389 # Make 64-bit versions of the build tools such as fpcmp (used for llvm
390 # test suite and for some reason it matters that they match the build machine)
391 ${PNACL_BUILD} llvm-configure
392 PNACL_MAKE_OPTS=BUILD_DIRS_ONLY=1 ${PNACL_BUILD} llvm-make
394 # run the torture tests. the "trybot" phases take care of prerequisites
396 for arch in ${archset}; do
397 if [[ "${arch}" == "x86-32" ]]; then
398 # Torture tests on x86-32 are covered by tc-tests-all in
402 echo "@@@BUILD_STEP torture_tests $arch @@@"
403 ${TORTURE_TEST} pnacl ${arch} --verbose \
404 --concurrency=${PNACL_CONCURRENCY} || handle-error
407 # llvm-test-suite below requires the SDK libraries to be installed.
408 # torture_tests above do this as a side effect, but we do it
409 # explicitly here for cases in which torture_tests are not run.
410 echo "@@@BUILD_STEP install sdk libraries @@@"
414 optset[1]="--opt O3f --opt O2b"
415 for arch in ${archset}; do
416 # Run all appropriate frontend/backend optimization combinations.
417 # For now, this means running 2 combinations for x86 since each
418 # takes about 20 minutes on the bots, and making a single run
419 # elsewhere since e.g. arm takes about 75 minutes. In a perfect
420 # world, all 4 combinations would be run.
421 if [[ ${archset} =~ x86 ]]; then
422 optset[2]="--opt O3f --opt O0b"
424 for opt in "${optset[@]}"; do
425 echo "@@@BUILD_STEP llvm-test-suite ${arch} ${opt} @@@"
426 python ${LLVM_TESTSUITE} --testsuite-prereq --arch ${arch}
427 python ${LLVM_TESTSUITE} --testsuite-clean
428 python ${LLVM_TESTSUITE} \
429 --testsuite-configure --testsuite-run --testsuite-report \
430 --arch ${arch} ${opt} -v -c || handle-error
433 archived-frontend-test ${arch}
435 # Note: we do not build the sandboxed translator on this bot
436 # because this would add another 20min to the build time.
437 # The upshot of this is that we are using the sandboxed
438 # toolchain which is currently deps'ed in.
439 # There is a small upside here: we will notice that bitcode has
440 # changed in a way that is incompatible with older translators.
441 # TODO(pnacl-team): rethink this.
442 # Note: the tests which use sandboxed translation are at the end,
443 # because they can sometimes hang on arm, causing buildbot to kill the
444 # script without running any more tests.
445 scons-tests-translator ${arch}
447 archived-pexe-translator-test ${arch}
449 if [[ ${arch} = x86-64 ]] ; then
450 scons-tests-x86-64-zero-based-sandbox
458 # NOTE: this is used for manual testing only
459 tc-test-bot "x86-64 x86-32 arm"