diff options
author | Cassidy Burden <cburden@google.com> | 2016-08-09 11:17:10 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-12 15:04:11 -0700 |
commit | b217c8a28be52f90572d26647d38dcfc9e08ce0b (patch) | |
tree | d0a61067a1b176f4243351455c5abd39c3cec1f0 /binary_search_tool/ndk/DO_BISECTION.sh | |
parent | a19ea38e4482af3bc98365be773305b5167eddfd (diff) | |
download | toolchain-utils-b217c8a28be52f90572d26647d38dcfc9e08ce0b.tar.gz |
binary search tool: Add sample NDK bisection
Add sample NDK bisection that can be given to those inside or outside of
Google. This sample includes a compressed source tree of the Teapot
sample NDK app, and a script showing the full setup and process for
running the bisection tool. It also includes a couple patches that show
the necessary changes to the build system, and the "compiler error" that
we will be bisecting.
TEST=Run DO_BISECTION.sh
Change-Id: I11279fe33e833b0dfe2fb147fde6f46b347d62be
Reviewed-on: https://chrome-internal-review.googlesource.com/274145
Commit-Ready: Cassidy Burden <cburden@google.com>
Tested-by: Cassidy Burden <cburden@google.com>
Reviewed-by: Luis Lozano <llozano@chromium.org>
Diffstat (limited to 'binary_search_tool/ndk/DO_BISECTION.sh')
-rwxr-xr-x | binary_search_tool/ndk/DO_BISECTION.sh | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/binary_search_tool/ndk/DO_BISECTION.sh b/binary_search_tool/ndk/DO_BISECTION.sh new file mode 100755 index 00000000..298d5747 --- /dev/null +++ b/binary_search_tool/ndk/DO_BISECTION.sh @@ -0,0 +1,92 @@ +#!/bin/bash +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# This is an example script to show users the steps for bisecting an NDK +# application for Android. Our example is the Teapot app that comes bundled with +# the NDK as a sample app. +# +# Our Teapot app only has 12 or so object files generated per build. Bisection +# for just 12 object files is overkill, but this bisection process easily scales +# to thousands of object files (as seen with the Android source). +# +# Setup: +# 1. Install NDK (make sure it is in your PATH) +# 2. Install compiler_wrapper.py +# 3. Connect an arm7 device (tested with Nexus 5X) +# a. See README for supporting other device archs +# +# Tested in bash on Linux. + +# Set CWD to where this script lives +pushd "$(dirname "$0")" + +# If Teapot dir already exists remove it. +if [[ -d Teapot ]]; then + rm -rf Teapot +fi + +# Unzip our repository we'll be testing with. +tar -xzf Teapot.tar.gz + +# Apply small setup patch. This patch makes a small change to the build system +# to make this bisecting example a little easier. It inserts the option to only +# build for an arm7. See the patch file for details. +# (This patch file was generated with git, -p1 will remove the a/ and b/) +patch -p1 -i PATCH1 + +# We want all of our cached files to be stored in ~/NDK_EXAMPLE_BISECT +# Remove directory if already exists +export BISECT_DIR=~/NDK_EXAMPLE_BISECT +if [[ -d ${BISECT_DIR} ]]; then + rm -rf ${BISECT_DIR} +fi + +# We will now take our normal "good compiler" and do a full build of the app. We +# need to clean before building. This ensures that all objects are generated and +# can be cached. +pushd Teapot +export BISECT_STAGE=POPULATE_GOOD +./gradlew clean +./gradlew installArm7Debug +popd + +# Inserting "compiler error". Really this is just a patch that inserts a simple +# error in the code, but this is used to simulate our compiler error. This patch +# will simply cause the app to crash as soon as it starts. See the patch file +# for details. +# (This patch file was generated with git, -p1 will remove the a/ and b/) +patch -p1 -i PATCH2 + +# Now that we have installed our bad compiler (i.e. applied the above patch that +# acts like a compiler error), we want to enumerate and cache all objects +# generated by this "bad compiler". So again, we clean the build tree so that +# all objects are regenerated and can be cached. +pushd Teapot +export BISECT_STAGE=POPULATE_BAD +./gradlew clean +./gradlew installArm7Debug +popd + +# Now ~/NDK_EXAMPLE_BISECT holds the caches for both good and bad compiler +# outputs. We will now use these to bisect our problem. We should find that +# TeapotRenderer.o is the bad file (because this is where PATCH2 inserted the +# "compiler error"). + +# Tell the compiler wrapper to not cache outputs, and instead begin bisecting. +export BISECT_STAGE=TRIAGE + +# Run the actual bisection tool. This will automatically narrow down which +# object file has the error. The test_setup.sh script will rebuild our app +# with gradle, and boot_test.sh will ping the device to see if the app crashed +# or not. +cd .. +./binary_search_state.py \ + --get_initial_items=ndk/get_initial_items.sh \ + --switch_to_good=ndk/switch_to_good.sh \ + --switch_to_bad=ndk/switch_to_bad.sh \ + --test_setup_script=ndk/test_setup.sh \ + --test_script=ndk/boot_test.sh \ + --file_args + +popd |