blob: 298d5747c00f54cdeed921c68798e7c5e0a384fd [file] [log] [blame]
# 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
# 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
# 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
if [[ -d ${BISECT_DIR} ]]; then
rm -rf ${BISECT_DIR}
# 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
./gradlew clean
./gradlew installArm7Debug
# 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
./gradlew clean
./gradlew installArm7Debug
# 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.
# Run the actual bisection tool. This will automatically narrow down which
# object file has the error. The script will rebuild our app
# with gradle, and will ping the device to see if the app crashed
# or not.
cd ..
./ \
--get_initial_items=ndk/ \
--switch_to_good=ndk/ \
--switch_to_bad=ndk/ \
--test_setup_script=ndk/ \
--test_script=ndk/ \