Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / buildbot / buildbot_spec2k.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 ######################################################################
11 # SCRIPT CONFIG
12 ######################################################################
13
14 readonly CLOBBER=${CLOBBER:-yes}
15 readonly SCONS_TRUSTED="./scons --mode=opt-host -j8"
16 readonly SCONS_NACL="./scons --mode=opt-host,nacl -j8"
17 readonly SPEC_HARNESS=${SPEC_HARNESS:-${HOME}/cpu2000-redhat64-ia32}/
18
19 readonly TRYBOT_TESTS="176.gcc 179.art 181.mcf 197.parser 252.eon 254.gap"
20 readonly TRYBOT_X86_64_ZERO_BASED_SANDBOX_TESTS="176.gcc"
21
22 readonly BUILDBOT_PNACL="buildbot/buildbot_pnacl.sh"
23 readonly UP_DOWN_LOAD="buildbot/file_up_down_load.sh"
24
25 readonly SPEC_BASE="tests/spec2k"
26 readonly ARCHIVE_NAME=$(${SPEC_BASE}/run_all.sh GetTestArchiveName)
27
28 readonly NAME_ARM_TRY_UPLOAD=$(${BUILDBOT_PNACL} NAME_ARM_TRY_UPLOAD)
29 readonly NAME_ARM_TRY_DOWNLOAD=$(${BUILDBOT_PNACL} NAME_ARM_TRY_DOWNLOAD)
30 readonly NAME_ARM_UPLOAD=$(${BUILDBOT_PNACL} NAME_ARM_UPLOAD)
31 readonly NAME_ARM_DOWNLOAD=$(${BUILDBOT_PNACL} NAME_ARM_DOWNLOAD)
32
33 readonly QEMU_TOOL="$(pwd)/toolchain/linux_x86/arm_trusted/run_under_qemu_arm"
34
35 # Note: the tool for updating the canned nexes lives at:
36 #        tools/canned_nexe_tool.sh
37 readonly CANNED_NEXE_REV=1001
38
39 # If true, terminate script when first error is encountered.
40 readonly FAIL_FAST=${FAIL_FAST:-false}
41 RETCODE=0
42
43 # Print the number of tests being run for the buildbot status output
44 testcount() {
45   local tests="$1"
46   if [[ ${tests} == "all" ]]; then
47     echo "all"
48   else
49     echo ${tests} | wc -w
50   fi
51 }
52
53 # called when a commands invocation fails
54 handle-error() {
55   RETCODE=1
56   echo "@@@STEP_FAILURE@@@"
57   if ${FAIL_FAST} ; then
58     echo "FAIL_FAST enabled"
59     exit 1
60   fi
61 }
62
63 ######################################################################
64 # SCRIPT ACTION
65 ######################################################################
66
67 clobber() {
68   if [ "${CLOBBER}" == "yes" ] ; then
69     rm -rf scons-out
70   fi
71 }
72
73 # Make up for the toolchain tarballs not quite being a full SDK
74 # Also clean the SPEC dir (that step is here because it should
75 # not be run on hw bots which download rather than build binaries)
76 build-prerequisites() {
77   echo "@@@BUILD_STEP build prerequisites [$*] @@@"
78   pushd ${SPEC_BASE}
79   ./run_all.sh BuildPrerequisites "$@"
80   ./run_all.sh CleanBenchmarks
81   ./run_all.sh PopulateFromSpecHarness "${SPEC_HARNESS}"
82   popd
83 }
84
85 build-tests() {
86   local setups="$1"
87   local tests="$2"
88   local timed="$3" # Do timing and size measurements
89   local compile_repetitions="$4"
90   local count=$(testcount "${tests}")
91
92   pushd ${SPEC_BASE}
93   for setup in ${setups}; do
94     echo "@@@BUILD_STEP spec2k build [${setup}] [${count} tests]@@@"
95     MAKEOPTS=-j8 \
96     SPEC_COMPILE_REPETITIONS=${compile_repetitions} \
97       ./run_all.sh BuildBenchmarks ${timed} ${setup} train ${tests} || \
98         handle-error
99   done
100   popd
101 }
102
103 run-tests() {
104   local setups="$1"
105   local tests="$2"
106   local timed="$3"
107   local run_repetitions="$4"
108   local count=$(testcount "${tests}")
109
110   pushd ${SPEC_BASE}
111   for setup in ${setups}; do
112     echo "@@@BUILD_STEP spec2k run [${setup}] [${count} tests]@@@"
113     if [ ${timed} == "1" ]; then
114       SPEC_RUN_REPETITIONS=${run_repetitions} \
115         ./run_all.sh RunTimedBenchmarks ${setup} train ${tests} || \
116           handle-error
117     else
118       ./run_all.sh RunBenchmarks ${setup} train ${tests} || \
119         handle-error
120     fi
121   done
122   popd
123 }
124
125 upload-test-binaries() {
126   local tests="$1"
127   local try="$2" # set to "try" if this is a try run
128
129   pushd ${SPEC_BASE}
130   echo "@@@BUILD_STEP spec2k archive@@@"
131   ./run_all.sh PackageArmBinaries ${tests}
132   popd
133   echo "@@@BUILD_STEP spec2k upload@@@"
134   if [[ ${try} == "try" ]]; then
135     ${UP_DOWN_LOAD} UploadArmBinariesForHWBotsTry ${NAME_ARM_TRY_UPLOAD} \
136         ${ARCHIVE_NAME}
137   else
138     ${UP_DOWN_LOAD} UploadArmBinariesForHWBots ${NAME_ARM_UPLOAD} \
139         ${ARCHIVE_NAME}
140   fi
141 }
142
143 download-test-binaries() {
144   local try="$1"
145   echo "@@@BUILD_STEP spec2k download@@@"
146   if [[ ${try} == "try" ]]; then
147     ${UP_DOWN_LOAD} DownloadArmBinariesForHWBotsTry ${NAME_ARM_TRY_DOWNLOAD} \
148         ${ARCHIVE_NAME}
149   else
150     ${UP_DOWN_LOAD} DownloadArmBinariesForHWBots ${NAME_ARM_DOWNLOAD} \
151         ${ARCHIVE_NAME}
152   fi
153   echo "@@@BUILD_STEP spec2k untar@@@"
154   pushd ${SPEC_BASE}
155   ./run_all.sh UnpackArmBinaries
156   popd
157 }
158
159 download-validator-test-nexes() {
160   local arch="$1"
161   echo "@@@BUILD_STEP validator test download@@@"
162   ${UP_DOWN_LOAD} DownloadArchivedNexes ${CANNED_NEXE_REV} \
163       "${arch}_giant" giant_nexe.tar.bz2
164   # This generates "CannedNexes/" in the current directory
165   rm -rf CannedNexes
166   tar jxf  giant_nexe.tar.bz2
167 }
168
169 get-validator() {
170   local arch="$1"
171   if [[ ${arch} == "x86-32" ]] ; then
172     echo "$(pwd)/scons-out/opt-linux-x86-32/staging/ncval_new"
173   elif [[ ${arch} == "x86-64" ]] ; then
174     echo "$(pwd)/scons-out/opt-linux-x86-64/staging/ncval_new"
175   elif [[ ${arch} == "arm" ]] ; then
176     echo "$(pwd)/scons-out/opt-linux-arm/staging/arm-ncval-core"
177   else
178     echo "ERROR: unknown arch"
179     exit 1
180   fi
181 }
182
183 LogTimeHelper() {
184   # This format is recognized by the buildbot system
185   echo "RESULT $1_$2: $3= $(bc) seconds"
186 }
187
188 LogTimedRun() {
189   local graph=$1
190   local benchmark=$2
191   local variant=$3
192   shift 3
193   # S: system mode CPU-seconds used by the process
194   # U: user mode CPU-seconds  used by the process
195   # We add a plus sign inbetween so that we can pipe the output to "bc"
196   # Note: the  >() magic creates a "fake" file (think named pipe)
197   #       which passes the output of time to LogTimeHelper
198   /usr/bin/time -f "%U + %S" \
199       --output >(LogTimeHelper ${graph} ${benchmark} ${variant}) \
200       "$@"
201 }
202
203 build-validator() {
204   local arch="$1"
205   echo "@@@BUILD_STEP build validator [${arch}]@@@"
206   if [[ ${arch} == "arm" ]] ; then
207     # TODO(robertm): build the validator
208     echo "NYI"
209   elif [[ ${arch} == "x86-32" ]] ; then
210     ${SCONS_NACL} platform=${arch} ncval_new
211   elif [[ ${arch} == "x86-64" ]] ; then
212     ${SCONS_NACL} platform=${arch} ncval_new
213   else
214     echo "ERROR: unknown arch"
215     exit 1
216   fi
217 }
218
219 measure-validator-speed() {
220   local arch="$1"
221   local validator=$(get-validator ${arch})
222
223   echo "@@@BUILD_STEP validator speed test [${arch}]@@@"
224   if [[ ! -e ${validator} ]] ; then
225     echo "ERROR: missing validator executable: ${validator}"
226     handle-error
227     return
228   fi
229
230   if [[ ${arch} == "arm" && $(uname -p) != arm* ]] ; then
231     # TODO(robertm): build the validator
232     validator="${QEMU_TOOL} ${validator}"
233   fi
234
235   for nexe in CannedNexes/* ; do
236     echo "timing validation of ${nexe}"
237     ls --size --block-size=1 ${nexe}
238     LogTimedRun  "validationtime" $(basename ${nexe}) "canned" \
239         ${validator} ${nexe}
240   done
241 }
242
243 ######################################################################
244 # NOTE: trybots only runs a subset of the the spec2k tests
245
246 pnacl-trybot-arm-buildonly() {
247   clobber
248   build-prerequisites "arm" "bitcode" "arm-ncval-core"
249   ${BUILDBOT_PNACL} archive-for-hw-bots "${NAME_ARM_TRY_UPLOAD}" try
250   build-tests SetupPnaclPexeOpt "${TRYBOT_TESTS}" 0 1
251   upload-test-binaries "${TRYBOT_TESTS}" try
252 }
253
254 pnacl-trybot-arm-hw() {
255   clobber
256   ${BUILDBOT_PNACL} unarchive-for-hw-bots "${NAME_ARM_TRY_DOWNLOAD}" try
257   download-test-binaries try
258   build-tests SetupPnaclTranslatorArmOptHW "${TRYBOT_TESTS}" 1 1
259   run-tests SetupPnaclTranslatorArmOptHW "${TRYBOT_TESTS}" 1 1
260   build-tests SetupPnaclTranslator1ThreadArmOptHW "${TRYBOT_TESTS}" 1 1
261   run-tests SetupPnaclTranslator1ThreadArmOptHW "${TRYBOT_TESTS}" 1 1
262   pushd ${SPEC_BASE};
263   ./run_all.sh TimeValidation SetupPnaclTranslatorArmOptHW "${TRYBOT_TESTS}" ||\
264     handle-error
265   popd
266   build-tests SetupPnaclTranslatorFastArmOptHW "${TRYBOT_TESTS}" 1 1
267   run-tests SetupPnaclTranslatorFastArmOptHW "${TRYBOT_TESTS}" 1 1
268   build-tests SetupPnaclTranslatorFast1ThreadArmOptHW "${TRYBOT_TESTS}" 1 1
269   run-tests SetupPnaclTranslatorFast1ThreadArmOptHW "${TRYBOT_TESTS}" 1 1
270 }
271
272 pnacl-trybot-x8632() {
273   clobber
274   build-prerequisites "x86-32" "bitcode"
275   build-tests SetupPnaclX8632Opt "${TRYBOT_TESTS}" 1 1
276   run-tests SetupPnaclX8632Opt "${TRYBOT_TESTS}" 1 1
277   build-tests SetupPnaclTranslatorX8632Opt "${TRYBOT_TESTS}" 1 1
278   run-tests SetupPnaclTranslatorX8632Opt "${TRYBOT_TESTS}" 1 1
279   build-tests SetupPnaclTranslator1ThreadX8632Opt "${TRYBOT_TESTS}" 1 1
280   run-tests SetupPnaclTranslator1ThreadX8632Opt "${TRYBOT_TESTS}" 1 1
281   build-tests SetupPnaclTranslatorFastX8632Opt "${TRYBOT_TESTS}" 1 1
282   run-tests SetupPnaclTranslatorFastX8632Opt "${TRYBOT_TESTS}" 1 1
283   build-tests SetupPnaclTranslatorFast1ThreadX8632Opt "${TRYBOT_TESTS}" 1 1
284   run-tests SetupPnaclTranslatorFast1ThreadX8632Opt "${TRYBOT_TESTS}" 1 1
285   build-validator x86-32
286   download-validator-test-nexes x86-32
287   measure-validator-speed x86-32
288 }
289
290 pnacl-x86-64-zero-based-sandbox() {
291   clobber
292   export NACL_ENABLE_INSECURE_ZERO_BASED_SANDBOX=1
293   build-prerequisites "x86-64" "bitcode" "x86_64_zero_based_sandbox=1"
294   build-tests SetupPnaclX8664ZBSOpt \
295     "${TRYBOT_X86_64_ZERO_BASED_SANDBOX_TESTS}" 1 1
296   run-tests SetupPnaclX8664ZBSOpt \
297     "${TRYBOT_X86_64_ZERO_BASED_SANDBOX_TESTS}" 1 1
298 }
299
300 pnacl-trybot-x8664() {
301   clobber
302   build-prerequisites "x86-64" "bitcode"
303   build-tests SetupPnaclX8664Opt "${TRYBOT_TESTS}" 1 1
304   run-tests SetupPnaclX8664Opt "${TRYBOT_TESTS}" 1 1
305   build-tests SetupPnaclTranslatorX8664Opt "${TRYBOT_TESTS}" 1 1
306   run-tests SetupPnaclTranslatorX8664Opt "${TRYBOT_TESTS}" 1 1
307   build-tests SetupPnaclTranslator1ThreadX8664Opt "${TRYBOT_TESTS}" 1 1
308   run-tests SetupPnaclTranslator1ThreadX8664Opt "${TRYBOT_TESTS}" 1 1
309   build-tests SetupPnaclTranslatorFastX8664Opt "${TRYBOT_TESTS}" 1 1
310   run-tests SetupPnaclTranslatorFastX8664Opt "${TRYBOT_TESTS}" 1 1
311   build-tests SetupPnaclTranslatorFast1ThreadX8664Opt "${TRYBOT_TESTS}" 1 1
312   run-tests SetupPnaclTranslatorFast1ThreadX8664Opt "${TRYBOT_TESTS}" 1 1
313   pnacl-x86-64-zero-based-sandbox
314   build-validator x86-64
315   download-validator-test-nexes x86-64
316   measure-validator-speed x86-64
317 }
318
319 pnacl-arm-buildonly() {
320   clobber
321   build-prerequisites "arm" "bitcode"
322   ${BUILDBOT_PNACL} archive-for-hw-bots "${NAME_ARM_UPLOAD}" regular
323   build-tests SetupPnaclPexeOpt all 0 1
324   upload-test-binaries all regular
325 }
326
327 pnacl-arm-hw() {
328   clobber
329   ${BUILDBOT_PNACL} unarchive-for-hw-bots "${NAME_ARM_DOWNLOAD}" regular
330   download-test-binaries regular
331   build-tests SetupPnaclTranslatorArmOptHW all 1 1
332   run-tests SetupPnaclTranslatorArmOptHW all 1 2
333   # Only run 1 thread ARM tests 1x to save some time for now.
334   # Hopefully perf infrastructure will smooth out flakes.
335   # Otherwise, we'll bump the runs up to 2x as well.
336   build-tests SetupPnaclTranslator1ThreadArmOptHW all 1 1
337   run-tests SetupPnaclTranslator1ThreadArmOptHW all 1 1
338   build-tests SetupPnaclTranslatorFastArmOptHW all 1 1
339   run-tests SetupPnaclTranslatorFastArmOptHW all 1 2
340   # Only run 1 thread ARM tests 1x to save some time for now.
341   # Hopefully perf infrastructure will smooth out flakes.
342   # Otherwise, we'll bump the runs up to 2x as well.
343   build-tests SetupPnaclTranslatorFast1ThreadArmOptHW all 1 1
344   run-tests SetupPnaclTranslatorFast1ThreadArmOptHW all 1 1
345 }
346
347 pnacl-x8664() {
348   clobber
349   build-prerequisites "x86-64" "bitcode"
350   local setups="SetupPnaclX8664Opt \
351                SetupPnaclTranslatorX8664Opt \
352                SetupPnaclTranslator1ThreadX8664Opt \
353                SetupPnaclTranslatorFastX8664Opt \
354                SetupPnaclTranslatorFast1ThreadX8664Opt"
355   build-tests "${setups}" all 1 3
356   run-tests "${setups}" all 1 3
357   pnacl-x86-64-zero-based-sandbox
358   build-validator x86-64
359   download-validator-test-nexes x86-64
360   measure-validator-speed x86-64
361 }
362
363 pnacl-x8632() {
364   clobber
365   build-prerequisites "x86-32" "bitcode"
366   local setups="SetupPnaclX8632Opt \
367                 SetupPnaclTranslatorX8632Opt \
368                 SetupPnaclTranslator1ThreadX8632Opt \
369                 SetupPnaclTranslatorFastX8632Opt \
370                 SetupPnaclTranslatorFast1ThreadX8632Opt"
371   build-tests "${setups}" all 1 3
372   run-tests "${setups}" all 1 3
373   build-validator x86-32
374   download-validator-test-nexes x86-32
375   measure-validator-speed x86-32
376 }
377
378 nacl-x8632() {
379   clobber
380   build-prerequisites "x86-32" ""
381   local setups="SetupNaclX8632 \
382                 SetupNaclX8632Opt"
383   build-tests "${setups}" all 1 3
384   run-tests "${setups}" all 1 3
385   build-validator x86-32
386   download-validator-test-nexes x86-32
387   measure-validator-speed x86-32
388 }
389
390 nacl-x8664() {
391   clobber
392   build-prerequisites "x86-64" ""
393   local setups="SetupNaclX8664 \
394                 SetupNaclX8664Opt"
395   build-tests "${setups}" all 1 3
396   run-tests "${setups}" all 1 3
397   build-validator x86-64
398   download-validator-test-nexes x86-64
399   measure-validator-speed x86-64
400 }
401
402
403 ######################################################################
404 # Script assumed to be run in native_client/
405 if [[ $(pwd) != */native_client ]]; then
406   echo "ERROR: must be run in native_client!"
407   exit 1
408 fi
409
410
411 if [[ $# -eq 0 ]] ; then
412   echo "you must specify a mode on the commandline:"
413   exit 1
414 fi
415
416 if [ "$(type -t $1)" != "function" ]; then
417   Usage
418   echo "ERROR: unknown mode '$1'." >&2
419   exit 1
420 fi
421
422 "$@"
423
424 if [[ ${RETCODE} != 0 ]]; then
425   echo "@@@BUILD_STEP summary@@@"
426   echo There were failed stages.
427   exit ${RETCODE}
428 fi