This is an automated email from the git hooks/post-receive script.
bernie.ogden pushed a commit to branch bernie/benchmarking in repository toolchain/abe.
commit 77d6a268c5b7394b7f358a973d4c30ea224a2dcb Author: Bernard Ogden bernie.ogden@linaro.org Date: Wed Jul 29 11:44:01 2015 +0200
Clean up error handling
Conservatively default value of error to 1, at beginning of each script. Always set error when desiring to exit with a specific error code.
Change-Id: I5710c828705bba2d2111fb73c5d3f01e2b815d11 --- scripts/benchmark.sh | 41 +++++++++++++++++++++++++++-------------- scripts/runbenchmark.sh | 39 +++++++++++++++++++++++++-------------- 2 files changed, 52 insertions(+), 28 deletions(-)
diff --git a/scripts/benchmark.sh b/scripts/benchmark.sh index b81b189..cc94b14 100755 --- a/scripts/benchmark.sh +++ b/scripts/benchmark.sh @@ -13,7 +13,7 @@ set -o nounset trap clean_top EXIT trap 'error=1; exit' TERM INT HUP QUIT
-error=0 +error=1 declare -A runpids
clean_top() @@ -63,7 +63,8 @@ if test -e "${PWD}/host.conf"; then . "${PWD}/host.conf" else echo "ERROR: no host.conf file! Did you run configure?" 1>&2 - exit 1 + error=1 + exit fi topdir="${abe_path}" #abe global, but this should be the right value for abe
@@ -73,7 +74,8 @@ if test "$((`umask` & 077))" -ne 63; then echo "umask grants permissions to group and world, will remove those permissions" 1>&2 if ! umask g-rwx,o-rwx; then echo "umask failed, wibble, aborting" 1>&2 - exit 1 + error=1 + exit fi fi #End sanity checks @@ -99,7 +101,8 @@ while getopts a:b:ce:f:g:hi:kps flag; do g) tag="${OPTARG}";; h) usage - exit 0 + error=0 + exit ;; i) benchmark_gcc_path="`cd `dirname ${OPTARG}` && echo $PWD/`basename ${OPT [...] k) @@ -111,7 +114,8 @@ while getopts a:b:ce:f:g:hi:kps flag; do echo 'Continue? (y/N)' read answer if ! echo "${answer}" | egrep -i '^(y|yes)[[:blank:]]*$' > /dev/null; then - exit 0 + error=0 + exit fi ;; p) @@ -124,7 +128,8 @@ while getopts a:b:ce:f:g:hi:kps flag; do s) skip_build=1;; *) echo "Bad arg" 1>&2 - exit 1 + error=1 + exit ;; esac done @@ -134,15 +139,18 @@ devices=("$@") if test x"${benchmark:-}" = x; then echo "No benchmark given (-b)" 1>&2 echo "Sensible values might be eembc, spec2000, spec2006" 1>&2 - exit 1 + error=1 + exit fi if test x"${benchmark_gcc_path:-}" = x; then echo "No GCC given (-i)" 1>&2 - exit 1 + error=1 + exit fi if ! test -x "${benchmark_gcc_path}"; then echo "GCC '${benchmark_gcc_path}' does not exist or is not executable" 1>&2 - exit 1 + error=1 + exit fi if test x"`basename ${benchmark_gcc_path}`" = xgcc; then #native build benchmark_gcc_triple= @@ -160,7 +168,8 @@ else #cross-build, implies we need remote devices benchmark_gcc_triple="`basename ${benchmark_gcc_path%-gcc}`" if test ${#devices[@]} -eq 0; then echo "Cross-compiling gcc '${benchmark_gcc_path} given, but no devices given f [...] - exit 1 + error=1 + exit fi fi
@@ -169,14 +178,16 @@ if test x"${skip_build:-}" = x; then (PATH="`dirname ${benchmark_gcc_path}`":${PATH} COMPILER_FLAGS=${compiler_flags} [...] if test $? -ne 0; then echo "Error while building benchmark ${benchmark}" 1>&2 - exit 1 + error=1 + exit fi fi
builddir="`. ${abe_top}/host.conf && . ${topdir}/lib/common.sh && if test x"${benc [...] if test $? -ne 0; then echo "Unable to get builddir" 1>&2 - exit 1 + error=1 + exit fi
#Compress build to a tmpfile in our top-level working directory @@ -185,11 +196,13 @@ fi cmpbuild="`mktemp -p ${abe_top} -t ${benchmark}_XXXXXXX.tar.bz2`" if test $? -ne 0; then echo "Unable to create temporary file for compressed build output" 1>&2 - exit 1 + error=1 + exit fi if ! tar cjf "${cmpbuild}" -C "${builddir}/.." "`basename ${builddir}`"; then echo "Unable to compress ${builddir} to ${cmpbuild}" 1>&2 - exit 1 + error=1 + exit fi for device in "${devices[@]}"; do "${topdir}"/scripts/runbenchmark.sh ${post_target_cmd:+-e "${post_target_cmd}"} [...] diff --git a/scripts/runbenchmark.sh b/scripts/runbenchmark.sh index dabb7c8..8a0b7c5 100755 --- a/scripts/runbenchmark.sh +++ b/scripts/runbenchmark.sh @@ -4,8 +4,10 @@ set -o pipefail set -o nounset
+error=1 + trap clean_benchmark EXIT -trap 'exit ${error}' TERM INT HUP QUIT +trap 'exit ${error}' TERM INT HUP QUIT #Signal death can be part of normal control [...]
#Precondition: the target is in known_hosts ssh_opts="-F /dev/null -o StrictHostKeyChecking=yes -o CheckHostIP=yes" @@ -32,17 +34,18 @@ while getopts a:b:cd:e:g:kpt: flag; do t) buildtar="${OPTARG}";; *) echo "Bad arg" 1>&2 - exit 1 + error=1 + exit ;; esac done shift $((OPTIND - 1)) if test $# -ne 0; then echo "Surplus arguments: $@" 1>&2 - exit 1 + error=1 + exit fi
-error=1 tee_output=/dev/null
# load the configure file produced by configure @@ -50,25 +53,29 @@ if test -e "${PWD}/host.conf"; then . "${PWD}/host.conf" else echo "ERROR: no host.conf file! Did you run configure?" 1>&2 - exit 1 + error=1 + exit fi topdir="${abe_path}" #abe global, but this should be the right value for abe confdir="${topdir}/config/bench/boards" benchlog="`. ${abe_top}/host.conf && . ${topdir}/lib/common.sh && read_config ${be [...] if test $? -ne 0; then echo "Unable to read benchmark config file for ${benchmark}" 1>&2 - exit 1 + error=1 + exit fi safe_output="`. ${abe_top}/host.conf && . ${topdir}/lib/common.sh && read_config $ [...] if test $? -ne 0; then echo "Unable to read benchmark config file for ${benchmark}" 1>&2 - exit 1 + error=1 + exit fi
. "${confdir}/${device}.conf" #We can't use abe's source_config here as it require [...] if test $? -ne 0; then echo "+++ Failed to source ${confdir}/${device}.conf" 1>&2 - exit 1 + error=1 + exit fi
#Make sure that subscripts clean up - we must not leave benchmark sources or data [...] @@ -104,12 +111,13 @@ clean_benchmark() echo "Target post-boot initialisation did not happen, thus nothing to clean up." fi
- exit "${error}" + exit }
if ! (. "${topdir}"/lib/common.sh; remote_exec "${ip}" true ${ssh_opts}) > /dev/nu [...] echo "Unable to connect to target ${ip:-(unknown)}" 1>&2 - exit 1 + error=1 + exit fi
#Should be a sufficient UID, as we wouldn't want to run multiple benchmarks on the [...] @@ -120,20 +128,23 @@ fi mkdir -p "${logdir}/${benchmark}.git" if test $? -ne 0; then echo "Failed to create dir ${logdir}" 1>&2 - exit 1 + error=1 + exit fi
#Create and populate working dir on target target_dir="`. ${topdir}/lib/common.sh; remote_exec ${ip} 'mktemp -dt XXXXXXX' ${s [...] if test $? -ne 0; then echo "Unable to get tmpdir on target" 1>&2 - exit 1 + error=1 + exit fi for thing in "${buildtar}" "${topdir}/scripts/controlledrun.sh" "${confdir}/${devi [...] (. "${topdir}"/lib/common.sh; remote_upload -r 3 "${ip}" "${thing}" "${target_di [...] if test $? -ne 0; then echo "Unable to copy ${thing}" to "${ip}:${target_dir}/${thing}" 1>&2 - exit 1 + error=1 + exit fi done
@@ -223,4 +234,4 @@ if test ${error} -eq 0; then else echo "+++ Run of ${benchmark} on ${device} failed" fi -exit ${error} +exit