diff options
author | Stephen Hines <srhines@google.com> | 2017-02-08 10:45:48 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-02-08 10:45:48 +0000 |
commit | 9826fbe38e2bc35fc6c680cc216dcb993b54d2ff (patch) | |
tree | 87b3a32b13c392939d66fa93105896f5df0736a6 /binary_search_tool/common | |
parent | baba90fd78c18585d22430dc95c748f96ad0c772 (diff) | |
parent | 271389dd3199539c4474c351942f4d4fa975b81b (diff) | |
download | toolchain-utils-9826fbe38e2bc35fc6c680cc216dcb993b54d2ff.tar.gz |
Merge remote-tracking branch 'aosp/mirror-chromium-master' into initial_import am: 870a8df6fc am: 9c6fa5f9e5 am: c5804ce784
am: 271389dd31
Change-Id: I22e657bc86117da9a6a45329a67a21096736da03
Diffstat (limited to 'binary_search_tool/common')
-rwxr-xr-x | binary_search_tool/common/boot_test.sh | 22 | ||||
-rwxr-xr-x | binary_search_tool/common/hash_test.sh | 57 | ||||
-rwxr-xr-x | binary_search_tool/common/interactive_test.sh | 37 | ||||
-rwxr-xr-x | binary_search_tool/common/test_setup.sh | 166 |
4 files changed, 282 insertions, 0 deletions
diff --git a/binary_search_tool/common/boot_test.sh b/binary_search_tool/common/boot_test.sh new file mode 100755 index 00000000..8f6d9a7d --- /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 test setup 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 '125' 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/hash_test.sh b/binary_search_tool/common/hash_test.sh new file mode 100755 index 00000000..5450988e --- /dev/null +++ b/binary_search_tool/common/hash_test.sh @@ -0,0 +1,57 @@ +#!/bin/bash -u +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# This script is intended to be used by binary_search_state.py. It is to +# be used for testing/development of the binary search triage tool +# itself. It waits for the test setup script to build and install the +# image, then checks the hashes in the provided file. +# If the real hashes match the checksum hashes, then the image is 'good', +# otherwise it is 'bad'. This allows the rest of the bisecting tool +# to run without requiring help from the user (as it would if we were +# dealing with a real 'bad' image). +# + +# +# Initialize the value below before using this script!!! +# +# Make an md5sum of all the files you want to check. For example if you want +# file1, file2, and file3 to be found as bad items: +# +# md5sum file1 file2 file3 > checksum.out +# +# (Make sure you are hashing the files from your good build and that the hashes +# from good to bad build differ) +# +# Then set HASHES_FILE to be the path to 'checksum.out' +# In this example, file1, file2, file3 will be found as the bad files +# because their hashes won't match when from the bad build tree. This is +# assuming that the hashes between good/bad builds change. It is suggested to +# build good and bad builds at different optimization levels to help ensure +# each item has a different hash. +# +# WARNING: +# Make sure paths to all files are absolute paths or relative to +# binary_search_state.py +# +# cros_pkg bisector example: +# 1. Build good packages with -O1, bad packages with -O2 +# 2. cros_pkg/switch_to_good.sh pkg1 pkg2 pkg3 +# 3. md5sum pkg1 pkg2 pkg3 > checksum.out.cros_pkg +# 4. Set HASHES_FILE to be checksum.out.cros_pkg +# 5. Run the bisector with this test script +# +# +HASHES_FILE= + +if [[ -z "${HASHES_FILE}" || ! -f "${HASHES_FILE}" ]]; +then + echo "ERROR: HASHES_FILE must be intialized in common/hash_test.sh" + exit 3 +fi + +md5sum -c --status ${HASHES_FILE} +md5_result=$? + + +exit $md5_result diff --git a/binary_search_tool/common/interactive_test.sh b/binary_search_tool/common/interactive_test.sh new file mode 100755 index 00000000..8773dd12 --- /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 test setup 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 '125' +# 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 125 diff --git a/binary_search_tool/common/test_setup.sh b/binary_search_tool/common/test_setup.sh new file mode 100755 index 00000000..c4f5f698 --- /dev/null +++ b/binary_search_tool/common/test_setup.sh @@ -0,0 +1,166 @@ +#!/bin/bash +# +# Copyright 2016 Google Inc. All Rights Reserved. +# +# This is a generic ChromeOS package/image test setup 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 setup succeeds; and '1' if the setup 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" + echo "4. Abort this installation and mark test as failed" + 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 125;; + 4) exit 1;; + *) echo "Please answer 1, 2, 3, or 4.";; + esac + done + + cros_flash_status=$? + done +else + echo "build_image returned a non-zero status: ${build_status}" + exit 1 +fi + +exit 0 |