diff options
Diffstat (limited to 'toolkit/crashreporter/google-breakpad/android')
9 files changed, 1458 insertions, 0 deletions
diff --git a/toolkit/crashreporter/google-breakpad/android/common-functions.sh b/toolkit/crashreporter/google-breakpad/android/common-functions.sh new file mode 100755 index 0000000000..c00e34f997 --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/common-functions.sh @@ -0,0 +1,372 @@ +# Copyright (c) 2012 Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Collection of common shell functions for 'run-checks.sh' et 'test-shell.sh' + +# All internal variables and functions use an underscore as a prefix +# (e.g. _VERBOSE, _ALL_CLEANUPS, etc..). + +# Sanitize the environment +export LANG=C +export LC_ALL=C + +if [ "$BASH_VERSION" ]; then + set -o posix +fi + +# Utility functions + +_ALL_CLEANUPS= + +# Register a function to be called when the script exits, even in case of +# Ctrl-C, logout, etc. +# $1: function name. +atexit () { + if [ -z "$_ALL_CLEANUPS" ]; then + _ALL_CLEANUPS=$1 + # Ensure a clean exit when the script is: + # - Exiting normally (EXIT) + # - Interrupted by Ctrl-C (INT) + # - Interrupted by log out (HUP) + # - Being asked to quit nicely (TERM) + # - Being asked to quit and dump core (QUIT) + trap "_exit_cleanups \$?" EXIT INT HUP QUIT TERM + else + _ALL_CLEANUPS="$_ALL_CLEANUPS $1" + fi +} + +# Called on exit if at least one function was registered with atexit +# $1: final exit status code +_exit_cleanups () { + local CLEANUP CLEANUPS + # Ignore calls to atexit during cleanups + CLEANUPS=$_ALL_CLEANUPS + _ALL_CLEANUPS= + for CLEANUP in $CLEANUPS; do + ($CLEANUP) + done + exit "$@" +} + + + + +# Dump a panic message then exit. +# $1+: message +panic () { + echo "ERROR: $@" >&2 + exit 1 +} + +# If the previous command failed, dump a panic message then exit. +# $1+: message. +fail_panic () { + if [ $? != 0 ]; then + panic "$@" + fi; +} + +_VERBOSE=0 + +# Increase verbosity for dump/log/run/run2 functions +increase_verbosity () { + _VERBOSE=$(( $_VERBOSE + 1 )) +} + +# Decrease verbosity +decrease_verbosity () { + _VERBOSE=$(( $_VERBOSE - 1 )) +} + +# Returns success iff verbosity level is higher than a specific value +# $1: verbosity level +verbosity_is_higher_than () { + [ "$_VERBOSE" -gt "$1" ] +} + +# Returns success iff verbosity level is lower than a specific value +# $1: verbosity level +verbosity_is_lower_than () { + [ "$_VERBOSE" -le "$1" ] +} + +# Dump message to stdout, unless verbosity is < 0, i.e. --quiet was called +# $1+: message +dump () { + if [ "$_VERBOSE" -ge 0 ]; then + printf "%s\n" "$*" + fi +} + +# If --verbose was used, dump a message to stdout. +# $1+: message +log () { + if [ "$_VERBOSE" -ge 1 ]; then + printf "%s\n" "$*" + fi +} + +_RUN_LOG= + +# Set a run log file that can be used to collect the output of commands that +# are not displayed. +set_run_log () { + _RUN_LOG=$1 +} + +# Run a command. Output depends on $_VERBOSE: +# $_VERBOSE <= 0: Run command, store output into the run log +# $_VERBOSE >= 1: Dump command, run it, output goest to stdout +# Note: Ideally, the command's output would go to the run log for $_VERBOSE >= 1 +# but the 'tee' tool doesn't preserve the status code of its input pipe +# in case of error. +run () { + local LOGILE + if [ "$_RUN_LOG" ]; then + LOGFILE=$_RUN_LOG + else + LOGFILE=/dev/null + fi + + if [ "$_VERBOSE" -ge 1 ]; then + echo "COMMAND: $@" + "$@" + else + "$@" >>$LOGFILE 2>&1 + fi +} + +# Same as run(), but only dump command output for $_VERBOSE >= 2 +run2 () { + local LOGILE + if [ "$_RUN_LOG" ]; then + LOGFILE=$_RUN_LOG + else + LOGFILE=/dev/null + fi + + if [ "$_VERBOSE" -ge 1 ]; then + echo "COMMAND: $@" + fi + if [ "$_VERBOSE" -ge 2 ]; then + "$@" + else + "$@" >>$LOGFILE 2>&1 + fi +} + +# Extract number of cores to speed up the builds +# Out: number of CPU cores +get_core_count () { + case $(uname -s) in + Linux) + grep -c -e '^processor' /proc/cpuinfo + ;; + Darwin) + sysctl -n hw.ncpu + ;; + CYGWIN*|*_NT-*) + echo $NUMBER_OF_PROCESSORS + ;; + *) + echo 1 + ;; + esac +} + + +# Check for the Android ADB program. +# +# On success, return nothing, but updates internal variables so later calls to +# adb_shell, adb_push, etc.. will work. You can get the path to the ADB program +# with adb_get_program if needed. +# +# On failure, returns 1, and updates the internal adb error message, which can +# be retrieved with adb_get_error. +# +# $1: optional ADB program path. +# Return: success or failure. +_ADB= +_ADB_STATUS= +_ADB_ERROR= + +adb_check () { + # First, try to find the executable in the path, or the SDK install dir. + _ADB=$1 + if [ -z "$_ADB" ]; then + _ADB=$(which adb 2>/dev/null) + if [ -z "$_ADB" -a "$ANDROID_SDK_ROOT" ]; then + _ADB=$ANDROID_SDK_ROOT/platform-tools/adb + if [ ! -f "$_ADB" ]; then + _ADB= + fi + fi + if [ -z "$_ADB" ]; then + _ADB_STATUS=1 + _ADB_ERROR="The Android 'adb' tool is not in your path." + return 1 + fi + fi + + log "Found ADB program: $_ADB" + + # Check that it works correctly + local ADB_VERSION + ADB_VERSION=$("$_ADB" version 2>/dev/null) + case $ADB_VERSION in + "Android Debug Bridge "*) # Pass + log "Found ADB version: $ADB_VERSION" + ;; + *) # Fail + _ADB_ERROR="Your ADB binary reports a bad version ($ADB_VERSION): $_ADB" + _ADB_STATUS=1 + return 1 + esac + + _ADB_STATUS=0 + return 0 +} + + +# Return the path to the Android ADB program, if correctly detected. +# On failure, return the empty string. +# Out: ADB program path (or empty on failure) +# Return: success or failure. +adb_get_program () { + # Return cached value as soon as possible. + if [ -z "$_ADB_STATUS" ]; then + adb_check $1 + fi + echo "$_ADB" + return $_ADB_STATUS +} + +# Return the error corresponding to the last ADB function failure. +adb_get_error () { + echo "$_ADB_ERROR" +} + +# Check that there is one device connected through ADB. +# In case of failure, use adb_get_error to know why this failed. +# $1: Optional adb program path +# Return: success or failure. +_ADB_DEVICE= +_ADB_DEVICE_STATUS= +adb_check_device () { + if [ "$_ADB_DEVICE_STATUS" ]; then + return $_ADB_DEVICE_STATUS + fi + + # Check for ADB. + if ! adb_check $1; then + _ADB_DEVICE_STATUS=$_ADB_STATUS + return 1 + fi + + local ADB_DEVICES NUM_DEVICES FINGERPRINT + + # Count the number of connected devices. + ADB_DEVICES=$("$_ADB" devices 2>/dev/null | awk '$2 == "device" { print $1; }') + NUM_DEVICES=$(echo "$ADB_DEVICES" | wc -l) + case $NUM_DEVICES in + 0) + _ADB_ERROR="No Android device connected. Please connect one to your machine." + _ADB_DEVICE_STATUS=1 + return 1 + ;; + 1) # Pass + # Ensure the same device will be called in later adb_shell calls. + export ANDROID_SERIAL=$ADB_DEVICES + ;; + *) # 2 or more devices. + if [ "$ANDROID_SERIAL" ]; then + ADB_DEVICES=$ANDROID_SERIAL + NUM_DEVICES=1 + else + _ADB_ERROR="More than one Android device connected. \ +Please define ANDROID_SERIAL in your environment" + _ADB_DEVICE_STATUS=1 + return 1 + fi + ;; + esac + + _ADB_DEVICE_STATUS=0 + _ADB_DEVICE=$ADB_DEVICES + + FINGERPRINT=$(adb_shell getprop ro.build.fingerprint) + log "Using ADB device: $ANDROID_SERIAL ($FINGERPRINT)" + return 0 +} + +# The 'adb shell' command is pretty hopeless, try to make sense of it by: +# 1/ Removing trailing \r from line endings. +# 2/ Ensuring the function returns the command's status code. +# +# $1+: Command +# Out: command output (stdout + stderr combined) +# Return: command exit status +adb_shell () { + local RET ADB_LOG + # Check for ADB device. + adb_check_device || return 1 + ADB_LOG=$(mktemp "${TMPDIR:-/tmp}/adb-XXXXXXXX") + "$_ADB" shell "$@" ";" echo \$? > "$ADB_LOG" 2>&1 + sed -i -e 's![[:cntrl:]]!!g' "$ADB_LOG" # Remove \r. + RET=$(sed -e '$!d' "$ADB_LOG") # Last line contains status code. + sed -e '$d' "$ADB_LOG" # Print everything except last line. + rm -f "$ADB_LOG" + return $RET +} + +# Push a file to a device. +# $1: source file path +# $2: device target file path +# Return: success or failure. +adb_push () { + adb_check_device || return 1 + run "$_ADB" push "$1" "$2" +} + +# Pull a file from a device +# $1: device file path +# $2: target host file path +# Return: success or failure. +adb_pull () { + adb_check_device || return 1 + run "$_ADB" pull "$1" "$2" +} + +# Same as adb_push, but will panic if the operations didn't succeed. +adb_install () { + adb_push "$@" + fail_panic "Failed to install $1 to the Android device at $2" +} + diff --git a/toolkit/crashreporter/google-breakpad/android/google_breakpad/Android.mk b/toolkit/crashreporter/google-breakpad/android/google_breakpad/Android.mk new file mode 100644 index 0000000000..8618492774 --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/google_breakpad/Android.mk @@ -0,0 +1,104 @@ +# Copyright (c) 2012, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# ndk-build module definition for the Google Breakpad client library +# +# To use this file, do the following: +# +# 1/ Include this file from your own Android.mk, either directly +# or with through the NDK's import-module function. +# +# 2/ Use the client static library in your project with: +# +# LOCAL_STATIC_LIBRARIES += breakpad_client +# +# 3/ In your source code, include "src/client/linux/exception_handler.h" +# and use the Linux instructions to use it. +# +# This module works with either the STLport or GNU libstdc++, but you need +# to select one in your Application.mk +# + +# The top Google Breakpad directory. +# We assume this Android.mk to be under 'android/google_breakpad' + +LOCAL_PATH := $(call my-dir)/../.. + +# Defube the client library module, as a simple static library that +# exports the right include path / linker flags to its users. + +include $(CLEAR_VARS) + +LOCAL_MODULE := breakpad_client + +LOCAL_CPP_EXTENSION := .cc + +# Breakpad uses inline ARM assembly that requires the library +# to be built in ARM mode. Otherwise, the build will fail with +# cryptic assembler messages like: +# Compile++ thumb : google_breakpad_client <= crash_generation_client.cc +# /tmp/cc8aMSoD.s: Assembler messages: +# /tmp/cc8aMSoD.s:132: Error: invalid immediate: 288 is out of range +# /tmp/cc8aMSoD.s:244: Error: invalid immediate: 296 is out of range +LOCAL_ARM_MODE := arm + +# List of client source files, directly taken from Makefile.am +LOCAL_SRC_FILES := \ + src/client/linux/crash_generation/crash_generation_client.cc \ + src/client/linux/dump_writer_common/thread_info.cc \ + src/client/linux/dump_writer_common/ucontext_reader.cc \ + src/client/linux/handler/exception_handler.cc \ + src/client/linux/handler/minidump_descriptor.cc \ + src/client/linux/log/log.cc \ + src/client/linux/microdump_writer/microdump_writer.cc \ + src/client/linux/minidump_writer/linux_dumper.cc \ + src/client/linux/minidump_writer/linux_ptrace_dumper.cc \ + src/client/linux/minidump_writer/minidump_writer.cc \ + src/client/minidump_file_writer.cc \ + src/common/convert_UTF.cc \ + src/common/md5.cc \ + src/common/string_conversion.cc \ + src/common/linux/breakpad_getcontext.S \ + src/common/linux/elfutils.cc \ + src/common/linux/file_id.cc \ + src/common/linux/guid_creator.cc \ + src/common/linux/linux_libc_support.cc \ + src/common/linux/memory_mapped_file.cc \ + src/common/linux/safe_readlink.cc + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/src/common/android/include \ + $(LOCAL_PATH)/src \ + $(LSS_PATH) + +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) +LOCAL_EXPORT_LDLIBS := -llog + +include $(BUILD_STATIC_LIBRARY) + +# Done. diff --git a/toolkit/crashreporter/google-breakpad/android/run-checks.sh b/toolkit/crashreporter/google-breakpad/android/run-checks.sh new file mode 100755 index 0000000000..51d2d50231 --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/run-checks.sh @@ -0,0 +1,555 @@ +#!/bin/sh +# Copyright (c) 2012 Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Sanitize the environment +export LANG=C +export LC_ALL=C + +if [ "$BASH_VERSION" ]; then + set -o posix +fi + +PROGDIR=$(dirname "$0") +PROGDIR=$(cd "$PROGDIR" && pwd) +PROGNAME=$(basename "$0") + +. $PROGDIR/common-functions.sh + +DEFAULT_ABI="armeabi" +VALID_ABIS="armeabi armeabi-v7a x86 mips" + +ABI= +ADB= +ALL_TESTS= +ENABLE_M32= +HELP= +HELP_ALL= +NDK_DIR= +NO_CLEANUP= +NO_DEVICE= +NUM_JOBS=$(get_core_count) +TMPDIR= + +for opt do + # The following extracts the value if the option is like --name=<value>. + optarg=$(expr -- $opt : '^--[^=]*=\(.*\)$') + case $opt in + --abi=*) ABI=$optarg;; + --adb=*) ADB=$optarg;; + --all-tests) ALL_TESTS=true;; + --enable-m32) ENABLE_M32=true;; + --help|-h|-?) HELP=TRUE;; + --help-all) HELP_ALL=true;; + --jobs=*) NUM_JOBS=$optarg;; + --ndk-dir=*) NDK_DIR=$optarg;; + --tmp-dir=*) TMPDIR=$optarg;; + --no-cleanup) NO_CLEANUP=true;; + --no-device) NO_DEVICE=true;; + --quiet) decrease_verbosity;; + --verbose) increase_verbosity;; + -*) panic "Invalid option '$opt', see --help for details.";; + *) panic "This script doesn't take any parameters. See --help for details." + ;; + esac +done + +if [ "$HELP" -o "$HELP_ALL" ]; then + echo "\ + Usage: $PROGNAME [options] + + This script is used to check that your Google Breakpad source tree can + be properly built for Android, and that the client library and host tools + work properly together. +" + if [ "$HELP_ALL" ]; then + echo "\ + In more details, this script will: + + - Rebuild the host version of Google Breakpad in a temporary + directory (with the Auto-tools based build system). + + - Rebuild the Android client library with the Google Breakpad build + system (using autotools/configure). This requires that you define + ANDROID_NDK_ROOT in your environment to point to a valid Android NDK + installation directory, or use the --ndk-dir=<path> option. + + - Rebuild the Android client library and a test crashing program with the + Android NDK build system (ndk-build). + + - Require an Android device connected to your machine, and the 'adb' + tool in your path. They are used to: + + - Install and run a test crashing program. + - Extract the corresponding minidump from the device. + - Dump the symbols from the test program on the host with 'dump_syms' + - Generate a stack trace with 'minidump_stackwalk' + - Check the stack trace content for valid source file locations. + + You can however skip this requirement and only test the builds by using + the --no-device flag. + + By default, all generated files will be created in a temporary directory + that is removed when the script completion. If you want to inspect the + files, use the --no-cleanup option. + + Finally, use --verbose to increase the verbosity level, this will help + you see which exact commands are being issues and their result. Use the + flag twice for even more output. Use --quiet to decrease verbosity + instead and run the script silently. + + If you have a device connected, the script will probe it to determine + its primary CPU ABI, and build the test program for it. You can however + use the --abi=<name> option to override this (this can be useful to check + the secondary ABI, e.g. using --abi=armeabi to check that such a program + works correctly on an ARMv7-A device). + + If you don't have a device connected, the test program will be built (but + not run) with the default '$DEFAULT_ABI' ABI. Again, you can use + --abi=<name> to override this. Valid ABI names are: + + $VALID_ABIS + + The script will only run the client library unit test on the device + by default. You can use --all-tests to also build and run the unit + tests for the Breakpad tools and processor, but be warned that this + adds several minutes of testing time. --all-tests will also run the + host unit tests suite. +" + + fi # HELP_ALL + + echo "\ + Valid options: + + --help|-h|-? Display this message. + --help-all Display extended help. + --enable-m32 Build 32-bit version of host tools. + --abi=<name> Specify target CPU ABI [auto-detected]. + --jobs=<count> Run <count> build tasks in parallel [$NUM_JOBS]. + --ndk-dir=<path> Specify NDK installation directory. + --tmp-dir=<path> Specify temporary directory (will be wiped-out). + --adb=<path> Specify adb program path. + --no-cleanup Don't remove temporary directory after completion. + --no-device Do not try to detect devices, nor run crash test. + --all-tests Run all unit tests (i.e. tools and processor ones too). + --verbose Increase verbosity. + --quiet Decrease verbosity." + + exit 0 +fi + +TESTAPP_DIR=$PROGDIR/sample_app + +# Select NDK install directory. +if [ -z "$NDK_DIR" ]; then + if [ -z "$ANDROID_NDK_ROOT" ]; then + panic "Please define ANDROID_NDK_ROOT in your environment, or use \ +--ndk-dir=<path>." + fi + NDK_DIR="$ANDROID_NDK_ROOT" + log "Found NDK directory: $NDK_DIR" +else + log "Using NDK directory: $NDK_DIR" +fi +# Small sanity check. +NDK_BUILD="$NDK_DIR/ndk-build" +if [ ! -f "$NDK_BUILD" ]; then + panic "Your NDK directory is not valid (missing ndk-build): $NDK_DIR" +fi + +# Ensure the temporary directory is deleted on exit, except if the --no-cleanup +# option is used. + +clean_tmpdir () { + if [ "$TMPDIR" ]; then + if [ -z "$NO_CLEANUP" ]; then + log "Cleaning up: $TMPDIR" + rm -rf "$TMPDIR" + else + dump "Temporary directory contents preserved: $TMPDIR" + fi + fi + exit "$@" +} + +atexit clean_tmpdir + +# If --tmp-dir=<path> is not used, create a temporary directory. +# Otherwise, start by cleaning up the user-provided path. +if [ -z "$TMPDIR" ]; then + TMPDIR=$(mktemp -d /tmp/$PROGNAME.XXXXXXXX) + fail_panic "Can't create temporary directory!" + log "Using temporary directory: $TMPDIR" +else + if [ ! -d "$TMPDIR" ]; then + mkdir -p "$TMPDIR" + fail_panic "Can't create temporary directory: $TMPDIR" + else + log "Cleaning up temporary directory: $TMPDIR" + rm -rf "$TMPDIR"/* + fail_panic "Cannot cleanup temporary directory!" + fi +fi + +if [ -z "$NO_DEVICE" ]; then + if ! adb_check_device $ADB; then + echo "$(adb_get_error)" + echo "Use --no-device to build the code without running any tests." + exit 1 + fi +fi + +BUILD_LOG="$TMPDIR/build.log" +RUN_LOG="$TMPDIR/run.log" +CRASH_LOG="$TMPDIR/crash.log" + +set_run_log "$RUN_LOG" + +TMPHOST="$TMPDIR/host-local" + +cd "$TMPDIR" + +# Build host version of the tools +dump "Building host binaries." +CONFIGURE_FLAGS= +if [ "$ENABLE_M32" ]; then + CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-m32" +fi +( + run mkdir "$TMPDIR/build-host" && + run cd "$TMPDIR/build-host" && + run2 "$PROGDIR/../configure" --prefix="$TMPHOST" $CONFIGURE_FLAGS && + run2 make -j$NUM_JOBS install +) +fail_panic "Can't build host binaries!" + +if [ "$ALL_TESTS" ]; then + dump "Running host unit tests." + ( + run cd "$TMPDIR/build-host" && + run2 make -j$NUM_JOBS check + ) + fail_panic "Host unit tests failed!!" +fi + +TMPBIN=$TMPHOST/bin + +# Generate a stand-alone NDK toolchain + +# Extract CPU ABI and architecture from device, if any. +if adb_check_device; then + DEVICE_ABI=$(adb_shell getprop ro.product.cpu.abi) + DEVICE_ABI2=$(adb_shell getprop ro.product.cpu.abi2) + if [ -z "$DEVICE_ABI" ]; then + panic "Can't extract ABI from connected device!" + fi + if [ "$DEVICE_ABI2" ]; then + dump "Found device ABIs: $DEVICE_ABI $DEVICE_ABI2" + else + dump "Found device ABI: $DEVICE_ABI" + DEVICE_ABI2=$DEVICE_ABI + fi + + # If --abi=<name> is used, check that the device supports it. + if [ "$ABI" -a "$DEVICE_ABI" != "$ABI" -a "$DEVICE_ABI2" != "$ABI" ]; then + dump "ERROR: Device ABI(s) do not match --abi command-line value ($ABI)!" + panic "Please use --no-device to skip device tests." + fi + + if [ -z "$ABI" ]; then + ABI=$DEVICE_ABI + dump "Using CPU ABI: $ABI (device)" + else + dump "Using CPU ABI: $ABI (command-line)" + fi +else + if [ -z "$ABI" ]; then + # No device connected, choose default ABI + ABI=$DEFAULT_ABI + dump "Using CPU ABI: $ABI (default)" + else + dump "Using CPU ABI: $ABI (command-line)" + fi +fi + +# Check the ABI value +VALID= +for VALID_ABI in $VALID_ABIS; do + if [ "$ABI" = "$VALID_ABI" ]; then + VALID=true + break + fi +done + +if [ -z "$VALID" ]; then + panic "Unknown CPU ABI '$ABI'. Valid values are: $VALID_ABIS" +fi + +# Extract architecture name from ABI +case $ABI in + armeabi*) ARCH=arm;; + *) ARCH=$ABI;; +esac + +# Extract GNU configuration name +case $ARCH in + arm) + GNU_CONFIG=arm-linux-androideabi + ;; + x86) + GNU_CONFIG=i686-linux-android + ;; + mips) + GNU_CONFIG=mipsel-linux-android + ;; + *) + GNU_CONFIG="$ARCH-linux-android" + ;; +esac + +# Generate standalone NDK toolchain installation +NDK_STANDALONE="$TMPDIR/ndk-$ARCH-toolchain" +echo "Generating NDK standalone toolchain installation" +mkdir -p "$NDK_STANDALONE" +# NOTE: The --platform=android-9 is required to provide <regex.h> for GTest. +run "$NDK_DIR/build/tools/make-standalone-toolchain.sh" \ + --arch="$ARCH" \ + --platform=android-9 \ + --install-dir="$NDK_STANDALONE" +fail_panic "Can't generate standalone NDK toolchain installation!" + +# Rebuild the client library, processor and tools with the auto-tools based +# build system. Even though it's not going to be used, this checks that this +# still works correctly. +echo "Building full Android binaries with configure/make" +TMPTARGET="$TMPDIR/target-local" +( + PATH="$NDK_STANDALONE/bin:$PATH" + run mkdir "$TMPTARGET" && + run mkdir "$TMPDIR"/build-target && + run cd "$TMPDIR"/build-target && + run2 "$PROGDIR"/../configure --prefix="$TMPTARGET" \ + --host="$GNU_CONFIG" && + run2 make -j$NUM_JOBS install +) +fail_panic "Could not rebuild Android binaries!" + +# Build and/or run unit test suite. +# If --no-device is used, only rebuild it, otherwise, run in on the +# connected device. +if [ "$NO_DEVICE" ]; then + ACTION="Building" + # This is a trick to force the Makefile to ignore running the scripts. + TESTS_ENVIRONMENT="TESTS_ENVIRONMENT=true" +else + ACTION="Running" + TESTS_ENVIRONMENT= +fi + +( + PATH="$NDK_STANDALONE/bin:$PATH" + run cd "$TMPDIR"/build-target && + # Reconfigure to only run the client unit test suite. + # This one should _never_ fail. + dump "$ACTION Android client library unit tests." + run2 "$PROGDIR"/../configure --prefix="$TMPTARGET" \ + --host="$GNU_CONFIG" \ + --disable-tools \ + --disable-processor && + run make -j$NUM_JOBS check $TESTS_ENVIRONMENT || exit $? + + if [ "$ALL_TESTS" ]; then + dump "$ACTION Tools and processor unit tests." + # Reconfigure to run the processor and tools tests. + # Most of these fail for now, so do not worry about it. + run2 "$PROGDIR"/../configure --prefix="$TMPTARGET" \ + --host="$GNU_CONFIG" && + run make -j$NUM_JOBS check $TESTS_ENVIRONMENT + if [ $? != 0 ]; then + dump "Tools and processor unit tests failed as expected. \ +Use --verbose for results." + fi + fi +) +fail_panic "Client library unit test suite failed!" + +# Copy sources to temporary directory +PROJECT_DIR=$TMPDIR/project +dump "Copying test program sources to: $PROJECT_DIR" +run cp -r "$TESTAPP_DIR" "$PROJECT_DIR" && +run rm -rf "$PROJECT_DIR/obj" && +run rm -rf "$PROJECT_DIR/libs" +fail_panic "Could not copy test program sources to: $PROJECT_DIR" + +# Build the test program with ndk-build. +dump "Building test program with ndk-build" +export NDK_MODULE_PATH="$PROGDIR" +NDK_BUILD_FLAGS="-j$NUM_JOBS" +if verbosity_is_higher_than 1; then + NDK_BUILD_FLAGS="$NDK_BUILD_FLAGS NDK_LOG=1 V=1" +fi +run "$NDK_DIR/ndk-build" -C "$PROJECT_DIR" $NDK_BUILD_FLAGS APP_ABI=$ABI +fail_panic "Can't build test program!" + +# Unless --no-device was used, stop right here if ADB isn't in the path, +# or there is no connected device. +if [ "$NO_DEVICE" ]; then + dump "Done. Please connect a device to run all tests!" + clean_exit 0 +fi + +# Push the program to the device. +TESTAPP=test_google_breakpad +TESTAPP_FILE="$PROJECT_DIR/libs/$ABI/test_google_breakpad" +if [ ! -f "$TESTAPP_FILE" ]; then + panic "Device requires '$ABI' binaries. None found!" +fi + +# Run the program there +dump "Installing test program on device" +DEVICE_TMP=/data/local/tmp +adb_push "$TESTAPP_FILE" "$DEVICE_TMP/" +fail_panic "Cannot push test program to device!" + +dump "Running test program on device" +adb_shell cd "$DEVICE_TMP" "&&" ./$TESTAPP > "$CRASH_LOG" 2>/dev/null +if [ $? = 0 ]; then + panic "Test program did *not* crash as expected!" +fi +if verbosity_is_higher_than 0; then + echo -n "Crash log: " + cat "$CRASH_LOG" +fi + +# Extract minidump from device +MINIDUMP_NAME=$(awk '$1 == "Dump" && $2 == "path:" { print $3; }' "$CRASH_LOG") +MINIDUMP_NAME=$(basename "$MINIDUMP_NAME") +if [ -z "$MINIDUMP_NAME" ]; then + panic "Test program didn't write minidump properly!" +fi + +dump "Extracting minidump: $MINIDUMP_NAME" +adb_pull "$DEVICE_TMP/$MINIDUMP_NAME" . +fail_panic "Can't extract minidump!" + +dump "Parsing test program symbols" +if verbosity_is_higher_than 1; then + log "COMMAND: $TMPBIN/dump_syms \ + $PROJECT_DIR/obj/local/$ABI/$TESTAPP >$TESTAPP.sym" +fi +"$TMPBIN/dump_syms" "$PROJECT_DIR/obj/local/$ABI/$TESTAPP" > $TESTAPP.sym +fail_panic "dump_syms doesn't work!" + +VERSION=$(awk '$1 == "MODULE" { print $4; }' $TESTAPP.sym) +dump "Found module version: $VERSION" +if [ -z "$VERSION" ]; then + echo "ERROR: Can't find proper module version from symbol dump!" + head -n5 $TESTAPP.sym + clean_exit 1 +fi + +run mkdir -p "$TMPDIR/symbols/$TESTAPP/$VERSION" +run mv $TESTAPP.sym "$TMPDIR/symbols/$TESTAPP/$VERSION/" + +dump "Generating stack trace" +# Don't use 'run' to be able to send stdout and stderr to two different files. +log "COMMAND: $TMPBIN/minidump_stackwalk $MINIDUMP_NAME symbols" +"$TMPBIN/minidump_stackwalk" $MINIDUMP_NAME \ + "$TMPDIR/symbols" \ + > "$BUILD_LOG" 2>>"$RUN_LOG" +fail_panic "minidump_stackwalk doesn't work!" + +dump "Checking stack trace content" + +if verbosity_is_higher_than 1; then + cat "$BUILD_LOG" +fi + +# The generated stack trace should look like the following: +# +# Thread 0 (crashed) +# 0 test_google_breakpad!crash [test_breakpad.cpp : 17 + 0x4] +# r4 = 0x00015530 r5 = 0xbea2cbe4 r6 = 0xffffff38 r7 = 0xbea2cb5c +# r8 = 0x00000000 r9 = 0x00000000 r10 = 0x00000000 fp = 0x00000000 +# sp = 0xbea2cb50 lr = 0x00009025 pc = 0x00008f84 +# Found by: given as instruction pointer in context +# 1 test_google_breakpad!main [test_breakpad.cpp : 25 + 0x3] +# r4 = 0x00015530 r5 = 0xbea2cbe4 r6 = 0xffffff38 r7 = 0xbea2cb5c +# r8 = 0x00000000 r9 = 0x00000000 r10 = 0x00000000 fp = 0x00000000 +# sp = 0xbea2cb50 pc = 0x00009025 +# Found by: call frame info +# 2 libc.so + 0x164e5 +# r4 = 0x00008f64 r5 = 0xbea2cc34 r6 = 0x00000001 r7 = 0xbea2cc3c +# r8 = 0x00000000 r9 = 0x00000000 r10 = 0x00000000 fp = 0x00000000 +# sp = 0xbea2cc18 pc = 0x400c34e7 +# Found by: call frame info +# ... +# +# The most important part for us is ensuring that the source location could +# be extracted, so look at the 'test_breakpad.cpp' references here. +# +# First, extract all the lines with test_google_breakpad! in them, and +# dump the corresponding crash location. +# +# Note that if the source location can't be extracted, the second field +# will only be 'test_google_breakpad' without the exclamation mark. +# +LOCATIONS=$(awk '$2 ~ "^test_google_breakpad!.*" { print $3; }' "$BUILD_LOG") + +if [ -z "$LOCATIONS" ]; then + if verbosity_is_lower_than 1; then + cat "$BUILD_LOG" + fi + panic "No source location found in stack trace!" +fi + +# Now check that they all match "[<source file>" +BAD_LOCATIONS= +for LOCATION in $LOCATIONS; do + case $LOCATION in + # Escape the opening bracket, or some shells like Dash will not + # match them properly. + \[*.cpp|\[*.cc|\[*.h) # These are valid source locations in our executable + ;; + *) # Everything else is not! + BAD_LOCATIONS="$BAD_LOCATIONS $LOCATION" + ;; + esac +done + +if [ "$BAD_LOCATIONS" ]; then + dump "ERROR: Generated stack trace doesn't contain valid source locations:" + cat "$BUILD_LOG" + echo "Bad locations are: $BAD_LOCATIONS" + exit 1 +fi + +echo "All clear! Congratulations." + diff --git a/toolkit/crashreporter/google-breakpad/android/sample_app/README b/toolkit/crashreporter/google-breakpad/android/sample_app/README new file mode 100644 index 0000000000..aa19dbb447 --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/sample_app/README @@ -0,0 +1,32 @@ +This is a sample Android executable that can be used to test the +Google Breakpad client library on Android. + +Its purpose is simply to crash and generate a minidump under /data/local/tmp. + +Build instructions: + + cd android/sample_app + $NDK/ndk-build + + Where $NDK points to a valid Android NDK installation. + +Usage instructions: + + After buildind the test program, send it to a device, then run it as + the shell UID: + + adb push libs/armeabi/test_google_breakpad /data/local/tmp + adb shell /data/local/tmp/test_google_breakpad + + This will simply crash after dumping the name of the generated minidump + file. + + See jni/test_breakpad.cpp for details. + + Use 'armeabi-v7a' instead of 'armeabi' above to test the ARMv7-A version + of the binary. + +Note: + If you plan to use the library in a regular Android application, store + the minidump files either to your app-specific directory, or to the SDCard + (the latter requiring a specific permission). diff --git a/toolkit/crashreporter/google-breakpad/android/sample_app/jni/Android.mk b/toolkit/crashreporter/google-breakpad/android/sample_app/jni/Android.mk new file mode 100644 index 0000000000..61487b52c1 --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/sample_app/jni/Android.mk @@ -0,0 +1,44 @@ +# Copyright (c) 2012, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := test_google_breakpad +LOCAL_SRC_FILES := test_breakpad.cpp +LOCAL_STATIC_LIBRARIES += breakpad_client +include $(BUILD_EXECUTABLE) + +# If NDK_MODULE_PATH is defined, import the module, otherwise do a direct +# includes. This allows us to build in all scenarios easily. +ifneq ($(NDK_MODULE_PATH),) + $(call import-module,google_breakpad) +else + include $(LOCAL_PATH)/../../google_breakpad/Android.mk +endif diff --git a/toolkit/crashreporter/google-breakpad/android/sample_app/jni/Application.mk b/toolkit/crashreporter/google-breakpad/android/sample_app/jni/Application.mk new file mode 100644 index 0000000000..9728017d3f --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/sample_app/jni/Application.mk @@ -0,0 +1,32 @@ +# Copyright (c) 2012, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +APP_STL := stlport_static +APP_ABI := all +APP_CXXFLAGS := -std=c++11 -D__STDC_LIMIT_MACROS diff --git a/toolkit/crashreporter/google-breakpad/android/sample_app/jni/test_breakpad.cpp b/toolkit/crashreporter/google-breakpad/android/sample_app/jni/test_breakpad.cpp new file mode 100644 index 0000000000..9c4ebbb148 --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/sample_app/jni/test_breakpad.cpp @@ -0,0 +1,57 @@ +// Copyright (c) 2012, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <stdio.h> + +#include "client/linux/handler/exception_handler.h" +#include "client/linux/handler/minidump_descriptor.h" + +namespace { + +bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, + void* context, + bool succeeded) { + printf("Dump path: %s\n", descriptor.path()); + return succeeded; +} + +void Crash() { + volatile int* a = reinterpret_cast<volatile int*>(NULL); + *a = 1; +} + +} // namespace + +int main(int argc, char* argv[]) { + google_breakpad::MinidumpDescriptor descriptor("."); + google_breakpad::ExceptionHandler eh(descriptor, NULL, DumpCallback, + NULL, true, -1); + Crash(); + return 0; +} diff --git a/toolkit/crashreporter/google-breakpad/android/test-driver b/toolkit/crashreporter/google-breakpad/android/test-driver new file mode 100755 index 0000000000..eaaac6b295 --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/test-driver @@ -0,0 +1,131 @@ +#! /bin/sh +# test-driver - basic testsuite driver script. + +# Slightly modified for Android, see ANDROID comment below. + +scriptversion=2012-06-27.10; # UTC + +# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to <bug-automake@gnu.org> or send patches to +# <automake-patches@gnu.org>. + +# Make unconditional expansion of undefined variables an error. This +# helps a lot in preventing typo-related bugs. +set -u + +usage_error () +{ + echo "$0: $*" >&2 + print_usage >&2 + exit 2 +} + +print_usage () +{ + cat <<END +Usage: + test-driver --test-name=NAME --log-file=PATH --trs-file=PATH + [--expect-failure={yes|no}] [--color-tests={yes|no}] + [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT +The '--test-name', '--log-file' and '--trs-file' options are mandatory. +END +} + +# TODO: better error handling in option parsing (in particular, ensure +# TODO: $log_file, $trs_file and $test_name are defined). +test_name= # Used for reporting. +log_file= # Where to save the output of the test script. +trs_file= # Where to save the metadata of the test run. +expect_failure=no +color_tests=no +enable_hard_errors=yes +while test $# -gt 0; do + case $1 in + --help) print_usage; exit $?;; + --version) echo "test-driver $scriptversion"; exit $?;; + --test-name) test_name=$2; shift;; + --log-file) log_file=$2; shift;; + --trs-file) trs_file=$2; shift;; + --color-tests) color_tests=$2; shift;; + --expect-failure) expect_failure=$2; shift;; + --enable-hard-errors) enable_hard_errors=$2; shift;; + --) shift; break;; + -*) usage_error "invalid option: '$1'";; + esac + shift +done + +if test $color_tests = yes; then + # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. + red='[0;31m' # Red. + grn='[0;32m' # Green. + lgn='[1;32m' # Light green. + blu='[1;34m' # Blue. + mgn='[0;35m' # Magenta. + std='[m' # No color. +else + red= grn= lgn= blu= mgn= std= +fi + +do_exit='rm -f $log_file $trs_file; (exit $st); exit $st' +trap "st=129; $do_exit" 1 +trap "st=130; $do_exit" 2 +trap "st=141; $do_exit" 13 +trap "st=143; $do_exit" 15 + +# Test script is run here. +# ANDROID: old line was: "$@" > $log_file 2>&1 +progdir=$(dirname "$0") +"$progdir/test-shell.sh" "$@" > $log_file 2>&1 +estatus=$? +if test $enable_hard_errors = no && test $estatus -eq 99; then + estatus=1 +fi + +case $estatus:$expect_failure in + 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; + 0:*) col=$grn res=PASS recheck=no gcopy=no;; + 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; + 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; + *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; + *:*) col=$red res=FAIL recheck=yes gcopy=yes;; +esac + +# Report outcome to console. +echo "${col}${res}${std}: $test_name" + +# Register the test result, and other relevant metadata. +echo ":test-result: $res" > $trs_file +echo ":global-test-result: $res" >> $trs_file +echo ":recheck: $recheck" >> $trs_file +echo ":copy-in-global-log: $gcopy" >> $trs_file + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff --git a/toolkit/crashreporter/google-breakpad/android/test-shell.sh b/toolkit/crashreporter/google-breakpad/android/test-shell.sh new file mode 100755 index 0000000000..3677d8755a --- /dev/null +++ b/toolkit/crashreporter/google-breakpad/android/test-shell.sh @@ -0,0 +1,131 @@ +#!/bin/sh +# +# Copyright (c) 2012 Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# A special shell wrapper that can be used to run the Google Breakpad unit +# tests on a connected Android device. +# +# This is designed to be called from the Makefile during 'make check' +# + +PROGDIR=$(dirname "$0") +PROGNAME=$(basename "$0") +. $PROGDIR/common-functions.sh + +# Extract test program name first. +TEST_PROGRAM=$1 +shift + +if [ -z "$TEST_PROGRAM" ]; then + panic "No test program/script name on the command-line!" +fi + +if [ ! -f "$TEST_PROGRAM" ]; then + panic "Can't find test program/script: $TEST_PROGRAM" +fi + +# Create test directory on the device +TEST_DIR=/data/local/tmp/test-google-breakpad-$$ +adb_shell mkdir "$TEST_DIR" || + panic "Can't create test directory on device: $TEST_DIR" + +# Ensure that it is always removed when the script exits. +clean_test_dir () { + # Don't care about success/failure, use '$ADB shell' directly. + adb_shell rm -r "$TEST_DIR" +} + +atexit clean_test_dir + +TEST_PROGRAM_NAME=$(basename "$TEST_PROGRAM") +TEST_PROGRAM_DIR=$(dirname "$TEST_PROGRAM") + +# Handle special case(s) here. +DATA_FILES= +case $TEST_PROGRAM_NAME in + linux_client_unittest) + # linux_client_unittest will call another executable at runtime, ensure + # it is installed too. + adb_install "$TEST_PROGRAM_DIR/linux_dumper_unittest_helper" "$TEST_DIR" + # linux_client_unittest loads a shared library at runtime, ensure it is + # installed too. + adb_install "$TEST_PROGRAM_DIR/linux_client_unittest_shlib" "$TEST_DIR" + ;; + basic_source_line_resolver_unittest) + DATA_FILES="module1.out \ + module2.out \ + module3_bad.out \ + module4_bad.out" + ;; + exploitability_unittest) + DATA_FILES="scii_read_av.dmp \ + ascii_read_av_block_write.dmp \ + ascii_read_av_clobber_write.dmp \ + ascii_read_av_conditional.dmp \ + ascii_read_av_non_null.dmp \ + ascii_read_av_then_jmp.dmp \ + ascii_read_av_xchg_write.dmp \ + ascii_write_av.dmp \ + ascii_write_av_arg_to_call.dmp \ + exec_av_on_stack.dmp \ + null_read_av.dmp \ + null_write_av.dmp \ + read_av.dmp \ + null_read_av.dmp \ + write_av_non_null.dmp" + ;; + fast_source_line_resolver_unittest) + DATA_FILES="module0.out \ + module1.out \ + module2.out \ + module3_bad.out \ + module4_bad.out" + ;; + minidump_processor_unittest|minidump_unittest) + DATA_FILES="src/processor/testdata/minidump2.dmp" + ;; +esac + +# Install the data files, their path is relative to the environment +# variable 'srcdir' +for FILE in $DATA_FILES; do + FILEDIR=src/processor/testdata/$(dirname "$FILE") + adb_shell mkdir -p "$TEST_DIR/$FILEDIR" + adb_install "${srcdir:-.}/$FILE" "$TEST_DIR"/"$FILE" +done + +# Copy test program to device +adb_install "$TEST_PROGRAM" "$TEST_DIR" + +# Run it +adb_shell "cd $TEST_DIR && LD_LIBRARY_PATH=. ./$TEST_PROGRAM_NAME $@" + +# Note: exiting here will call cleanup_exit which will remove the temporary +# files from the device. |