Upstream version 5.34.104.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_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   pushd ${SPEC_BASE};
261   ./run_all.sh TimeValidation SetupPnaclTranslatorArmOptHW "${TRYBOT_TESTS}" ||\
262     handle-error
263   popd
264   build-tests SetupPnaclTranslatorFastArmOptHW "${TRYBOT_TESTS}" 1 1
265   run-tests SetupPnaclTranslatorFastArmOptHW "${TRYBOT_TESTS}" 1 1
266 }
267
268 pnacl-trybot-x8632() {
269   clobber
270   build-prerequisites "x86-32" "bitcode"
271   build-tests SetupPnaclX8632Opt "${TRYBOT_TESTS}" 1 1
272   run-tests SetupPnaclX8632Opt "${TRYBOT_TESTS}" 1 1
273   build-tests SetupPnaclTranslatorX8632Opt "${TRYBOT_TESTS}" 1 1
274   run-tests SetupPnaclTranslatorX8632Opt "${TRYBOT_TESTS}" 1 1
275   build-tests SetupPnaclTranslatorFastX8632Opt "${TRYBOT_TESTS}" 1 1
276   run-tests SetupPnaclTranslatorFastX8632Opt "${TRYBOT_TESTS}" 1 1
277   build-validator x86-32
278   download-validator-test-nexes x86-32
279   measure-validator-speed x86-32
280 }
281
282 pnacl-x86-64-zero-based-sandbox() {
283   clobber
284   export NACL_ENABLE_INSECURE_ZERO_BASED_SANDBOX=1
285   build-prerequisites "x86-64" "bitcode" "x86_64_zero_based_sandbox=1"
286   build-tests SetupPnaclX8664ZBSOpt \
287     "${TRYBOT_X86_64_ZERO_BASED_SANDBOX_TESTS}" 1 1
288   run-tests SetupPnaclX8664ZBSOpt \
289     "${TRYBOT_X86_64_ZERO_BASED_SANDBOX_TESTS}" 1 1
290 }
291
292 pnacl-trybot-x8664() {
293   clobber
294   build-prerequisites "x86-64" "bitcode"
295   build-tests SetupPnaclX8664Opt "${TRYBOT_TESTS}" 1 1
296   run-tests SetupPnaclX8664Opt "${TRYBOT_TESTS}" 1 1
297   build-tests SetupPnaclTranslatorX8664Opt "${TRYBOT_TESTS}" 1 1
298   run-tests SetupPnaclTranslatorX8664Opt "${TRYBOT_TESTS}" 1 1
299   build-tests SetupPnaclTranslatorFastX8664Opt "${TRYBOT_TESTS}" 1 1
300   run-tests SetupPnaclTranslatorFastX8664Opt "${TRYBOT_TESTS}" 1 1
301   pnacl-x86-64-zero-based-sandbox
302   build-validator x86-64
303   download-validator-test-nexes x86-64
304   measure-validator-speed x86-64
305 }
306
307 pnacl-arm-buildonly() {
308   clobber
309   build-prerequisites "arm" "bitcode"
310   ${BUILDBOT_PNACL} archive-for-hw-bots "${NAME_ARM_UPLOAD}" regular
311   build-tests SetupPnaclPexeOpt all 0 1
312   upload-test-binaries all regular
313 }
314
315 pnacl-arm-hw() {
316   clobber
317   ${BUILDBOT_PNACL} unarchive-for-hw-bots "${NAME_ARM_DOWNLOAD}" regular
318   download-test-binaries regular
319   build-tests SetupPnaclTranslatorArmOptHW all 1 1
320   run-tests SetupPnaclTranslatorArmOptHW all 1 2
321   build-tests SetupPnaclTranslatorFastArmOptHW all 1 1
322   run-tests SetupPnaclTranslatorFastArmOptHW all 1 2
323 }
324
325 pnacl-x8664() {
326   clobber
327   build-prerequisites "x86-64" "bitcode"
328   local setups="SetupPnaclX8664Opt \
329                SetupPnaclTranslatorX8664Opt \
330                SetupPnaclTranslatorFastX8664Opt"
331   build-tests "${setups}" all 1 3
332   run-tests "${setups}" all 1 3
333   pnacl-x86-64-zero-based-sandbox
334   build-validator x86-64
335   download-validator-test-nexes x86-64
336   measure-validator-speed x86-64
337 }
338
339 pnacl-x8632() {
340   clobber
341   build-prerequisites "x86-32" "bitcode"
342   local setups="SetupPnaclX8632Opt \
343                 SetupPnaclTranslatorX8632Opt \
344                 SetupPnaclTranslatorFastX8632Opt"
345   build-tests "${setups}" all 1 3
346   run-tests "${setups}" all 1 3
347   build-validator x86-32
348   download-validator-test-nexes x86-32
349   measure-validator-speed x86-32
350 }
351
352 nacl-x8632() {
353   clobber
354   build-prerequisites "x86-32" ""
355   local setups="SetupNaclX8632 \
356                 SetupNaclX8632Opt"
357   build-tests "${setups}" all 1 3
358   run-tests "${setups}" all 1 3
359   build-validator x86-32
360   download-validator-test-nexes x86-32
361   measure-validator-speed x86-32
362 }
363
364 nacl-x8664() {
365   clobber
366   build-prerequisites "x86-64" ""
367   local setups="SetupNaclX8664 \
368                 SetupNaclX8664Opt"
369   build-tests "${setups}" all 1 3
370   run-tests "${setups}" all 1 3
371   build-validator x86-64
372   download-validator-test-nexes x86-64
373   measure-validator-speed x86-64
374 }
375
376
377 ######################################################################
378 # Script assumed to be run in native_client/
379 if [[ $(pwd) != */native_client ]]; then
380   echo "ERROR: must be run in native_client!"
381   exit 1
382 fi
383
384
385 if [[ $# -eq 0 ]] ; then
386   echo "you must specify a mode on the commandline:"
387   exit 1
388 fi
389
390 if [ "$(type -t $1)" != "function" ]; then
391   Usage
392   echo "ERROR: unknown mode '$1'." >&2
393   exit 1
394 fi
395
396 "$@"
397
398 if [[ ${RETCODE} != 0 ]]; then
399   echo "@@@BUILD_STEP summary@@@"
400   echo There were failed stages.
401   exit ${RETCODE}
402 fi