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.
7 #@-------------------------------------------------------------------
11 #@ test.sh test-<arch>[-sbtc] [extra_arguments_to_scons]
13 #@ Runs the SCons tests with selected arch (optionally with sandboxed tc)
20 #@ test.sh test-x86-32
21 #@ test.sh test-arm-sbtc
23 #@ The env variables: PNACL_CONCURRENCY, PNACL_BUILDBOT, PNACL_DEBUG
24 #@ control behavior of this script
28 ######################################################################
30 ######################################################################
35 # The script is located in "pnacl/".
36 # Set pwd to native_client/
37 cd "$(dirname "$0")"/..
38 if [[ $(basename "$(pwd)") != "native_client" ]] ; then
39 echo "ERROR: cannot find native_client/ directory"
42 readonly NACL_ROOT="$(pwd)"
44 readonly DRYRUN=${DRYRUN:-false}
46 source pnacl/scripts/common-tools.sh
47 SetScriptPath "${NACL_ROOT}/pnacl/test.sh"
48 SetLogDirectory "${NACL_ROOT}/toolchain/test-log"
50 # For different levels of make parallelism change this in your env
51 readonly PNACL_CONCURRENCY=${PNACL_CONCURRENCY:-8}
53 # This needs to be kept in sync with the var of the same name in build.sh
54 readonly TC_BUILD_LLVM="$(pwd)/pnacl/build/llvm_${HOST_ARCH}"
56 ######################################################################
57 ######################################################################
61 ######################################################################
62 ######################################################################
64 # TODO(robertm): figure out what to do about concurrency in debug mode.
65 # Perhaps it is fine just tweaking that via PNACL_CONCURRENCY.
66 if ${PNACL_DEBUG} || ${PNACL_BUILDBOT}; then
67 readonly SCONS_ARGS=(MODE=nacl,opt-host
70 -j${PNACL_CONCURRENCY})
72 readonly SCONS_ARGS=(MODE=nacl,opt-host
76 -j${PNACL_CONCURRENCY})
79 #@ show-tests - see what tests can be run
81 StepBanner "SHOWING TESTS"
82 cat $(find tests -name nacl.scons) | grep -o 'run_[A-Za-z_-]*' | sort | uniq
95 Run ./scons "${SCONS_ARGS[@]}" platform=${arch} "$@"
98 # Returns true if the arguments specify a test
99 # or target name to SCons.
101 while [ $# -gt 0 ]; do
102 # Skip arguments of the form -foo, --foo, or foo=bar.
103 if [[ "$1" =~ ^-.* ]] || [[ "$1" =~ = ]]; then
116 # Clear both the pexe and the nonpexe scons-out directory, since we run
117 # a mix of both tests.
118 if [ "${mode}" == "native" ] ; then
119 Run rm -rf scons-out/nacl-${arch}-pnacl-${frontend}
120 Run rm -rf scons-out/nacl-${arch}-pnacl-pexe-${frontend}
122 Run rm -rf scons-out/nacl-${arch}-pnacl-${mode}-${frontend}
123 Run rm -rf scons-out/nacl-${arch}-pnacl-${mode}-pexe-${frontend}
127 build-sbtc-prerequisites() {
129 # Sandboxed translators currently only require irt_core since they do not
131 RunScons ${arch} sel_ldr sel_universal irt_core
134 #+ Run scons test under a certain configuration
135 #+ scons-tests <arch> <mode={sbtc|}> [optional list of test names]
136 #+ If no optional tests are listed, we will build all the tests then
137 #+ run the "smoke_tests" test suite.
142 scons-clean ${arch} ${mode}
145 if [ ${mode} == "sbtc" ]; then
146 build-sbtc-prerequisites "${arch}"
147 modeflags="use_sandboxed_translator=1"
150 if has-target-name "$@" ; then
151 # By default this uses pexe mode (except where not supported) but this
153 RunScons ${arch} ${modeflags} "$@"
155 # For now, mostly just duplicate mode-buildbot-x86 in buildbot_pnacl.sh
156 # (but don't bother separating build/run for now) until we
157 # converge on exactly what we want
158 RunScons ${arch} ${modeflags} "$@" smoke_tests
159 if [ ${mode} != "sbtc" ]; then
161 RunScons ${arch} ${modeflags} pnacl_generate_pexe=0 "$@" nonpexe_tests
167 ${NACL_ROOT}/pnacl/driver/tests/driver_tests.py --platform="$1"
169 test-arm() { test-driver arm && scons-tests arm native "$@" ; }
170 test-x86-32() { test-driver x86-32 && scons-tests x86-32 native "$@" ; }
171 test-x86-64() { test-driver x86-64 && scons-tests x86-64 native "$@" ; }
173 test-arm-sbtc() { scons-tests arm sbtc "$@" ; }
174 test-x86-32-sbtc() { scons-tests x86-32 sbtc "$@" ; }
175 test-x86-64-sbtc() { scons-tests x86-64 sbtc "$@" ; }
178 #@ test-spec <official-spec-dir> <setup> [ref|train] [<benchmarks>]*
181 if [[ $# -lt 2 ]]; then
182 echo "not enough arguments for test-spec"
185 official=$(GetAbsolutePath $1)
189 ./run_all.sh BuildPrerequisitesSetupBased ${setup}
190 ./run_all.sh CleanBenchmarks "$@"
191 ./run_all.sh PopulateFromSpecHarness ${official} "$@"
192 ./run_all.sh BuildAndRunBenchmarks ${setup} "$@"
196 #+ CollectTimingInfo <directory> <timing_result_file> <tagtype...>
197 #+ CD's into the directory in a subshell and collects all the
198 #+ relevant timed run info
199 #+ tagtype just gets printed out.
200 CollectTimingInfo() {
205 mkdir -p $(dirname ${result_file})
206 echo "##################################################" >>${result_file}
207 date +"# Completed at %F %H:%M:%S %A ${result_file}" >> ${result_file}
209 echo "#" $(uname -a) >> ${result_file}
210 echo "# SETUP: ${setup}" >>${result_file}
211 echo "##################################################" >>${result_file}
212 echo "# COMPILE " >> ${result_file}
213 for ff in $(find . -name "*.compile_time"); do
214 cat ${ff} >> ${result_file}
216 echo "# RUN " >> ${result_file}
217 for ff in $(find . -name "*.run_time"); do
218 cat ${ff} >> ${result_file}
225 #@ timed-test-spec <result-file> <official-spec-dir> <setup> ... - run spec and
226 #@ measure time / size data. Data is emitted to stdout, but also collected
227 #@ in <result-file>. <result-file> is not cleared across runs (but temp files
228 #@ are cleared on each run).
229 #@ Note that the VERIFY variable effects the timing!
231 if ${BUILD_PLATFORM_MAC} ; then
232 echo "Timed-test-spec is not currently supported on MacOS"
233 echo "Namely, /usr/bin/time -f is not supported."
236 if [ "$#" -lt "3" ]; then
237 echo "timed-test-spec {result-file} {spec2krefdir} {setupfunc}" \
238 "[ref|train] [benchmark]*"
242 official=$(GetAbsolutePath $2)
246 ./run_all.sh BuildPrerequisitesSetupBased ${setup}
247 ./run_all.sh CleanBenchmarks "$@"
248 ./run_all.sh PopulateFromSpecHarness ${official} "$@"
249 ./run_all.sh TimedBuildAndRunBenchmarks ${setup} "$@"
250 CollectTimingInfo $(pwd) ${result_file} ${setup}
254 #@ help - Usage information.
259 #@ help-full - Usage information including internal functions.
264 ######################################################################
265 ######################################################################
269 ######################################################################
270 ######################################################################
272 [ $# = 0 ] && set -- help # Avoid reference to undefined $1.
273 if [ "$(type -t $1)" != "function" ]; then
275 echo "ERROR: unknown function '$1'." >&2
276 echo "For help, try:"