toolkit/crashreporter/google-breakpad/android/run-checks.sh

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/android/run-checks.sh	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,552 @@
     1.4 +#!/bin/sh
     1.5 +# Copyright (c) 2012 Google Inc.
     1.6 +# All rights reserved.
     1.7 +#
     1.8 +# Redistribution and use in source and binary forms, with or without
     1.9 +# modification, are permitted provided that the following conditions are
    1.10 +# met:
    1.11 +#
    1.12 +#     * Redistributions of source code must retain the above copyright
    1.13 +# notice, this list of conditions and the following disclaimer.
    1.14 +#     * Redistributions in binary form must reproduce the above
    1.15 +# copyright notice, this list of conditions and the following disclaimer
    1.16 +# in the documentation and/or other materials provided with the
    1.17 +# distribution.
    1.18 +#     * Neither the name of Google Inc. nor the names of its
    1.19 +# contributors may be used to endorse or promote products derived from
    1.20 +# this software without specific prior written permission.
    1.21 +#
    1.22 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.23 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.24 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.25 +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.26 +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.27 +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.28 +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.29 +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.30 +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.31 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.32 +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.33 +
    1.34 +# Sanitize the environment
    1.35 +export LANG=C
    1.36 +export LC_ALL=C
    1.37 +
    1.38 +if [ "$BASH_VERSION" ]; then
    1.39 +  set -o posix
    1.40 +fi
    1.41 +
    1.42 +PROGDIR=$(dirname "$0")
    1.43 +PROGDIR=$(cd "$PROGDIR" && pwd)
    1.44 +PROGNAME=$(basename "$0")
    1.45 +
    1.46 +. $PROGDIR/common-functions.sh
    1.47 +
    1.48 +DEFAULT_ABI="armeabi"
    1.49 +VALID_ABIS="armeabi armeabi-v7a x86 mips"
    1.50 +
    1.51 +ABI=
    1.52 +ADB=
    1.53 +ALL_TESTS=
    1.54 +ENABLE_M32=
    1.55 +HELP=
    1.56 +HELP_ALL=
    1.57 +NDK_DIR=
    1.58 +NO_CLEANUP=
    1.59 +NO_DEVICE=
    1.60 +NUM_JOBS=$(get_core_count)
    1.61 +TMPDIR=
    1.62 +
    1.63 +for opt do
    1.64 +  # The following extracts the value if the option is like --name=<value>.
    1.65 +  optarg=$(expr -- $opt : '^--[^=]*=\(.*\)$')
    1.66 +  case $opt in
    1.67 +    --abi=*) ABI=$optarg;;
    1.68 +    --adb=*) ADB=$optarg;;
    1.69 +    --all-tests) ALL_TESTS=true;;
    1.70 +    --enable-m32) ENABLE_M32=true;;
    1.71 +    --help|-h|-?) HELP=TRUE;;
    1.72 +    --help-all) HELP_ALL=true;;
    1.73 +    --jobs=*) NUM_JOBS=$optarg;;
    1.74 +    --ndk-dir=*) NDK_DIR=$optarg;;
    1.75 +    --tmp-dir=*) TMPDIR=$optarg;;
    1.76 +    --no-cleanup) NO_CLEANUP=true;;
    1.77 +    --no-device) NO_DEVICE=true;;
    1.78 +    --quiet) decrease_verbosity;;
    1.79 +    --verbose) increase_verbosity;;
    1.80 +    -*) panic "Invalid option '$opt', see --help for details.";;
    1.81 +    *) panic "This script doesn't take any parameters. See --help for details."
    1.82 +       ;;
    1.83 +  esac
    1.84 +done
    1.85 +
    1.86 +if [ "$HELP" -o "$HELP_ALL" ]; then
    1.87 +  echo "\
    1.88 +  Usage: $PROGNAME [options]
    1.89 +
    1.90 +  This script is used to check that your Google Breakpad source tree can
    1.91 +  be properly built for Android, and that the client library and host tools
    1.92 +  work properly together.
    1.93 +"
    1.94 +  if [ "$HELP_ALL" ]; then
    1.95 +    echo "\
    1.96 +  In more details, this script will:
    1.97 +
    1.98 +  - Rebuild the host version of Google Breakpad in a temporary
    1.99 +    directory (with the Auto-tools based build system).
   1.100 +
   1.101 +  - Rebuild the Android client library with the Google Breakpad build
   1.102 +    system (using autotools/configure). This requires that you define
   1.103 +    ANDROID_NDK_ROOT in your environment to point to a valid Android NDK
   1.104 +    installation directory, or use the --ndk-dir=<path> option.
   1.105 +
   1.106 +  - Rebuild the Android client library and a test crashing program with the
   1.107 +    Android NDK build system (ndk-build).
   1.108 +
   1.109 +  - Require an Android device connected to your machine, and the 'adb'
   1.110 +    tool in your path. They are used to:
   1.111 +
   1.112 +      - Install and  run a test crashing program.
   1.113 +      - Extract the corresponding minidump from the device.
   1.114 +      - Dump the symbols from the test program on the host with 'dump_syms'
   1.115 +      - Generate a stack trace with 'minidump_stackwalk'
   1.116 +      - Check the stack trace content for valid source file locations.
   1.117 +
   1.118 +    You can however skip this requirement and only test the builds by using
   1.119 +    the --no-device flag.
   1.120 +
   1.121 +    By default, all generated files will be created in a temporary directory
   1.122 +    that is removed when the script completion. If you want to inspect the
   1.123 +    files, use the --no-cleanup option.
   1.124 +
   1.125 +    Finally, use --verbose to increase the verbosity level, this will help
   1.126 +    you see which exact commands are being issues and their result. Use the
   1.127 +    flag twice for even more output. Use --quiet to decrease verbosity
   1.128 +    instead and run the script silently.
   1.129 +
   1.130 +    If you have a device connected, the script will probe it to determine
   1.131 +    its primary CPU ABI, and build the test program for it. You can however
   1.132 +    use the --abi=<name> option to override this (this can be useful to check
   1.133 +    the secondary ABI, e.g. using --abi=armeabi to check that such a program
   1.134 +    works correctly on an ARMv7-A device).
   1.135 +
   1.136 +    If you don't have a device connected, the test program will be built (but
   1.137 +    not run) with the default '$DEFAULT_ABI' ABI. Again, you can use
   1.138 +    --abi=<name> to override this. Valid ABI names are:
   1.139 +
   1.140 +        $VALID_ABIS
   1.141 +
   1.142 +    The script will only run the client library unit test on the device
   1.143 +    by default. You can use --all-tests to also build and run the unit
   1.144 +    tests for the Breakpad tools and processor, but be warned that this
   1.145 +    adds several minutes of testing time. --all-tests will also run the
   1.146 +    host unit tests suite.
   1.147 +"
   1.148 +
   1.149 +  fi  # HELP_ALL
   1.150 +
   1.151 +  echo "\
   1.152 +  Valid options:
   1.153 +
   1.154 +      --help|-h|-?     Display this message.
   1.155 +      --help-all       Display extended help.
   1.156 +      --enable-m32     Build 32-bit version of host tools.
   1.157 +      --abi=<name>     Specify target CPU ABI [auto-detected].
   1.158 +      --jobs=<count>   Run <count> build tasks in parallel [$NUM_JOBS].
   1.159 +      --ndk-dir=<path> Specify NDK installation directory.
   1.160 +      --tmp-dir=<path> Specify temporary directory (will be wiped-out).
   1.161 +      --adb=<path>     Specify adb program path.
   1.162 +      --no-cleanup     Don't remove temporary directory after completion.
   1.163 +      --no-device      Do not try to detect devices, nor run crash test.
   1.164 +      --all-tests      Run all unit tests (i.e. tools and processor ones too).
   1.165 +      --verbose        Increase verbosity.
   1.166 +      --quiet          Decrease verbosity."
   1.167 +
   1.168 +  exit 0
   1.169 +fi
   1.170 +
   1.171 +TESTAPP_DIR=$PROGDIR/sample_app
   1.172 +
   1.173 +# Select NDK install directory.
   1.174 +if [ -z "$NDK_DIR" ]; then
   1.175 +  if [ -z "$ANDROID_NDK_ROOT" ]; then
   1.176 +    panic "Please define ANDROID_NDK_ROOT in your environment, or use \
   1.177 +--ndk-dir=<path>."
   1.178 +  fi
   1.179 +  NDK_DIR="$ANDROID_NDK_ROOT"
   1.180 +  log "Found NDK directory: $NDK_DIR"
   1.181 +else
   1.182 +  log "Using NDK directory: $NDK_DIR"
   1.183 +fi
   1.184 +# Small sanity check.
   1.185 +NDK_BUILD="$NDK_DIR/ndk-build"
   1.186 +if [ ! -f "$NDK_BUILD" ]; then
   1.187 +  panic "Your NDK directory is not valid (missing ndk-build): $NDK_DIR"
   1.188 +fi
   1.189 +
   1.190 +# Ensure the temporary directory is deleted on exit, except if the --no-cleanup
   1.191 +# option is used.
   1.192 +
   1.193 +clean_tmpdir () {
   1.194 +  if [ "$TMPDIR" ]; then
   1.195 +    if [ -z "$NO_CLEANUP" ]; then
   1.196 +      log "Cleaning up: $TMPDIR"
   1.197 +      rm -rf "$TMPDIR"
   1.198 +    else
   1.199 +      dump "Temporary directory contents preserved: $TMPDIR"
   1.200 +    fi
   1.201 +  fi
   1.202 +  exit "$@"
   1.203 +}
   1.204 +
   1.205 +atexit clean_tmpdir
   1.206 +
   1.207 +# If --tmp-dir=<path> is not used, create a temporary directory.
   1.208 +# Otherwise, start by cleaning up the user-provided path.
   1.209 +if [ -z "$TMPDIR" ]; then
   1.210 +  TMPDIR=$(mktemp -d /tmp/$PROGNAME.XXXXXXXX)
   1.211 +  fail_panic "Can't create temporary directory!"
   1.212 +  log "Using temporary directory: $TMPDIR"
   1.213 +else
   1.214 +  if [ ! -d "$TMPDIR" ]; then
   1.215 +    mkdir -p "$TMPDIR"
   1.216 +    fail_panic "Can't create temporary directory: $TMPDIR"
   1.217 +  else
   1.218 +    log "Cleaning up temporary directory: $TMPDIR"
   1.219 +    rm -rf "$TMPDIR"/*
   1.220 +    fail_panic "Cannot cleanup temporary directory!"
   1.221 +  fi
   1.222 +fi
   1.223 +
   1.224 +if [ -z "$NO_DEVICE" ]; then
   1.225 +  if ! adb_check_device $ADB; then
   1.226 +    echo "$(adb_get_error)"
   1.227 +    echo "Use --no-device to build the code without running any tests."
   1.228 +    exit 1
   1.229 +  fi
   1.230 +fi
   1.231 +
   1.232 +BUILD_LOG="$TMPDIR/build.log"
   1.233 +RUN_LOG="$TMPDIR/run.log"
   1.234 +CRASH_LOG="$TMPDIR/crash.log"
   1.235 +
   1.236 +set_run_log "$RUN_LOG"
   1.237 +
   1.238 +TMPHOST="$TMPDIR/host-local"
   1.239 +
   1.240 +cd "$TMPDIR"
   1.241 +
   1.242 +# Build host version of the tools
   1.243 +dump "Building host binaries."
   1.244 +CONFIGURE_FLAGS=
   1.245 +if [ "$ENABLE_M32" ]; then
   1.246 +  CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-m32"
   1.247 +fi
   1.248 +(
   1.249 +  run mkdir "$TMPDIR/build-host" &&
   1.250 +  run cd "$TMPDIR/build-host" &&
   1.251 +  run2 "$PROGDIR/../configure" --prefix="$TMPHOST" $CONFIGURE_FLAGS &&
   1.252 +  run2 make -j$NUM_JOBS install
   1.253 +)
   1.254 +fail_panic "Can't build host binaries!"
   1.255 +
   1.256 +if [ "$ALL_TESTS" ]; then
   1.257 +  dump "Running host unit tests."
   1.258 +  (
   1.259 +    run cd "$TMPDIR/build-host" &&
   1.260 +    run2 make -j$NUM_JOBS check
   1.261 +  )
   1.262 +  fail_panic "Host unit tests failed!!"
   1.263 +fi
   1.264 +
   1.265 +TMPBIN=$TMPHOST/bin
   1.266 +
   1.267 +# Generate a stand-alone NDK toolchain
   1.268 +
   1.269 +# Extract CPU ABI and architecture from device, if any.
   1.270 +if adb_check_device; then
   1.271 +  DEVICE_ABI=$(adb_shell getprop ro.product.cpu.abi)
   1.272 +  DEVICE_ABI2=$(adb_shell getprop ro.product.cpu.abi2)
   1.273 +  if [ -z "$DEVICE_ABI" ]; then
   1.274 +    panic "Can't extract ABI from connected device!"
   1.275 +  fi
   1.276 +  if [ "$DEVICE_ABI2" ]; then
   1.277 +    dump "Found device ABIs: $DEVICE_ABI $DEVICE_ABI2"
   1.278 +  else
   1.279 +    dump "Found device ABI: $DEVICE_ABI"
   1.280 +    DEVICE_ABI2=$DEVICE_ABI
   1.281 +  fi
   1.282 +
   1.283 +  # If --abi=<name> is used, check that the device supports it.
   1.284 +  if [ "$ABI" -a "$DEVICE_ABI" != "$ABI" -a "$DEVICE_ABI2" != "$ABI" ]; then
   1.285 +    dump  "ERROR: Device ABI(s) do not match --abi command-line value ($ABI)!"
   1.286 +    panic "Please use --no-device to skip device tests."
   1.287 +  fi
   1.288 +
   1.289 +  if [ -z "$ABI" ]; then
   1.290 +    ABI=$DEVICE_ABI
   1.291 +    dump "Using CPU ABI: $ABI (device)"
   1.292 +  else
   1.293 +    dump "Using CPU ABI: $ABI (command-line)"
   1.294 +  fi
   1.295 +else
   1.296 +  if [ -z "$ABI" ]; then
   1.297 +    # No device connected, choose default ABI
   1.298 +    ABI=$DEFAULT_ABI
   1.299 +    dump "Using CPU ABI: $ABI (default)"
   1.300 +  else
   1.301 +    dump "Using CPU ABI: $ABI (command-line)"
   1.302 +  fi
   1.303 +fi
   1.304 +
   1.305 +# Check the ABI value
   1.306 +VALID=
   1.307 +for VALID_ABI in $VALID_ABIS; do
   1.308 +  if [ "$ABI" = "$VALID_ABI" ]; then
   1.309 +    VALID=true
   1.310 +    break
   1.311 +  fi
   1.312 +done
   1.313 +
   1.314 +if [ -z "$VALID" ]; then
   1.315 +  panic "Unknown CPU ABI '$ABI'. Valid values are: $VALID_ABIS"
   1.316 +fi
   1.317 +
   1.318 +# Extract architecture name from ABI
   1.319 +case $ABI in
   1.320 +  armeabi*) ARCH=arm;;
   1.321 +  *) ARCH=$ABI;;
   1.322 +esac
   1.323 +
   1.324 +# Extract GNU configuration name
   1.325 +case $ARCH in
   1.326 +  arm)
   1.327 +    GNU_CONFIG=arm-linux-androideabi
   1.328 +    ;;
   1.329 +  x86)
   1.330 +    GNU_CONFIG=i686-linux-android
   1.331 +    ;;
   1.332 +  *)
   1.333 +    GNU_CONFIG="$ARCH-linux-android"
   1.334 +    ;;
   1.335 +esac
   1.336 +
   1.337 +# Generate standalone NDK toolchain installation
   1.338 +NDK_STANDALONE="$TMPDIR/ndk-$ARCH-toolchain"
   1.339 +echo "Generating NDK standalone toolchain installation"
   1.340 +mkdir -p "$NDK_STANDALONE"
   1.341 +# NOTE: The --platform=android-9 is required to provide <regex.h> for GTest.
   1.342 +run "$NDK_DIR/build/tools/make-standalone-toolchain.sh" \
   1.343 +      --arch="$ARCH" \
   1.344 +      --platform=android-9 \
   1.345 +      --install-dir="$NDK_STANDALONE"
   1.346 +fail_panic "Can't generate standalone NDK toolchain installation!"
   1.347 +
   1.348 +# Rebuild the client library, processor and tools with the auto-tools based
   1.349 +# build system. Even though it's not going to be used, this checks that this
   1.350 +# still works correctly.
   1.351 +echo "Building full Android binaries with configure/make"
   1.352 +TMPTARGET="$TMPDIR/target-local"
   1.353 +(
   1.354 +  PATH="$NDK_STANDALONE/bin:$PATH"
   1.355 +  run mkdir "$TMPTARGET" &&
   1.356 +  run mkdir "$TMPDIR"/build-target &&
   1.357 +  run cd "$TMPDIR"/build-target &&
   1.358 +  run2 "$PROGDIR"/../configure --prefix="$TMPTARGET" \
   1.359 +                               --host="$GNU_CONFIG" &&
   1.360 +  run2 make -j$NUM_JOBS install
   1.361 +)
   1.362 +fail_panic "Could not rebuild Android binaries!"
   1.363 +
   1.364 +# Build and/or run unit test suite.
   1.365 +# If --no-device is used, only rebuild it, otherwise, run in on the
   1.366 +# connected device.
   1.367 +if [ "$NO_DEVICE" ]; then
   1.368 +  ACTION="Building"
   1.369 +  # This is a trick to force the Makefile to ignore running the scripts.
   1.370 +  TESTS_ENVIRONMENT="TESTS_ENVIRONMENT=true"
   1.371 +else
   1.372 +  ACTION="Running"
   1.373 +  TESTS_ENVIRONMENT=
   1.374 +fi
   1.375 +
   1.376 +(
   1.377 +  PATH="$NDK_STANDALONE/bin:$PATH"
   1.378 +  run cd "$TMPDIR"/build-target &&
   1.379 +  # Reconfigure to only run the client unit test suite.
   1.380 +  # This one should _never_ fail.
   1.381 +  dump "$ACTION Android client library unit tests."
   1.382 +  run2 "$PROGDIR"/../configure --prefix="$TMPTARGET" \
   1.383 +                               --host="$GNU_CONFIG" \
   1.384 +                               --disable-tools \
   1.385 +                               --disable-processor &&
   1.386 +  run make -j$NUM_JOBS check $TESTS_ENVIRONMENT || exit $?
   1.387 +
   1.388 +  if [ "$ALL_TESTS" ]; then
   1.389 +    dump "$ACTION Tools and processor unit tests."
   1.390 +    # Reconfigure to run the processor and tools tests.
   1.391 +    # Most of these fail for now, so do not worry about it.
   1.392 +    run2 "$PROGDIR"/../configure --prefix="$TMPTARGET" \
   1.393 +                                 --host="$GNU_CONFIG" &&
   1.394 +    run make -j$NUM_JOBS check $TESTS_ENVIRONMENT
   1.395 +    if [ $? != 0 ]; then
   1.396 +      dump "Tools and processor unit tests failed as expected. \
   1.397 +Use --verbose for results."
   1.398 +    fi                           
   1.399 +  fi
   1.400 +)
   1.401 +fail_panic "Client library unit test suite failed!"
   1.402 +
   1.403 +# Copy sources to temporary directory
   1.404 +PROJECT_DIR=$TMPDIR/project
   1.405 +dump "Copying test program sources to: $PROJECT_DIR"
   1.406 +run cp -r "$TESTAPP_DIR" "$PROJECT_DIR" &&
   1.407 +run rm -rf "$PROJECT_DIR/obj" &&
   1.408 +run rm -rf "$PROJECT_DIR/libs"
   1.409 +fail_panic "Could not copy test program sources to: $PROJECT_DIR"
   1.410 +
   1.411 +# Build the test program with ndk-build.
   1.412 +dump "Building test program with ndk-build"
   1.413 +export NDK_MODULE_PATH="$PROGDIR"
   1.414 +NDK_BUILD_FLAGS="-j$NUM_JOBS"
   1.415 +if verbosity_is_higher_than 1; then
   1.416 +  NDK_BUILD_FLAGS="$NDK_BUILD_FLAGS NDK_LOG=1 V=1"
   1.417 +fi
   1.418 +run "$NDK_DIR/ndk-build" -C "$PROJECT_DIR" $NDK_BUILD_FLAGS APP_ABI=$ABI
   1.419 +fail_panic "Can't build test program!"
   1.420 +
   1.421 +# Unless --no-device was used, stop right here if ADB isn't in the path,
   1.422 +# or there is no connected device.
   1.423 +if [ "$NO_DEVICE" ]; then
   1.424 +  dump "Done. Please connect a device to run all tests!"
   1.425 +  clean_exit 0
   1.426 +fi
   1.427 +
   1.428 +# Push the program to the device.
   1.429 +TESTAPP=test_google_breakpad
   1.430 +TESTAPP_FILE="$PROJECT_DIR/libs/$ABI/test_google_breakpad"
   1.431 +if [ ! -f "$TESTAPP_FILE" ]; then
   1.432 +  panic "Device requires '$ABI' binaries. None found!"
   1.433 +fi
   1.434 +
   1.435 +# Run the program there
   1.436 +dump "Installing test program on device"
   1.437 +DEVICE_TMP=/data/local/tmp
   1.438 +adb_push "$TESTAPP_FILE" "$DEVICE_TMP/"
   1.439 +fail_panic "Cannot push test program to device!"
   1.440 +
   1.441 +dump "Running test program on device"
   1.442 +adb_shell cd "$DEVICE_TMP" "&&" ./$TESTAPP > "$CRASH_LOG" 2>/dev/null
   1.443 +if [ $? = 0 ]; then
   1.444 +  panic "Test program did *not* crash as expected!"
   1.445 +fi
   1.446 +if verbosity_is_higher_than 0; then
   1.447 +  echo -n "Crash log: "
   1.448 +  cat "$CRASH_LOG"
   1.449 +fi
   1.450 +
   1.451 +# Extract minidump from device
   1.452 +MINIDUMP_NAME=$(awk '$1 == "Dump" && $2 == "path:" { print $3; }' "$CRASH_LOG")
   1.453 +MINIDUMP_NAME=$(basename "$MINIDUMP_NAME")
   1.454 +if [ -z "$MINIDUMP_NAME" ]; then
   1.455 +  panic "Test program didn't write minidump properly!"
   1.456 +fi
   1.457 +
   1.458 +dump "Extracting minidump: $MINIDUMP_NAME"
   1.459 +adb_pull "$DEVICE_TMP/$MINIDUMP_NAME" .
   1.460 +fail_panic "Can't extract minidump!"
   1.461 +
   1.462 +dump "Parsing test program symbols"
   1.463 +if verbosity_is_higher_than 1; then
   1.464 +  log "COMMAND: $TMPBIN/dump_syms \
   1.465 +                $PROJECT_DIR/obj/local/$ABI/$TESTAPP >$TESTAPP.sym"
   1.466 +fi
   1.467 +"$TMPBIN/dump_syms" "$PROJECT_DIR/obj/local/$ABI/$TESTAPP" > $TESTAPP.sym
   1.468 +fail_panic "dump_syms doesn't work!"
   1.469 +
   1.470 +VERSION=$(awk '$1 == "MODULE" { print $4; }' $TESTAPP.sym)
   1.471 +dump "Found module version: $VERSION"
   1.472 +if [ -z "$VERSION" ]; then
   1.473 +  echo "ERROR: Can't find proper module version from symbol dump!"
   1.474 +  head -n5 $TESTAPP.sym
   1.475 +  clean_exit 1
   1.476 +fi
   1.477 +
   1.478 +run mkdir -p "$TMPDIR/symbols/$TESTAPP/$VERSION"
   1.479 +run mv $TESTAPP.sym "$TMPDIR/symbols/$TESTAPP/$VERSION/"
   1.480 +
   1.481 +dump "Generating stack trace"
   1.482 +# Don't use 'run' to be able to send stdout and stderr to two different files.
   1.483 +log "COMMAND: $TMPBIN/minidump_stackwalk $MINIDUMP_NAME symbols"
   1.484 +"$TMPBIN/minidump_stackwalk" $MINIDUMP_NAME \
   1.485 +                             "$TMPDIR/symbols" \
   1.486 +                             > "$BUILD_LOG" 2>>"$RUN_LOG"
   1.487 +fail_panic "minidump_stackwalk doesn't work!"
   1.488 +
   1.489 +dump "Checking stack trace content"
   1.490 +
   1.491 +if verbosity_is_higher_than 1; then
   1.492 +  cat "$BUILD_LOG"
   1.493 +fi
   1.494 +
   1.495 +# The generated stack trace should look like the following:
   1.496 +#
   1.497 +# Thread 0 (crashed)
   1.498 +#  0  test_google_breakpad!crash [test_breakpad.cpp : 17 + 0x4]
   1.499 +#      r4 = 0x00015530    r5 = 0xbea2cbe4    r6 = 0xffffff38    r7 = 0xbea2cb5c
   1.500 +#      r8 = 0x00000000    r9 = 0x00000000   r10 = 0x00000000    fp = 0x00000000
   1.501 +#      sp = 0xbea2cb50    lr = 0x00009025    pc = 0x00008f84
   1.502 +#     Found by: given as instruction pointer in context
   1.503 +#  1  test_google_breakpad!main [test_breakpad.cpp : 25 + 0x3]
   1.504 +#      r4 = 0x00015530    r5 = 0xbea2cbe4    r6 = 0xffffff38    r7 = 0xbea2cb5c
   1.505 +#      r8 = 0x00000000    r9 = 0x00000000   r10 = 0x00000000    fp = 0x00000000
   1.506 +#      sp = 0xbea2cb50    pc = 0x00009025
   1.507 +#     Found by: call frame info
   1.508 +#  2  libc.so + 0x164e5
   1.509 +#      r4 = 0x00008f64    r5 = 0xbea2cc34    r6 = 0x00000001    r7 = 0xbea2cc3c
   1.510 +#      r8 = 0x00000000    r9 = 0x00000000   r10 = 0x00000000    fp = 0x00000000
   1.511 +#      sp = 0xbea2cc18    pc = 0x400c34e7
   1.512 +#     Found by: call frame info
   1.513 +# ...
   1.514 +#
   1.515 +# The most important part for us is ensuring that the source location could
   1.516 +# be extracted, so look at the 'test_breakpad.cpp' references here.
   1.517 +#
   1.518 +# First, extract all the lines with test_google_breakpad! in them, and
   1.519 +# dump the corresponding crash location.
   1.520 +#
   1.521 +# Note that if the source location can't be extracted, the second field
   1.522 +# will only be 'test_google_breakpad' without the exclamation mark.
   1.523 +#
   1.524 +LOCATIONS=$(awk '$2 ~ "^test_google_breakpad!.*" { print $3; }' "$BUILD_LOG")
   1.525 +
   1.526 +if [ -z "$LOCATIONS" ]; then
   1.527 +  if verbosity_is_lower_than 1; then
   1.528 +    cat "$BUILD_LOG"
   1.529 +  fi
   1.530 +  panic "No source location found in stack trace!"
   1.531 +fi
   1.532 +
   1.533 +# Now check that they all match "[<source file>"
   1.534 +BAD_LOCATIONS=
   1.535 +for LOCATION in $LOCATIONS; do
   1.536 +  case $LOCATION in
   1.537 +    # Escape the opening bracket, or some shells like Dash will not
   1.538 +    # match them properly.
   1.539 +    \[*.cpp|\[*.cc|\[*.h) # These are valid source locations in our executable
   1.540 +      ;;
   1.541 +    *) # Everything else is not!
   1.542 +      BAD_LOCATIONS="$BAD_LOCATIONS $LOCATION"
   1.543 +      ;;
   1.544 +  esac
   1.545 +done
   1.546 +
   1.547 +if [ "$BAD_LOCATIONS" ]; then
   1.548 +  dump "ERROR: Generated stack trace doesn't contain valid source locations:"
   1.549 +  cat "$BUILD_LOG"
   1.550 +  echo "Bad locations are: $BAD_LOCATIONS"
   1.551 +  exit 1
   1.552 +fi
   1.553 +
   1.554 +echo "All clear! Congratulations."
   1.555 +

mercurial