diff options
author | Cassidy Burden <cburden@google.com> | 2016-06-30 15:24:20 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-07-01 11:58:13 -0700 |
commit | c4671bdd601ff945b2cccbfe1aee9f931dc908c7 (patch) | |
tree | 4cdec6fd367b6f8a9162f4c56f18d3232a494b63 | |
parent | 63f13489b1a02bbbc75b46fec6ae7a817442df94 (diff) | |
download | toolchain-utils-c4671bdd601ff945b2cccbfe1aee9f931dc908c7.tar.gz |
binary search tool: (Refactor) Extract common scripts into common folder
Refactor warning! Move install.sh, boot_test.sh, and interactive_test.sh
into common folder so they can be shared by both package and object
bisectors. To allow this sharing, sysroot_wrapper now has a setup script
similar to cros_pkg. All scripts now source common/common.sh.
TEST=Run unit tests, run system tests, run couple iterations of install
script for both bisectors.
Change-Id: I9e164b4e6b842ff321c2400201e6ac0984f99088
Reviewed-on: https://chrome-internal-review.googlesource.com/268027
Commit-Ready: Cassidy Burden <cburden@google.com>
Tested-by: Cassidy Burden <cburden@google.com>
Reviewed-by: Caroline Tice <cmtice@google.com>
25 files changed, 352 insertions, 410 deletions
diff --git a/binary_search_tool/bisect.py b/binary_search_tool/bisect.py index 8e454f62..4ce87cd2 100755 --- a/binary_search_tool/bisect.py +++ b/binary_search_tool/bisect.py @@ -168,7 +168,8 @@ class BisectPackage(Bisector): class BisectObject(Bisector): """The class for object bisection steps.""" - sysroot_wrapper_files = ['bad/_LIST', 'good/_LIST'] + sysroot_wrapper_setup = 'sysroot_wrapper/setup.sh' + sysroot_wrapper_cleanup = 'sysroot_wrapper/cleanup.sh' def __init__(self, options, overrides): super(BisectObject, self).__init__(options, overrides) @@ -191,22 +192,25 @@ class BisectObject(Bisector): self.ArgOverride(self.default_kwargs, overrides) def PreRun(self): - for f in self.sysroot_wrapper_files: - full_path = os.path.join(self.options.dir, f) - if not os.path.exists(full_path): - self.logger.LogError('Object bisector setup failed, %s does not exist' % - full_path) - return 1 - - os.environ['BISECT_BOARD'] = self.options.board - os.environ['BISECT_REMOTE'] = self.options.remote - os.environ['BISECT_PACKAGE'] = self.options.package + cmd = ('%s %s %s %s' % (self.sysroot_wrapper_setup, self.options.board, + self.options.remote, self.options.package)) + ret, _, _ = self.ce.RunCommandWExceptionCleanup(cmd, print_to_console=True) + if ret: + self.logger.LogError('Object bisector setup failed w/ error %d' % ret) + return 1 + + os.environ['BISECT_STAGE'] = 'TRIAGE' return 0 def Run(self): return binary_search_state.Run(**self.default_kwargs) def PostRun(self): + cmd = self.sysroot_wrapper_cleanup + ret, _, _ = self.ce.RunCommandWExceptionCleanup(cmd, print_to_console=True) + if ret: + self.logger.LogError('Object bisector cleanup failed w/ error %d' % ret) + return 1 return 0 diff --git a/binary_search_tool/common/boot_test.sh b/binary_search_tool/common/boot_test.sh new file mode 100755 index 00000000..f58c345b --- /dev/null +++ b/binary_search_tool/common/boot_test.sh @@ -0,0 +1,22 @@ +#!/bin/bash -u +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# This script pings the chromebook to determine if it has successfully booted. +# +# This script is intended to be used by binary_search_state.py, as +# part of the binary search triage on ChromeOS package and object files. +# It waits for the install script to build and install the image, then pings the +# machine. It should return '0' if the test succeeds (the image booted); '1' if +# the test fails (the image did not boot); and '2' if it could not determine +# (does not apply in this case). +# + +source common/common.sh + +# Send 3 pings and wait 3 seconds for any responsed (then timeout). +ping -c 3 -W 3 ${BISECT_REMOTE} +retval=$? + + +exit $retval diff --git a/binary_search_tool/common/install.sh b/binary_search_tool/common/install.sh new file mode 100755 index 00000000..f1aff40c --- /dev/null +++ b/binary_search_tool/common/install.sh @@ -0,0 +1,164 @@ +#!/bin/bash +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# This is a generic ChromeOS package/image installation script. It is meant to +# be used for either the object file or package bisection tools. This script +# does one of the following depending on what ${BISECT_MODE} is set to: +# +# 1) ${BISECT_MODE} is PACKAGE_MODE: +# build_image is called and generates a new ChromeOS image using whatever +# packages are currently in the build tree. This image is then pushed to the +# remote machine using flash over ethernet (or usb flash if ethernet flash +# fails). +# +# 2) ${BISECT_MODE} is OBJECT_MODE: +# emerge is called for ${BISECT_PACKAGE} and generates a build for said +# package. This package is then deployed to the remote machine and the machine +# is rebooted. If deploying fails then a new ChromeOS image is built from +# scratch and pushed to the machine like in PACKAGE_MODE. +# +# This script is intended to be used by binary_search_state.py, as +# part of the binary search triage on ChromeOS objects and packages. It should +# return '0' if the install succeeds; and '1' if the install fails (the image +# could not build or be flashed). +# + +export PYTHONUNBUFFERED=1 + +source common/common.sh + +usb_flash() +{ + echo + echo "Insert a usb stick into the current machine" + echo "Note: The cros flash will take time and doesn't give much output." + echo " Be patient. If your usb access light is flashing it's working." + sleep 1 + read -p "Press enter to continue" notused + + cros flash --board=${BISECT_BOARD} --clobber-stateful usb:// ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin + + echo + echo "Flash to usb complete!" + echo "Plug the usb into your chromebook and install the image." + echo "Refer to the ChromiumOS Developer's Handbook for more details." + echo "http://www.chromium.org/chromium-os/developer-guide#TOC-Boot-from-your-USB-disk" + while true; do + sleep 1 + read -p "Was the installation of the image successful? " choice + case $choice in + [Yy]*) return 0;; + [Nn]*) return 1;; + *) echo "Please answer y or n.";; + esac + done +} + +ethernet_flash() +{ + echo + echo "Please ensure your Chromebook is up and running Chrome so" + echo "cros flash may run." + echo "If your Chromebook has a broken image you can try:" + echo "1. Rebooting your Chromebook 6 times to install the last working image" + echo "2. Alternatively, running the following command on the Chromebook" + echo " will also rollback to the last working image:" + echo " 'update_engine_client --rollback --nopowerwash --reboot'" + echo "3. Flashing a new image through USB" + echo + sleep 1 + read -p $'Press enter to continue and retry the ethernet flash' notused + cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin +} + +reboot() +{ + ret_val=0 + pushd ~/trunk/src/scripts > /dev/null + set -- --remote=${BISECT_REMOTE} + . ./common.sh || ret_val=1 + . ./remote_access.sh || ret_val=1 + TMP=$(mktemp -d) + FLAGS "$@" || ret_val=1 + remote_access_init || ret_val=1 + remote_reboot || ret_val=1 + popd > /dev/null + + return $ret_val +} + +echo +echo "INSTALLATION BEGIN" +echo + +if [[ "${BISECT_MODE}" == "OBJECT_MODE" ]]; then + echo "EMERGING ${BISECT_PACKAGE}" + CLEAN_DELAY=0 emerge-${BISECT_BOARD} -C ${BISECT_PACKAGE} + emerge-${BISECT_BOARD} ${BISECT_PACKAGE} + emerge_status=$? + + if [[ ${emerge_status} -ne 0 ]] ; then + echo "emerging ${BISECT_PACKAGE} returned a non-zero status: $emerge_status" + exit 1 + fi + + echo + echo "DEPLOYING" + echo "cros deploy ${BISECT_REMOTE} ${BISECT_PACKAGE}" + cros deploy ${BISECT_REMOTE} ${BISECT_PACKAGE} --log-level=info + deploy_status=$? + + if [[ ${deploy_status} -eq 0 ]] ; then + echo "Deploy successful. Rebooting device..." + reboot + if [[ $? -ne 0 ]] ; then + echo + echo "Could not automatically reboot device!" + read -p "Please manually reboot device and press enter to continue" notused + fi + exit 0 + fi + + echo "Deploy failed! Trying build_image/cros flash instead..." + echo +fi + +echo "BUILDING IMAGE" +pushd ~/trunk/src/scripts +./build_image test --board=${BISECT_BOARD} --noenable_rootfs_verification --noeclean +build_status=$? +popd + +if [[ ${build_status} -eq 0 ]] ; then + echo + echo "FLASHING" + echo "Pushing built image onto device." + echo "cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin" + cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin + cros_flash_status=$? + while [[ ${cros_flash_status} -ne 0 ]] ; do + while true; do + echo + echo "cros flash has failed! From here you can:" + echo "1. Flash through USB" + echo "2. Retry flashing over ethernet" + echo "3. Abort this installation and skip this image" + sleep 1 + read -p "Which method would you like to do? " choice + case $choice in + 1) usb_flash && break;; + 2) ethernet_flash && break;; + 3) exit 1;; + *) echo "Please answer 1, 2, or 3.";; + esac + done + + cros_flash_status=$? + done +else + echo "build_image returned a non-zero status: ${build_status}" + exit 1 +fi + +exit 0 diff --git a/binary_search_tool/common/interactive_test.sh b/binary_search_tool/common/interactive_test.sh new file mode 100755 index 00000000..7005da36 --- /dev/null +++ b/binary_search_tool/common/interactive_test.sh @@ -0,0 +1,37 @@ +#!/bin/bash -u +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# This script pings the chromebook to determine if it successfully booted. +# It then asks the user if the image is good or not, allowing the user to +# conduct whatever tests the user wishes, and waiting for a response. +# +# This script is intended to be used by binary_search_state.py, as +# part of the binary search triage on ChromeOS package and object files. It +# waits for the install script to build and install the image, then asks the +# user if the image is good or not. It should return '0' if the test succeeds +# (the image is 'good'); '1' if the test fails (the image is 'bad'); and '2' if +# it could not determine (does not apply in this case). +# + +source common/common.sh + +ping -c 3 -W 3 ${BISECT_REMOTE} +retval=$? + +if [[ ${retval} -eq 0 ]]; then + echo "ChromeOS image has been built and installed on ${BISECT_REMOTE}." +else + exit 1 +fi + +while true; do + read -p "Is this a good ChromeOS image?" yn + case $yn in + [Yy]* ) exit 0;; + [Nn]* ) exit 1;; + * ) echo "Please answer yes or no.";; + esac +done + +exit 2 diff --git a/binary_search_tool/cros_pkg/boot_test.sh b/binary_search_tool/cros_pkg/boot_test.sh index 4ccb05c6..9a345617 100755..120000 --- a/binary_search_tool/cros_pkg/boot_test.sh +++ b/binary_search_tool/cros_pkg/boot_test.sh @@ -1,22 +1 @@ -#!/bin/bash -u -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# This script pings the chromebook to determine if it has successfully booted. -# -# This script is intended to be used by binary_search_state.py, as -# part of the binary search triage on ChromeOS packages. It waits for the -# install script to build and install the image, then pings the machine. -# It should return '0' if the test succeeds (the image booted); '1' if the test -# fails (the image did not boot); and '2' if it could not determine (does not -# apply in this case). -# - -source cros_pkg/common.sh - -# Send 3 pings and wait 3 seconds for any responsed (then timeout). -ping -c 3 -W 3 ${REMOTE} -retval=$? - - -exit $retval +../common/boot_test.sh
\ No newline at end of file diff --git a/binary_search_tool/cros_pkg/create_cleanup_script.py b/binary_search_tool/cros_pkg/create_cleanup_script.py index 45a90260..dc05d1ba 100755 --- a/binary_search_tool/cros_pkg/create_cleanup_script.py +++ b/binary_search_tool/cros_pkg/create_cleanup_script.py @@ -100,7 +100,7 @@ def Main(argv): options.board)) out_file.write('\n') # Remove common.sh file - out_file.write('rm cros_pkg/common.sh\n') + out_file.write('rm common/common.sh\n') return 0 diff --git a/binary_search_tool/cros_pkg/get_initial_items.sh b/binary_search_tool/cros_pkg/get_initial_items.sh index 6c87e4f2..49ca3d18 100755 --- a/binary_search_tool/cros_pkg/get_initial_items.sh +++ b/binary_search_tool/cros_pkg/get_initial_items.sh @@ -8,7 +8,7 @@ # for doing the binary search. # -source cros_pkg/common.sh +source common/common.sh cd ${GOOD_BUILD}/packages find . -name "*.tbz2" diff --git a/binary_search_tool/cros_pkg/install.sh b/binary_search_tool/cros_pkg/install.sh index f12534d6..562f7bbe 100755..120000 --- a/binary_search_tool/cros_pkg/install.sh +++ b/binary_search_tool/cros_pkg/install.sh @@ -1,105 +1 @@ -#!/bin/bash -u -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# This script calls build_image to generate a new ChromeOS image, -# using whatever packages are currently in the build tree. If -# build_images succeeeds, then it pushes the new ChromeOS image onto a -# chromebook. If pushing the ChromeOS image onto the chromebook fails it -# will walk the user through troubleshooting the problem. -# -# This script is intended to be used by binary_search_state.py, as -# part of the binary search triage on ChromeOS packages. It should return '0' -# if the install succeeds; and '1' if the install fails (the image could not -# build or be flashed). -# - -export PYTHONUNBUFFERED=1 - -source cros_pkg/common.sh - -usb_flash() -{ - echo - echo "Insert a usb stick into the current machine" - echo "Note: The cros flash will take time and doesn't given much output." - echo " Be patient. If your usb access light is flashing it's working." - sleep 1 - read -p "Press enter to continue" notused - - cros flash --board=${BOARD} --clobber-stateful usb:// ~/trunk/src/build/images/${BOARD}/latest/chromiumos_test_image.bin - - echo - echo "Flash to usb complete!" - echo "Plug the usb into your chromebook and install the image." - echo "Refer to the ChromiumOS Developer's Handbook for more details." - echo "http://www.chromium.org/chromium-os/developer-guide#TOC-Boot-from-your-USB-disk" - while true; do - sleep 1 - read -p "Was the installation of the image successful? " choice - case $choice in - [Yy]*) return 0;; - [Nn]*) return 1;; - *) echo "Please answer y or n.";; - esac - done -} - -ethernet_flash() -{ - echo - echo "Please ensure your Chromebook is up and running Chrome so" - echo "cros flash may run." - echo "If your Chromebook has a broken image you can try:" - echo "1. Rebooting your Chromebook 6 times to install the last working image" - echo "2. Alternatively, running the following command on the Chromebook" - echo " will also rollback to the last working image:" - echo " 'update_engine_client --rollback --nopowerwash --reboot'" - echo "3. Flashing a new image through USB" - echo - sleep 1 - read -p $'Press enter to continue and retry the ethernet flash' notused - cros flash --board=${BOARD} --clobber-stateful ${REMOTE} ~/trunk/src/build/images/${BOARD}/latest/chromiumos_test_image.bin -} - -echo -echo "INSTALLATION BEGIN" -echo -echo "BUILDING" -pushd ~/trunk/src/scripts -./build_image test --noeclean --board=${BOARD} --noenable_rootfs_verification -build_status=$? -popd - -if [[ ${build_status} -eq 0 ]] ; then - echo - echo "FLASHING" - echo "Pushing built image onto device." - echo "cros flash --board=${BOARD} --clobber-stateful ${REMOTE} ~/trunk/src/build/images/${BOARD}/latest/chromiumos_test_image.bin" - cros flash --board=${BOARD} --clobber-stateful ${REMOTE} ~/trunk/src/build/images/${BOARD}/latest/chromiumos_test_image.bin - cros_flash_status=$? - while [[ ${cros_flash_status} -ne 0 ]] ; do - while true; do - echo - echo "cros flash has failed! From here you can:" - echo "1. Flash through USB" - echo "2. Retry flashing over ethernet" - echo "3. Abort this installation and skip this image" - sleep 1 - read -p "Which method would you like to do? " choice - case $choice in - 1) usb_flash && break;; - 2) ethernet_flash && break;; - 3) exit 1;; - *) echo "Please answer 1, 2, or 3.";; - esac - done - - cros_flash_status=$? - done -else - echo "build_image returned a non-zero status: ${build_status}" - exit 1 -fi - -exit 0 +../common/install.sh
\ No newline at end of file diff --git a/binary_search_tool/cros_pkg/interactive_test.sh b/binary_search_tool/cros_pkg/interactive_test.sh index 011c6d8d..18fe3958 100755..120000 --- a/binary_search_tool/cros_pkg/interactive_test.sh +++ b/binary_search_tool/cros_pkg/interactive_test.sh @@ -1,37 +1 @@ -#!/bin/bash -u -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# This script pings the chromebook to determine if it successfully booted. -# It then asks the user if the image is good or not, allowing the user to -# conduct whatever tests the user wishes, and waiting for a response. -# -# This script is intended to be used by binary_search_state.py, as -# part of the binary search triage on ChromeOS packages. It waits for the -# install script to build and install the image, then asks the user if the -# image is good or not. It should return '0' if the test succeeds (the image -# is 'good'); '1' if the test fails (the image is 'bad'); and '2' if it could -# not determine (does not apply in this case). -# - -source cros_pkg/common.sh - -ping -c 3 -W 3 ${REMOTE} -retval=$? - -if [[ ${retval} -eq 0 ]]; then - echo "ChromeOS image has been built and installed on ${REMOTE}." -else - exit 1 -fi - -while true; do - read -p "Is this a good ChromeOS image?" yn - case $yn in - [Yy]* ) exit 0;; - [Nn]* ) exit 1;; - * ) echo "Please answer yes or no.";; - esac -done - -exit 2 +../common/interactive_test.sh
\ No newline at end of file diff --git a/binary_search_tool/cros_pkg/setup.sh b/binary_search_tool/cros_pkg/setup.sh index b3bee64c..ae31fa82 100755 --- a/binary_search_tool/cros_pkg/setup.sh +++ b/binary_search_tool/cros_pkg/setup.sh @@ -81,12 +81,13 @@ sudo ln -s /build/${BOARD}.work /build/${BOARD} # Create common.sh file, containing appropriate environment variables. # -COMMON_FILE="cros_pkg/common.sh" +COMMON_FILE="common/common.sh" cat <<-EOF > ${COMMON_FILE} -BOARD=${BOARD} -REMOTE=${REMOTE} +BISECT_BOARD=${BOARD} +BISECT_REMOTE=${REMOTE} +BISECT_MODE="PACKAGE_MODE" GOOD_BUILD=/build/${BOARD}.good BAD_BUILD=/build/${BOARD}.bad diff --git a/binary_search_tool/cros_pkg/switch_to_bad.sh b/binary_search_tool/cros_pkg/switch_to_bad.sh index c971270a..126425f4 100755 --- a/binary_search_tool/cros_pkg/switch_to_bad.sh +++ b/binary_search_tool/cros_pkg/switch_to_bad.sh @@ -8,7 +8,7 @@ # build tree, for testing. # -source cros_pkg/common.sh +source common/common.sh pushd ${WORK_BUILD} diff --git a/binary_search_tool/cros_pkg/switch_to_good.sh b/binary_search_tool/cros_pkg/switch_to_good.sh index c5bfa8b9..a9095e99 100755 --- a/binary_search_tool/cros_pkg/switch_to_good.sh +++ b/binary_search_tool/cros_pkg/switch_to_good.sh @@ -8,7 +8,7 @@ # build tree, for testing. # -source cros_pkg/common.sh +source common/common.sh pushd ${WORK_BUILD} diff --git a/binary_search_tool/cros_pkg/testing_test.sh b/binary_search_tool/cros_pkg/testing_test.sh index c20b78bb..0f634db5 100755 --- a/binary_search_tool/cros_pkg/testing_test.sh +++ b/binary_search_tool/cros_pkg/testing_test.sh @@ -13,7 +13,7 @@ # dealing with a real 'bad' image). # -source cros_pkg/common.sh +source common/common.sh # #Initialize the value below before using this script!!! diff --git a/binary_search_tool/sysroot_wrapper/README b/binary_search_tool/sysroot_wrapper/README index 132c03d3..599d700d 100644 --- a/binary_search_tool/sysroot_wrapper/README +++ b/binary_search_tool/sysroot_wrapper/README @@ -3,10 +3,22 @@ the bisecting functionality included in the sysroot_wrapper.hardened. The only script that you need to create for your triaging problem is the test_script.sh (The ones in this directory are here only as an example). +Before running the binary searcher tool you will need to run the setup script: + +./sysroot_wrapper/setup.sh ${board} ${remote_ip} ${package} + +This setup script will ensure your $BISECT_DIR is properly populated and +generate a common variable script for the convenience of the scripts in +./sysroot_wrapper + To run the binary searcher tool with these scripts, execute it like this: ./binary_search_state.py --get_initial_items=./sysroot_wrapper/get_initial_items.sh --switch_to_good=./sysroot_wrapper/switch_to_good.sh --switch_to_bad=./sysroot_wrapper/switch_to_bad.sh --test_script=./sysroot_wrapper/test_script.sh --noincremental --file_args 2>&1 | tee /tmp/binary_search.log +Finally once done you will want to run the cleanup script: + +./sysroot_wrapper/cleanup.sh + For more information on how to use the sysroot_wrapper to do object file triaging see: diff --git a/binary_search_tool/sysroot_wrapper/boot_test.sh b/binary_search_tool/sysroot_wrapper/boot_test.sh index a3de2dec..9a345617 100755..120000 --- a/binary_search_tool/sysroot_wrapper/boot_test.sh +++ b/binary_search_tool/sysroot_wrapper/boot_test.sh @@ -1,22 +1 @@ -#!/bin/bash -u -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# This script pings the chromebook to determine if it has successfully booted. -# -# This script is intended to be used by binary_search_state.py, as -# part of the binary search triage on ChromeOS object files. It waits for the -# install script to build and install the image, then pings the machine. -# It should return '0' if the test succeeds (the image booted); '1' if the test -# fails (the image did not boot); and '2' if it could not determine (does not -# apply in this case). -# - -source sysroot_wrapper/common.sh - -# Send 3 pings and wait 3 seconds for any responsed (then timeout). -ping -c 3 -W 3 ${BISECT_REMOTE} -retval=$? - - -exit $retval +../common/boot_test.sh
\ No newline at end of file diff --git a/binary_search_tool/sysroot_wrapper/cleanup.sh b/binary_search_tool/sysroot_wrapper/cleanup.sh new file mode 100755 index 00000000..5066d638 --- /dev/null +++ b/binary_search_tool/sysroot_wrapper/cleanup.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# This script is part of the ChromeOS object binary search triage process. +# It should be the last script called by the user, after the user has +# successfully run the bisection tool and found their bad items. This script +# will perform all necessary cleanup for the bisection tool. +# + +rm common/common.sh diff --git a/binary_search_tool/sysroot_wrapper/common.sh b/binary_search_tool/sysroot_wrapper/common.sh deleted file mode 100755 index 0d60b9a6..00000000 --- a/binary_search_tool/sysroot_wrapper/common.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -u - -bisect_dir=${BISECT_DIR:-/tmp/sysroot_bisect} diff --git a/binary_search_tool/sysroot_wrapper/get_initial_items.sh b/binary_search_tool/sysroot_wrapper/get_initial_items.sh index 85d6942d..c1beb972 100755 --- a/binary_search_tool/sysroot_wrapper/get_initial_items.sh +++ b/binary_search_tool/sysroot_wrapper/get_initial_items.sh @@ -1,5 +1,5 @@ #!/bin/bash -u -source ./sysroot_wrapper/common.sh +source common/common.sh cat ${bisect_dir}/good/_LIST diff --git a/binary_search_tool/sysroot_wrapper/glibc_test_script.sh b/binary_search_tool/sysroot_wrapper/glibc_test_script.sh index 74e492ad..8e9ae8e4 100755 --- a/binary_search_tool/sysroot_wrapper/glibc_test_script.sh +++ b/binary_search_tool/sysroot_wrapper/glibc_test_script.sh @@ -7,7 +7,7 @@ # Note it returns 0 only when the installation of the image succeeded # (ie: the machine booted after installation) -source ./sysroot_wrapper/common.sh +source common/common.sh #export BISECT_STAGE=TRIAGE echo "BISECT_STAGE=${BISECT_STAGE}" diff --git a/binary_search_tool/sysroot_wrapper/install.sh b/binary_search_tool/sysroot_wrapper/install.sh index 7cf62168..562f7bbe 100755..120000 --- a/binary_search_tool/sysroot_wrapper/install.sh +++ b/binary_search_tool/sysroot_wrapper/install.sh @@ -1,160 +1 @@ -#!/bin/bash -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# This script calls build_image to generate a new ChromeOS image, -# using whatever packages are currently in the build tree. If -# build_images succeeeds, then it pushes the new ChromeOS image onto a -# chromebook. If pushing the ChromeOS image onto the chromebook fails it -# will walk the user through troubleshooting the problem. -# -# This script is intended to be used by binary_search_state.py, as -# part of the binary search triage on ChromeOS objects. It should return '0' -# if the install succeeds; and '1' if the install fails (the image could not -# build or be flashed). -# -# This script requires $BISECT_BOARD, $BISECT_REMOTE, and $BISECT_PACKAGE to be -# set. If they are not set the script will exit. -# - -export PYTHONUNBUFFERED=1 - -source sysroot_wrapper/common.sh - -usb_flash() -{ - echo - echo "Insert a usb stick into the current machine" - echo "Note: The cros flash will take time and doesn't give much output." - echo " Be patient. If your usb access light is flashing it's working." - sleep 1 - read -p "Press enter to continue" notused - - cros flash --board=${BISECT_BOARD} --clobber-stateful usb:// ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin - - echo - echo "Flash to usb complete!" - echo "Plug the usb into your chromebook and install the image." - echo "Refer to the ChromiumOS Developer's Handbook for more details." - echo "http://www.chromium.org/chromium-os/developer-guide#TOC-Boot-from-your-USB-disk" - while true; do - sleep 1 - read -p "Was the installation of the image successful? " choice - case $choice in - [Yy]*) return 0;; - [Nn]*) return 1;; - *) echo "Please answer y or n.";; - esac - done -} - -ethernet_flash() -{ - echo - echo "Please ensure your Chromebook is up and running Chrome so" - echo "cros flash may run." - echo "If your Chromebook has a broken image you can try:" - echo "1. Rebooting your Chromebook 6 times to install the last working image" - echo "2. Alternatively, running the following command on the Chromebook" - echo " will also rollback to the last working image:" - echo " 'update_engine_client --rollback --nopowerwash --reboot'" - echo "3. Flashing a new image through USB" - echo - sleep 1 - read -p $'Press enter to continue and retry the ethernet flash' notused - cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin -} - -reboot() -{ - ret_val=0 - pushd ~/trunk/src/scripts > /dev/null - set -- --remote=${BISECT_REMOTE} - . ./common.sh || ret_val=1 - . ./remote_access.sh || ret_val=1 - TMP=$(mktemp -d) - FLAGS "$@" || ret_val=1 - remote_access_init || ret_val=1 - remote_reboot || ret_val=1 - popd > /dev/null - - return $ret_val -} - -if [[ -z "${BISECT_BOARD}" || -z "${BISECT_REMOTE}" || -z "${BISECT_PACKAGE}" ]] -then - echo "ERROR: Environment variables not properly setup. Please ensure that " - echo "\$BISECT_BOARD, \$BISECT_REMOTE, and \$BISECT_PACKAGE are set" - exit 3 -fi - -echo -echo "INSTALLATION BEGIN" -echo -echo "EMERGING ${BISECT_PACKAGE}" -CLEAN_DELAY=0 emerge-${BISECT_BOARD} -C ${BISECT_PACKAGE} -emerge-${BISECT_BOARD} ${BISECT_PACKAGE} -emerge_status=$? - -if [[ ${emerge_status} -ne 0 ]] ; then - echo "emerging ${BISECT_PACKAGE} returned a non-zero status: $emerge_status" - exit 1 -fi - -echo -echo "DEPLOYING" -echo "cros deploy ${BISECT_REMOTE} ${BISECT_PACKAGE}" -cros deploy ${BISECT_REMOTE} ${BISECT_PACKAGE} --log-level=info -deploy_status=$? - -if [[ ${deploy_status} -eq 0 ]] ; then - echo "Deploy successful. Rebooting device..." - reboot - if [[ $? -ne 0 ]] ; then - echo - echo "Could not automatically reboot device!" - read -p "Please manually reboot device and press enter to continue" notused - fi - exit 0 -fi - -echo "Deploy failed! Trying build_image/cros flash instead..." -echo -echo "BUILDING IMAGE" -pushd ~/trunk/src/scripts -./build_image test --board=${BISECT_BOARD} --noenable_rootfs_verification -build_status=$? -popd - -if [[ ${build_status} -eq 0 ]] ; then - echo - echo "FLASHING" - echo "Pushing built image onto device." - echo "cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin" - cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin - cros_flash_status=$? - while [[ ${cros_flash_status} -ne 0 ]] ; do - while true; do - echo - echo "cros flash has failed! From here you can:" - echo "1. Flash through USB" - echo "2. Retry flashing over ethernet" - echo "3. Abort this installation and skip this image" - sleep 1 - read -p "Which method would you like to do? " choice - case $choice in - 1) usb_flash && break;; - 2) ethernet_flash && break;; - 3) exit 1;; - *) echo "Please answer 1, 2, or 3.";; - esac - done - - cros_flash_status=$? - done -else - echo "build_image returned a non-zero status: ${build_status}" - exit 1 -fi - -exit 0 +../common/install.sh
\ No newline at end of file diff --git a/binary_search_tool/sysroot_wrapper/interactive_test.sh b/binary_search_tool/sysroot_wrapper/interactive_test.sh index 1b5b7e19..18fe3958 100755..120000 --- a/binary_search_tool/sysroot_wrapper/interactive_test.sh +++ b/binary_search_tool/sysroot_wrapper/interactive_test.sh @@ -1,37 +1 @@ -#!/bin/bash -u -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# This script pings the chromebook to determine if it successfully booted. -# It then asks the user if the image is good or not, allowing the user to -# conduct whatever tests the user wishes, and waiting for a response. -# -# This script is intended to be used by binary_search_state.py, as -# part of the binary search triage on ChromeOS object files. It waits for the -# install script to build and install the image, then asks the user if the -# image is good or not. It should return '0' if the test succeeds (the image -# is 'good'); '1' if the test fails (the image is 'bad'); and '2' if it could -# not determine (does not apply in this case). -# - -source cros_pkg/common.sh - -ping -c 3 -W 3 ${BISECT_REMOTE} -retval=$? - -if [[ ${retval} -eq 0 ]]; then - echo "ChromeOS image has been built and installed on ${BISECT_REMOTE}." -else - exit 1 -fi - -while true; do - read -p "Is this a good ChromeOS image?" yn - case $yn in - [Yy]* ) exit 0;; - [Nn]* ) exit 1;; - * ) echo "Please answer yes or no.";; - esac -done - -exit 2 +../common/interactive_test.sh
\ No newline at end of file diff --git a/binary_search_tool/sysroot_wrapper/setup.sh b/binary_search_tool/sysroot_wrapper/setup.sh new file mode 100755 index 00000000..d000b3b5 --- /dev/null +++ b/binary_search_tool/sysroot_wrapper/setup.sh @@ -0,0 +1,71 @@ +#!/bin/bash -u +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# This script is part of the ChromeOS object binary search triage process. +# It should be the first script called by the user, after the user has set up +# the two necessary build tree directories (see sysroot_wrapper/README). +# +# This script requires three arguments. The first argument must be the name of +# the board for which this work is being done (e.g. 'daisy', 'lumpy','parrot', +# etc.). The second argument must be the name or IP address of the chromebook +# on which the ChromeOS images will be pushed and tested. The third argument +# must be the name of the package being bisected (e.g. 'chromeos-chrome', +# 'cryptohome', etc.). +# +# This script generates common/common.sh, which generates enviroment variables +# used by the other scripts in the object file binary search triage process. +# + +# Set up basic variables. +bisect_dir=${BISECT_DIR:-/tmp/sysroot_bisect} + +BOARD=$1 +REMOTE=$2 +PACKAGE=$3 + +GOOD_BUILD=${bisect_dir}/good +BAD_BUILD=${bisect_dir}/bad +GOOD_LIST=${GOOD_BUILD}/_LIST +BAD_LIST=${BAD_BUILD}/_LIST + +# +# Verify that the necessary directories exist. +# + +if [[ ! -d ${GOOD_BUILD} ]] ; then + echo "Error: ${GOOD_BUILD} does not exist." + exit 1 +fi + +if [[ ! -d ${BAD_BUILD} ]] ; then + echo "Error: ${BAD_BUILD} does not exist." + exit 1 +fi + +if [[ ! -e ${GOOD_LIST} ]] ; then + echo "Error: ${GOOD_LIST} does not exist." + exit 1 +fi + +if [[ ! -e ${BAD_LIST} ]] ; then + echo "Error: ${BAD_LIST} does not exist." + exit 1 +fi + +COMMON_FILE="common/common.sh" + +cat <<-EOF > ${COMMON_FILE} + +BISECT_BOARD=${BOARD} +BISECT_REMOTE=${REMOTE} +BISECT_PACKAGE=${PACKAGE} +BISECT_MODE="OBJECT_MODE" + +bisect_dir=${bisect_dir} + +EOF + +chmod 755 ${COMMON_FILE} + +exit 0 diff --git a/binary_search_tool/sysroot_wrapper/switch_to_bad.sh b/binary_search_tool/sysroot_wrapper/switch_to_bad.sh index 62a908f4..7aae3504 100755 --- a/binary_search_tool/sysroot_wrapper/switch_to_bad.sh +++ b/binary_search_tool/sysroot_wrapper/switch_to_bad.sh @@ -1,6 +1,6 @@ #!/bin/bash -u -source ./sysroot_wrapper/common.sh +source common/common.sh cat $1 > ${bisect_dir}/BAD_SET diff --git a/binary_search_tool/sysroot_wrapper/switch_to_good.sh b/binary_search_tool/sysroot_wrapper/switch_to_good.sh index 3db8a9c6..7b3c98c4 100755 --- a/binary_search_tool/sysroot_wrapper/switch_to_good.sh +++ b/binary_search_tool/sysroot_wrapper/switch_to_good.sh @@ -1,6 +1,6 @@ #!/bin/bash -u -source ./sysroot_wrapper/common.sh +source common/common.sh cat $1 > ${bisect_dir}/GOOD_SET diff --git a/binary_search_tool/sysroot_wrapper/test_script.sh b/binary_search_tool/sysroot_wrapper/test_script.sh index ef6b4d40..8b424825 100755 --- a/binary_search_tool/sysroot_wrapper/test_script.sh +++ b/binary_search_tool/sysroot_wrapper/test_script.sh @@ -7,7 +7,7 @@ # Note it returns 0 only when the installation of the image succeeded # (ie: the machine booted after installation) -source ./sysroot_wrapper/common.sh +source common/common.sh export BISECT_STAGE=TRIAGE echo "BISECT_STAGE=${BISECT_STAGE}" |