Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / spec2k / run_all.sh
1 #!/bin/bash
2
3 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 set -o nounset
8 set -o errexit
9
10 # The script is located in "native_client/tests/spec2k"
11 # Set pwd to spec2k/
12 cd "$(dirname "$0")"
13 if [[ $(basename "$(pwd)") != "spec2k" ]] ; then
14   echo "ERROR: cannot find the spec2k/ directory"
15   exit -1
16 fi
17
18 # TODO(pdox): Remove this dependency.
19 source ../../pnacl/scripts/common-tools.sh
20 readonly NACL_ROOT="$(GetAbsolutePath "../../")"
21 SetScriptPath "$(pwd)/run_all.sh"
22 SetLogDirectory "${NACL_ROOT}/toolchain/test-log"
23 readonly TESTS_ARCHIVE=arm-spec.tar.gz
24
25 ######################################################################
26 # CONFIGURATION
27 ######################################################################
28 # TODO(robertm): make this configurable from the commandline
29
30 readonly LIST_INT_C="164.gzip 175.vpr 176.gcc 181.mcf 186.crafty 197.parser \
31 253.perlbmk 254.gap 255.vortex 256.bzip2 300.twolf"
32
33 readonly LIST_FP_C="177.mesa 179.art 183.equake 188.ammp"
34
35 readonly LIST_INT_CPP="252.eon"
36
37 SPEC2K_BENCHMARKS="${LIST_FP_C} ${LIST_INT_C} ${LIST_INT_CPP}"
38
39 # One of {./run.train.sh, ./run.ref.sh}
40 SPEC2K_SCRIPT="./run.train.sh"
41
42 # uncomment this to disable verification
43 # verification time will be part of  overall benchmarking time
44 # export VERIFY=no
45 export VERIFY=${VERIFY:-yes}
46 export MAKEOPTS=${MAKEOPTS:-}
47
48 # Helper script to process timing / other perf data.
49 # Export these paths to Makefile.common, which will be included by other
50 # Makefiles in random sub-directories (where pwd will be different).
51 export PERF_LOGGER="$(pwd)/emit_perf_log.sh"
52 export COMPILE_REPEATER="$(pwd)/compile_repeater.sh"
53 # Number of times to repeat a timed step.
54 export SPEC_RUN_REPETITIONS=${SPEC_RUN_REPETITIONS:-1}
55 export SPEC_COMPILE_REPETITIONS=${SPEC_COMPILE_REPETITIONS:-1}
56
57 export PNACL_LIBMODE=${PNACL_LIBMODE:-newlib}
58 export DASHDASH=""
59 DO_SIZE=true
60
61 ######################################################################
62 # Helper
63 ######################################################################
64
65 readonly SCONS_OUT="${NACL_ROOT}/scons-out"
66 readonly TC_ROOT="${NACL_ROOT}/toolchain"
67
68 readonly ARM_TRUSTED_TC="${TC_ROOT}/linux_arm-trusted"
69 readonly QEMU_TOOL="${ARM_TRUSTED_TC}/run_under_qemu_arm"
70
71 readonly PNACL_TC=\
72 "${TC_ROOT}/pnacl_${BUILD_PLATFORM}_${BUILD_ARCH}/${PNACL_LIBMODE}"
73 readonly ARM_LLC_NEXE=${TC_ROOT}/pnacl_translator/armv7/bin/pnacl-llc.nexe
74
75 readonly NNACL_TC="${TC_ROOT}/${SCONS_BUILD_PLATFORM}_x86"
76 readonly RUNNABLE_LD_X8632="${NNACL_TC}/x86_64-nacl/lib32/runnable-ld.so"
77 readonly RUNNABLE_LD_X8664="${NNACL_TC}/x86_64-nacl/lib/runnable-ld.so"
78
79 gnu_size() {
80   if ! ${DO_SIZE}; then
81     return 0
82   fi
83   # If the PNaCl toolchain is installed, prefer to use its "size".
84   # TODO(robertm): standardize on one of the pnacl dirs
85   if [ -d "${PNACL_TC}/../host/bin/" ] ; then
86     GNU_SIZE="${PNACL_TC}/../host/bin/arm-pc-nacl-size"
87   elif [ -d "${PNACL_TC}/../pkg/binutils/bin/" ] ; then
88     GNU_SIZE="${PNACL_TC}/../pkg/binutils/bin/arm-pc-nacl-size"
89   elif ${BUILD_PLATFORM_LINUX} ; then
90     GNU_SIZE="size"
91   else
92     # There's nothing we can run here.
93     # The system might have "size" installed, but if it is not GNU,
94     # there's no guarantee it can handle ELF.
95     return 0
96   fi
97   "${GNU_SIZE}" "$@"
98 }
99
100 ######################################################################
101 # Various Setups
102 ######################################################################
103 #@ invocation
104 #@    run_all.sh <mode> <mode-arg>*
105
106 #@ ------------------------------------------------------------
107 #@ Available Setups:
108 #@ ------------------------------------------------------------
109
110 # Setups for building (but not running) Pexes only. Used for arm-hw translator
111 # testing where pexes are build on x86 and translated on arm
112 SetupPnaclPexeOpt() {
113   SUFFIX=opt.stripped.pexe
114 }
115
116 SetupPnaclPexe() {
117   SUFFIX=unopt.stripped.pexe
118 }
119
120 #@
121 #@ SetupGccX8632
122 #@   use system compiler for x86-32
123 SetupGccX8632() {
124   PREFIX=
125   SUFFIX=gcc.x8632
126 }
127
128 #@
129 #@ SetupGccX8632Opt
130 #@   use system compiler for x86-32 with optimization
131 SetupGccX8632Opt() {
132   PREFIX=
133   SUFFIX=gcc.opt.x8632
134 }
135
136 #@
137 #@ SetupGccX8664
138 #@   use system compiler for x86-64
139 SetupGccX8664() {
140   PREFIX=
141   SUFFIX=gcc.x8664
142 }
143
144 #@
145 #@ SetupGccX8664Opt
146 #@   use system compiler for x86-64 with optimization
147 SetupGccX8664Opt() {
148   PREFIX=
149   SUFFIX=gcc.opt.x8664
150 }
151
152 #@
153 #@ SetupEmcc
154 #@   use Emscripten emcc compiler for Asm.js JavaScript generation
155 SetupEmcc() {
156   PREFIX=../run_asmjs.sh
157   SUFFIX=emcc.html
158   DO_SIZE=false
159   VERIFY=no
160 }
161
162 #@
163 #@ SetupLlvmX8632
164 #@   use system compiler for x86-32
165 SetupLlvmX8632() {
166   PREFIX=
167   SUFFIX=llvm.x8632
168 }
169
170 #@
171 #@ SetupLlvmX8632Opt
172 #@   use system compiler for x86-32 with optimization
173 SetupLlvmX8632Opt() {
174   PREFIX=
175   SUFFIX=llvm.opt.x8632
176 }
177
178 #@
179 #@ SetupLlvmX8664
180 #@   use system compiler for x86-64
181 SetupLlvmX8664() {
182   PREFIX=
183   SUFFIX=llvm.x8664
184 }
185
186 #@
187 #@ SetupLlvmX8664Opt
188 #@   use system compiler for x86-64 with optimization
189 SetupLlvmX8664Opt() {
190   PREFIX=
191   SUFFIX=llvm.opt.x8664
192 }
193
194 #@
195 #@ SetupLlvmArm
196 #@   use system compiler for ARM
197 SetupLlvmArm() {
198   PREFIX=
199   SUFFIX=llvm.hw.arm
200 }
201
202 #@
203 #@ SetupLlvmArmOpt
204 #@   use system compiler for ARM with optimization
205 SetupLlvmArmOpt() {
206   PREFIX=
207   SUFFIX=llvm.opt.hw.arm
208 }
209
210 ######################################################################
211
212 SetupNaclX8632Common() {
213   SetupSelLdr x86-32
214 }
215
216 #@
217 #@ SetupNaclX8632
218 #@   use nacl-gcc compiler
219 SetupNaclX8632() {
220   SetupNaclX8632Common
221   SUFFIX=nacl.x8632
222 }
223
224 #@
225 #@ SetupNaclX8632Opt
226 #@   use nacl-gcc compiler with optimizations
227 SetupNaclX8632Opt() {
228   SetupNaclX8632Common
229   SUFFIX=nacl.opt.x8632
230 }
231
232 SetupNaclX8664Common() {
233   SetupSelLdr x86-64
234 }
235
236 #@
237 #@ SetupNaclX8664
238 #@   use nacl-gcc64 compiler
239 SetupNaclX8664() {
240   SetupNaclX8664Common
241   SUFFIX=nacl.x8664
242 }
243
244 #@
245 #@ SetupNaclX8664Opt
246 #@   use nacl-gcc64 compiler with optimizations
247 SetupNaclX8664Opt() {
248   SetupNaclX8664Common
249   SUFFIX=nacl.opt.x8664
250 }
251
252 SetupNaclDynX8632Common() {
253   SetupSelLdr x86-32 "" "-s" "${RUNNABLE_LD_X8632}"
254 }
255
256 #@
257 #@ SetupNaclDynX8632
258 #@   use nacl-gcc compiler with glibc toolchain and dynamic linking
259 SetupNaclDynX8632() {
260   SetupNaclDynX8632Common
261   SUFFIX=nacl.dyn.x8632
262 }
263
264 #@
265 #@ SetupNaclDynX8632Opt
266 #@   use nacl-gcc compiler with glibc toolchain and dynamic linking
267 SetupNaclDynX8632Opt() {
268   SetupNaclDynX8632Common
269   SUFFIX=nacl.dyn.opt.x8632
270 }
271
272 SetupNaclDynX8664Common() {
273   SetupSelLdr x86-64 "" "-s" "${RUNNABLE_LD_X8664}"
274 }
275
276 #@
277 #@ SetupNaclDynX8664
278 #@   use nacl64-gcc compiler with glibc toolchain and dynamic linking
279 SetupNaclDynX8664() {
280   SetupNaclDynX8664Common
281   SUFFIX=nacl.dyn.x8664
282 }
283
284 #@
285 #@ SetupNaclDynX8664Opt
286 #@   use nacl64-gcc compiler with glibc toolchain and dynamic linking
287 SetupNaclDynX8664Opt() {
288   SetupNaclDynX8664Common
289   SUFFIX=nacl.dyn.opt.x8664
290 }
291
292 ######################################################################
293
294 SetupPnaclX8664Common() {
295   SetupSelLdr x86-64
296 }
297
298 #@
299 #@ SetupPnaclX8664
300 #@    use pnacl x86-64 compiler (no lto)
301 SetupPnaclX8664() {
302   SetupPnaclX8664Common
303   SUFFIX=pnacl.x8664
304 }
305
306 #@
307 #@ SetupPnaclX8664Opt
308 #@    use pnacl x86-64 compiler (with lto)
309 SetupPnaclX8664Opt() {
310   SetupPnaclX8664Common
311   SUFFIX=pnacl.opt.x8664
312 }
313
314 #@
315 #@ SetupPnaclX8664ZBSOpt
316 #@    use pnacl x86-64 compiler (with lto)
317 #@    use x86-64 zero-based sandbox
318 SetupPnaclX8664ZBSOpt() {
319   SetupSelLdr x86-64 "" "-c"
320   # TODO(arbenson): Give this a different suffix to differentitate
321   # from the existing x86-64 build, and make the corresponding
322   # changes to the build process.
323   SUFFIX=pnacl.opt.x8664
324 }
325
326 #@
327 #@ SetupPnaclTranslatorX8664
328 #@    use pnacl x8664 translator (no lto)
329 SetupPnaclTranslatorX8664() {
330   SetupPnaclX8664Common
331   SUFFIX=pnacl_translator.x8664
332 }
333
334 #@
335 #@ SetupPnaclTranslatorX8664Opt
336 #@    use pnacl x8664 translator (with lto)
337 SetupPnaclTranslatorX8664Opt() {
338   SetupPnaclX8664Common
339   SUFFIX=pnacl_translator.opt.x8664
340 }
341
342 #@
343 #@ SetupPnaclTranslatorFastX8664Opt
344 #@    use pnacl x8664 translator fast mode (with lto)
345 SetupPnaclTranslatorFastX8664Opt() {
346   SetupPnaclX8664Common
347   SUFFIX=pnacl_translator_fast.opt.x8664
348 }
349
350
351
352 SetupPnaclTranslatorJITX8632Common() {
353  SetupSelLdr x86-32 "" "-S" "${RUNNABLE_LD_X8632} -- --library-path ${NNACL_TC}/x86_64-nacl/lib32 ${NACL_ROOT}/toolchain/pnacl_linux_x86/glibc/tools-sb/x8632/nonsrpc/bin/lli.x8632.nexe -asm-verbose=false -march=x86 -mcpu=pentium4 -mtriple=i686-none-nacl-gnu -jit-emit-debug=false -disable-lazy-compilation"
354   DO_SIZE=false
355   DASHDASH=""
356 }
357
358 #@
359 #@ SetupPnaclTranslatorJITX8632
360 #@    use pnacl x8632 JIT translator (no lto)
361 SetupPnaclTranslatorJITX8632() {
362   SetupPnaclTranslatorJITX8632Common
363   SUFFIX=unopt.pexe
364 }
365
366 #@
367 #@ SetupPnaclTranslatorJITX8632Opt
368 #@    use pnacl x8632 JIT translator
369 SetupPnaclTranslatorJITX8632Opt() {
370   SetupPnaclTranslatorJITX8632Common
371   SUFFIX=opt.stripped.pexe
372 }
373
374 SetupPnaclX8632Common() {
375   SetupSelLdr x86-32
376 }
377
378 #@
379 #@ SetupPnaclX8632
380 #@    use pnacl x86-32 compiler (no lto)
381 SetupPnaclX8632() {
382   SetupPnaclX8632Common
383   SUFFIX=pnacl.x8632
384 }
385
386 #@
387 #@ SetupPnaclX8632Opt
388 #@    use pnacl x86-32 compiler (with lto)
389 SetupPnaclX8632Opt() {
390   SetupPnaclX8632Common
391   SUFFIX=pnacl.opt.x8632
392 }
393
394
395 #@
396 #@ SetupPnaclTranslatorX8632
397 #@    use pnacl x8632 translator (no lto)
398 SetupPnaclTranslatorX8632() {
399   SetupPnaclX8632Common
400   SUFFIX=pnacl_translator.x8632
401 }
402
403 #@
404 #@ SetupPnaclTranslatorX8632Opt
405 #@    use pnacl x8632 translator (with lto)
406 SetupPnaclTranslatorX8632Opt() {
407   SetupPnaclX8632Common
408   SUFFIX=pnacl_translator.opt.x8632
409 }
410
411 #@
412 #@ SetupPnaclTranslatorFastX8632Opt
413 #@    use pnacl x8632 translator fast mode (with lto)
414 SetupPnaclTranslatorFastX8632Opt() {
415   SetupPnaclX8632Common
416   SUFFIX=pnacl_translator_fast.opt.x8632
417 }
418
419
420 #@
421 #@ SetupGccArm
422 #@   use gcc cross compiler
423 SetupGccArm() {
424   PREFIX="${QEMU_TOOL}"
425   SUFFIX=gcc.arm
426 }
427
428 #@
429 #@ SetupGccArmOpt
430 #@   use gcc cross compiler
431 SetupGccArmOpt() {
432   PREFIX="${QEMU_TOOL}"
433   SUFFIX=gcc.opt.arm
434 }
435
436
437 SetupPnaclArmCommon() {
438   SetupSelLdr arm "${QEMU_TOOL}" "-Q"
439 }
440
441 #@
442 #@ SetupPnaclArmOpt
443 #@    use pnacl arm compiler (with lto)  -- run with QEMU
444 SetupPnaclArmOpt() {
445   SetupPnaclArmCommon
446   SUFFIX=pnacl.opt.arm
447 }
448
449 #@
450 #@ SetupPnaclArm
451 #@    use pnacl arm compiler (no lto)  -- run with QEMU
452 SetupPnaclArm() {
453   SetupPnaclArmCommon
454   SUFFIX=pnacl.arm
455 }
456
457 #@
458 #@ SetupPnaclTranslatorArm
459 #@    use pnacl arm translator (no lto)
460 SetupPnaclTranslatorArm() {
461   SetupPnaclArmCommon
462   SUFFIX=pnacl_translator.arm
463 }
464
465 #@
466 #@ SetupPnaclTranslatorArmOpt
467 #@    use pnacl arm translator (with lto)
468 SetupPnaclTranslatorArmOpt() {
469   SetupPnaclArmCommon
470   SUFFIX=pnacl_translator.opt.arm
471 }
472
473 #@
474 #@ SetupPnaclTranslatorFastArmOpt
475 #@    use pnacl arm translator fast mode (with lto)
476 SetupPnaclTranslatorFastArmOpt() {
477   SetupPnaclArmCommon
478   SUFFIX=pnacl_translator_fast.opt.arm
479 }
480
481
482
483 SetupPnaclArmCommonHW() {
484   SetupSelLdr arm
485 }
486
487 #@
488 #@ SetupPnaclArmOptHW
489 #@    use pnacl arm compiler (with lto) -- run on ARM hardware
490 SetupPnaclArmOptHW() {
491   SetupPnaclArmCommonHW
492   SUFFIX=pnacl.opt.arm
493 }
494
495 #@
496 #@ SetupPnaclArmHW
497 #@    use pnacl arm compiler (no lto) -- run on ARM hardware
498 SetupPnaclArmHW() {
499   SetupPnaclArmCommonHW
500   SUFFIX=pnacl.arm
501 }
502
503 #@
504 #@ SetupPnaclTranslatorArmHW
505 #@    use pnacl arm translator (no lto) -- run on ARM hardware
506 SetupPnaclTranslatorArmHW() {
507   SetupPnaclArmCommonHW
508   SUFFIX=pnacl_translator.hw.arm
509 }
510
511 #@
512 #@ SetupPnaclTranslatorArmOptHW
513 #@    use pnacl arm translator (with lto) -- run on ARM hardware
514 SetupPnaclTranslatorArmOptHW() {
515   SetupPnaclArmCommonHW
516   SUFFIX=pnacl_translator.opt.hw.arm
517 }
518
519 #@
520 #@ SetupPnaclTranslatorFastArmOptHW
521 #@    use pnacl arm translator fast mode (with lto) -- run on ARM hardware
522 SetupPnaclTranslatorFastArmOptHW() {
523   SetupPnaclArmCommonHW
524   SUFFIX=pnacl_translator_fast.opt.hw.arm
525 }
526
527
528 ConfigInfo() {
529   SubBanner "Config Info"
530   echo "benchmarks: $(GetBenchmarkList "$@")"
531   echo "script:     $(GetInputSize "$@")"
532   echo "suffix      ${SUFFIX}"
533   echo "verify      ${VERIFY}"
534   echo "prefix     ${PREFIX}"
535
536 }
537
538 ######################################################################
539 # Functions intended to be called
540 ######################################################################
541 #@
542 #@ ------------------------------------------------------------
543 #@ Available Modes:
544 #@ ------------------------------------------------------------
545
546 #@
547 #@ GetBenchmarkList
548 #@
549 #@   Show available benchmarks
550 GetBenchmarkList() {
551   if [[ $# -ge 1 ]]; then
552       if [[ ($1 == "ref") || ($1 == "train") ]]; then
553           shift
554       fi
555   fi
556
557   if [[ ($# == 0) || ($1 == "all") ]] ; then
558       echo "${SPEC2K_BENCHMARKS[@]}"
559   else
560       echo "$@"
561   fi
562 }
563
564 #+
565 #+ GetInputSize [train|ref]
566 #+
567 #+  Picks input size for spec runs (train or ref)
568 GetInputSize() {
569   if [[ $# -ge 1 ]]; then
570     case $1 in
571       train)
572         echo "./run.train.sh"
573         return
574         ;;
575       ref)
576         echo "./run.ref.sh"
577         return
578         ;;
579     esac
580   fi
581   echo ${SPEC2K_SCRIPT}
582 }
583
584 #+
585 #+ CheckFileBuilt <depname> <file> -
586 #+
587 #+   Check that a dependency is actually built.
588 CheckFileBuilt() {
589   local depname="$1"
590   local filename="$2"
591   if [[ ! -f "${filename}" ]] ; then
592     echo "You have not built ${depname} yet (${filename})!" 1>&2
593     exit -1
594   fi
595 }
596
597 #+
598 #+ SetupSelLdr <arch> <prefix> <extra_flags> <preload>
599 #+
600 #+   Set up PREFIX to run sel_ldr on <arch>.
601 #+   <prefix> precedes sel_ldr in the command.
602 #+   <extra_flags> are additional flags to sel_ldr.
603 #+   <preload> is used as the actual nexe to load, making the real nexe an arg.
604 SetupSelLdr() {
605   local arch="$1"
606   local prefix="${2-}"
607   local extra_flags="${3-}"
608   local preload="${4-}"
609
610   local staging="${SCONS_OUT}/opt-${SCONS_BUILD_PLATFORM}-${arch}/staging"
611   SEL_LDR="${staging}/sel_ldr"
612   SEL_LDR_BOOTSTRAP="${staging}/nacl_helper_bootstrap"
613   CheckFileBuilt "sel_ldr" "${SEL_LDR}"
614   CheckFileBuilt "bootstrap" "${SEL_LDR_BOOTSTRAP}"
615
616   IRT_IMAGE="${SCONS_OUT}/nacl_irt-${arch}/staging/irt_core.nexe"
617   CheckFileBuilt "IRT image" "${IRT_IMAGE}"
618
619   local validator_bin="ncval"
620   if [[ ${arch} = "arm" ]]; then
621     validator_bin="arm-ncval-core"
622   fi
623   VALIDATOR="${staging}/${validator_bin}"
624   # We don't CheckFileBuilt for VALIDATOR because we currently don't build
625   # or use it on x86
626
627   TEMPLATE_DIGITS="XXXXXXXXXXXXXXXX"
628   PREFIX="${prefix} ${SEL_LDR_BOOTSTRAP} \
629 ${SEL_LDR} --r_debug=0x${TEMPLATE_DIGITS} \
630 --reserved_at_zero=0x${TEMPLATE_DIGITS} -B ${IRT_IMAGE} \
631 -a ${extra_flags} -f ${preload}"
632   DASHDASH="--"
633 }
634
635 SCONS_COMMON="./scons --mode=opt-host,nacl -j8 --verbose"
636
637 EnableX8664ZeroBasedSandbox() {
638   export NACL_ENABLE_INSECURE_ZERO_BASED_SANDBOX=1
639 }
640
641 build-runtime() {
642   local platforms=$1
643   local runtime_pieces=$2
644   local extra_flags="${3-}"
645   for platform in ${platforms} ; do
646     echo "build-runtime: scons ${runtime_pieces} [${platform}]"
647     (cd ${NACL_ROOT};
648       ${SCONS_COMMON} ${extra_flags} platform=${platform} ${runtime_pieces})
649   done
650 }
651
652 build-libs-nacl() {
653   local platforms=$1
654   shift 1
655   for platform in ${platforms} ; do
656     echo "build-libs-nacl: scons build_lib [${platform}] $*"
657     (cd ${NACL_ROOT};
658       ${SCONS_COMMON} platform=${platform} build_lib "$@")
659   done
660 }
661
662 build-libs-pnacl() {
663   pushd "${NACL_ROOT}"
664   # TODO(dschuff/jvoung): fix this circular dependency with the toolchain build
665   TOOLCHAIN_LABEL=pnacl_linux_x86 pnacl/build.sh sdk newlib
666   popd
667 }
668
669 #@
670 #@ CleanBenchmarks <benchmark>*
671 #@
672 #@   this is a deep clean and you have to rerun PopulateFromSpecHarness
673 CleanBenchmarks() {
674   local list=$(GetBenchmarkList "$@")
675   rm -rf bin/
676   for i in ${list} ; do
677     SubBanner "Cleaning: $i"
678     cd $i
679     make clean
680     rm -rf src/ data/
681     cd ..
682   done
683 }
684
685 #@
686 #@ BuildBenchmarks <do_timing> <setup> <benchmark>*
687 #@
688 #@  Build all benchmarks according to the setup
689 #@  First arg should be either 0 (no timing) or 1 (run timing measure).
690 #@  Results are delivered to {execname}.compile_time
691 BuildBenchmarks() {
692   export PREFIX=
693   local timeit=$1
694   local setup_func=$2
695   "${setup_func}"
696   shift 2
697
698   local list=$(GetBenchmarkList "$@")
699   ConfigInfo "$@"
700   for i in ${list} ; do
701     SubBanner "Building: $i"
702     cd $i
703     # SPEC_COMPONENT is used for Asm.js builds in Makefile.common.
704     export SPEC_COMPONENT="${i}"
705
706     make ${MAKEOPTS} measureit=${timeit} \
707          PERF_LOGGER="${PERF_LOGGER}" \
708          REPETITIONS="${SPEC_COMPILE_REPETITIONS}" \
709          COMPILE_REPEATER="${COMPILE_REPEATER}" \
710          BUILD_PLATFORM=${BUILD_PLATFORM} \
711          SCONS_BUILD_PLATFORM=${SCONS_BUILD_PLATFORM} \
712          BUILD_ARCH=${BUILD_ARCH} \
713          PNACL_LIBMODE=${PNACL_LIBMODE} \
714          ${i#*.}.${SUFFIX}
715     cd ..
716   done
717 }
718
719
720 #@ TimedRunCmd <time_result_file> {actual_cmd }
721 #@
722 #@  Run the command under time and dump time data to file.
723 TimedRunCmd() {
724   target="$1"
725   shift
726   /usr/bin/time -f "%U %S %e %C" --append -o "${target}" "$@"
727 }
728
729 #@
730 #@ RunBenchmarks <setup> [ref|train] <benchmark>*
731 #@
732 #@  Run all benchmarks according to the setup.
733 RunBenchmarks() {
734   export PREFIX=
735   local setup_func=$1
736   "${setup_func}"
737   shift
738   local list=$(GetBenchmarkList "$@")
739   local script=$(GetInputSize "$@")
740   ConfigInfo "$@"
741   for i in ${list} ; do
742     SubBanner "Benchmarking: $i"
743     cd $i
744     target_file=./${i#*.}.${SUFFIX}
745     gnu_size ${target_file}
746     # SCRIPTNAME is needed by run_asmjs.sh so that it knows
747     # which version of the prepackaged files to use.
748     export SCRIPTNAME="${script}"
749     ${script} ${target_file}
750     cd ..
751   done
752 }
753
754
755 #@
756 #@ RunTimedBenchmarks <setup> [ref|train] <benchmark>*
757 #@
758 #@  Run all benchmarks according to the setup.
759 #@  All timing related files are stored in {execname}.run_time
760 #@  Note that the VERIFY variable effects the timing!
761 RunTimedBenchmarks() {
762   export PREFIX=
763   "$1"
764   shift
765   local list=$(GetBenchmarkList "$@")
766   local script=$(GetInputSize "$@")
767
768   ConfigInfo "$@"
769   for i in ${list} ; do
770     SubBanner "Benchmarking: $i"
771     pushd $i
772     local benchname=${i#*.}
773     local target_file=./${benchname}.${SUFFIX}
774     local time_file=${target_file}.run_time
775     gnu_size  ${target_file}
776     # SCRIPTNAME is needed by run_asmjs.sh so that it knows
777     # which version of the prepackaged files to use.
778     export SCRIPTNAME="${script}"
779     # Clear out the previous times.
780     rm -f "${time_file}"
781     echo "Running benchmark ${SPEC_RUN_REPETITIONS} times"
782     for ((i=0; i<${SPEC_RUN_REPETITIONS}; i++))
783     do
784       TimedRunCmd ${time_file} ${script} ${target_file}
785     done
786     # TODO(jvoung): split runtimes by arch as well
787     # i.e., pull "arch" out of SUFFIX and add to the "runtime" label.
788     "${PERF_LOGGER}" LogRealTime "${time_file}" "runtime" \
789       ${benchname} ${SUFFIX}
790     popd
791   done
792 }
793
794 TimeValidation() {
795   local setup_func=$1
796   "${setup_func}"
797   shift
798   local list=$(GetBenchmarkList "$@")
799   for i in ${list}; do
800     SubBanner "Validating: $i"
801     pushd $i
802     local benchname=${i#*.}
803     local target_file=./${benchname}.${SUFFIX}
804     local time_file=${target_file}.validation_time
805     rm -f "${time_file}"
806     for ((i=0; i<${SPEC_RUN_REPETITIONS}; i++))
807     do
808       TimedRunCmd ${time_file} "${VALIDATOR}" ${target_file}
809     done
810     "${PERF_LOGGER}" LogRealTime "${time_file}" "validationtime" \
811       ${benchname} ${SUFFIX}
812     popd
813   done
814   if [[ ${setup_func} =~ "Arm" ]]; then
815     TimedRunCmd llc.validation_time "${VALIDATOR}" "${ARM_LLC_NEXE}"
816     "${PERF_LOGGER}" LogRealTime llc.validation_time "validationtime" \
817       "llc" ${SUFFIX}
818   fi
819 }
820
821 #@
822 #@ BuildAndRunBenchmarks <setup> [ref|train] <benchmark>*
823 #@
824 #@   Builds and run all benchmarks according to the setup
825 BuildAndRunBenchmarks() {
826   setup=$1
827   shift
828   BuildBenchmarks 0 ${setup} "$@"
829   RunBenchmarks ${setup} "$@"
830 }
831
832 #@
833 #@ TimedBuildAndRunBenchmarks <setup> [ref|train] <benchmark>*
834 #@
835 #@   Builds and run all benchmarks according to the setup, using
836 #@   and records the time spent at each task..
837 #@   Results are saved in {execname}.compile_time and
838 #@   {execname}.run_time for each benchmark executable
839 #@   Note that the VERIFY variable effects the timing!
840 TimedBuildAndRunBenchmarks() {
841   setup=$1
842   shift
843   BuildBenchmarks 1 ${setup} "$@"
844   RunTimedBenchmarks ${setup} "$@"
845 }
846
847 #@
848 #@ PackageArmBinaries [usual var-args for RunBenchmarks]
849 #@
850 #@   Archives ARM binaries built from a local QEMU run of spec
851 #@
852 #@   Note: <setup> should be the QEMU setup (e.g., SetupPnaclArmOpt)
853 #@   Note: As with the other modes in this script, this script should be
854 #@   run from the directory of the script (not the native_client directory).
855 #@
856 PackageArmBinaries() {
857   local BENCH_LIST=$(GetBenchmarkList "$@")
858
859   local UNZIPPED_TAR=$(basename ${TESTS_ARCHIVE} .gz)
860
861   # Switch to native_client directory (from tests/spec2k) so that
862   # when we extract, the builder will have a more natural directory layout.
863   pushd "../.."
864   # Carefully tar only the parts of the spec harness that we need.
865   # First prune
866   find tests/spec2k -name '*.bc' -delete
867   find tests/spec2k -maxdepth 1 -type f -print |
868     xargs tar --no-recursion -cvf ${UNZIPPED_TAR}
869   tar -rvf ${UNZIPPED_TAR} tests/spec2k/bin
870   for i in ${BENCH_LIST} ; do
871     tar -rvf ${UNZIPPED_TAR} tests/spec2k/$i
872   done
873   gzip -f ${UNZIPPED_TAR}
874   popd
875 }
876
877 #@ UnpackArmBinaries
878 #@ Unpack a packaged archive of ARM SPEC binaries. The archive is
879 #@ located in the nacl root directory, but the script is run from the spec dir.
880 UnpackArmBinaries() {
881   (cd ${NACL_ROOT};
882     tar xvzf ${TESTS_ARCHIVE})
883 }
884
885 GetTestArchiveName() {
886   echo ${TESTS_ARCHIVE}
887 }
888
889 #@
890 #@ PopulateFromSpecHarness <path> <benchmark>*
891 #@
892 #@   populate a few essential directories (src, date) from
893 #@   the given spec2k harness
894 PopulateFromSpecHarness() {
895   harness=$1
896   shift
897   cp -r ${harness}/bin .
898   local list=$(GetBenchmarkList "$@")
899   echo ${list}
900   for i in ${list} ; do
901     SubBanner "Populating: $i"
902     # fix the dir with the same name inside spec harness
903     src=$(find -H ${harness} -name $i)
904     # copy relevant dirs over
905     echo "COPY"
906     rm -rf src/ data/
907     cp -r ${src}/data ${src}/src $i
908     # patch if necessary
909     if [[ -e $i/diff ]] ; then
910       echo "PATCH"
911       patch -d $i --verbose -p0 < $i/diff
912     fi
913
914     echo "COMPLETE"
915   done
916 }
917
918 #@
919 #@ BuildPrerequisites <platform> <bitcode>
920 #@
921 #@   Invoke scons to build some potentially missing  components, e.g.
922 #@   sel_ldr, sel_universal, irt, some untrusted libraries.
923 #@   Those compoents should be present in the SDK but are not in the
924 #@   standard toolchain tarballs.
925 BuildPrerequisites() {
926   local platforms=$1
927   local bitcode=$2
928   local extrabuild="${3-}"
929   local extra_flags="${4-}"
930   # Sel universal is only used for the pnacl sandboxed translator,
931   # but prepare it just in case.
932   # IRT is used both to run the tests and to run the pnacl sandboxed translator.
933   build-runtime "${platforms}" "sel_ldr sel_universal irt_core ${extrabuild}" \
934 ${extra_flags}
935   if [ ${bitcode} == "bitcode" ] ; then
936      build-libs-pnacl
937   else
938     # libs may be unnecessary for the glibc build, but build it just in case.
939     build-libs-nacl "${platforms}"
940   fi
941 }
942
943 #@
944 #@ BuildPrerequisitesSetupBased <setup>
945 #@
946 #@   Convenience wrapper for BuildPrerequisites
947 BuildPrerequisitesSetupBased() {
948   local platforms=""
949   local bitcode=""
950   if [[ "$1" == SetupPnacl* ]] ; then
951     bitcode="bitcode"
952   fi
953   if [[ "$1" == Setup*Arm* ]] ; then
954     platforms="arm"
955   elif [[ "$1" == Setup*X8632* ]] ; then
956     platforms="x86-32"
957   elif [[ "$1" == Setup*X8664* ]] ; then
958     platforms="x86-64"
959   else
960     echo "Bad setup [$1]"
961     exit -1
962   fi
963   BuildPrerequisites "${platforms}" "${bitcode}"
964 }
965 ######################################################################
966 # Main
967 ######################################################################
968
969 [ $# = 0 ] && set -- help  # Avoid reference to undefined $1.
970
971 if [ "$(type -t $1)" != "function" ]; then
972   Usage
973   echo "ERROR: unknown mode '$1'." >&2
974   exit 1
975 fi
976
977 "$@"