boot_test.sh revision f67b68da6d8ed5e8e84409a1c78be4d457e792b4
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 install script to build and install the image, then checks if
10# 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 '2' if
12# it could not determine (does not apply in this case).
13#
14
15source android/common.sh
16
17# Check if boot animation has stopped and trim whitespace
18is_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
28wait_for_boot()
29{
30  while ! is_booted
31  do
32    sleep 1
33  done
34}
35
36echo "Waiting 60 seconds for device to come online..."
37timeout 60 adb wait-for-device
38retval=$?
39
40if [[ ${retval} -eq 0 ]]; then
41  echo "Android image has been built and installed."
42else
43  echo "Device failed to reboot within 60 seconds."
44  exit 1
45fi
46
47echo "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)
51timeout 60 cat <(wait_for_boot)
52retval=$?
53
54if [[ ${retval} -eq 0 ]]; then
55  echo "Android device fully booted!"
56else
57  echo "Device failed to fully boot within 60 seconds."
58  exit 1
59fi
60
61exit ${retval}
62