1 #!/bin/bash -u 2 # 3 # Copyright 2016 Google Inc. All Rights Reserved. 4 # 5 # This script pings the android device to determine if it successfully booted. 6 # 7 # This script is intended to be used by binary_search_state.py, as 8 # part of the binary search triage on the Android source tree. It 9 # waits for the test setup script to build and install the image, then checks 10 # if image boots or not. It should return '0' if the test succeeds 11 # (the image is 'good'); '1' if the test fails (the image is 'bad'); and '125' 12 # if it could not determine (does not apply in this case). 13 # 14 15 source android/common.sh 16 17 # Check if boot animation has stopped and trim whitespace 18 is_booted() 19 { 20 # Wait for boot animation to stop and trim whitespace 21 status=`adb shell getprop init.svc.bootanim | tr -d '[:space:]'` 22 [[ "$status" == "stopped" ]] 23 return $? 24 } 25 26 # Wait for device to boot, retry every 1s 27 # WARNING: Do not run without timeout command, could run forever 28 wait_for_boot() 29 { 30 while ! is_booted 31 do 32 sleep 1 33 done 34 } 35 36 echo "Waiting 60 seconds for device to come online..." 37 timeout 60 adb wait-for-device 38 retval=$? 39 40 if [[ ${retval} -eq 0 ]]; then 41 echo "Android image has been built and installed." 42 else 43 echo "Device failed to reboot within 60 seconds." 44 exit 1 45 fi 46 47 echo "Waiting 60 seconds for device to finish boot..." 48 # Spawn subshell that will timeout in 60 seconds 49 # Feed to cat so that timeout will recognize it as a command 50 # (timeout only works for commands/programs, not functions) 51 timeout 60 cat <(wait_for_boot) 52 retval=$? 53 54 if [[ ${retval} -eq 0 ]]; then 55 echo "Android device fully booted!" 56 else 57 echo "Device failed to fully boot within 60 seconds." 58 exit 1 59 fi 60 61 exit ${retval} 62