Commit c23691ab authored by bulach@chromium.org's avatar bulach@chromium.org

Android: wait for at least one device if usb restart fails.

On some bots, the USB restart fails, but some devices come back
online shortly afterwards.
Rather than completely shortcut, wait for at least one device to be alive.

BUG=332356
TBR=navabi@chromium.org

Review URL: https://codereview.chromium.org/128083002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244145 0039d316-1c4b-4281-b951-d872f2087c98
parent 1139c6c2
...@@ -225,7 +225,7 @@ def RestartUsb(): ...@@ -225,7 +225,7 @@ def RestartUsb():
if not os.path.isfile('/usr/bin/restart_usb'): if not os.path.isfile('/usr/bin/restart_usb'):
print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed ' print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed '
'on host (see BUG=305769).') 'on host (see BUG=305769).')
return 1 return False
lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE) lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE)
lsusb_output, _ = lsusb_proc.communicate() lsusb_output, _ = lsusb_proc.communicate()
...@@ -236,7 +236,7 @@ def RestartUsb(): ...@@ -236,7 +236,7 @@ def RestartUsb():
usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0] usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0]
for lsusb_line in lsusb_output.strip().split('\n')] for lsusb_line in lsusb_output.strip().split('\n')]
failed_restart = False all_restarted = True
# Walk USB devices from leaves up (i.e reverse sorted) restarting the # Walk USB devices from leaves up (i.e reverse sorted) restarting the
# connection. If a parent node (e.g. usb hub) is restarted before the # connection. If a parent node (e.g. usb hub) is restarted before the
# devices connected to it, the (bus, dev) for the hub can change, making the # devices connected to it, the (bus, dev) for the hub can change, making the
...@@ -247,14 +247,11 @@ def RestartUsb(): ...@@ -247,14 +247,11 @@ def RestartUsb():
return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev]) return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev])
if return_code: if return_code:
print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev) print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev)
failed_restart = True all_restarted = False
else: else:
print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev) print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev)
if failed_restart: return all_restarted
return 1
return 0
def KillAllAdb(): def KillAllAdb():
...@@ -299,18 +296,24 @@ def main(): ...@@ -299,18 +296,24 @@ def main():
if options.restart_usb: if options.restart_usb:
expected_devices = GetLastDevices(os.path.abspath(options.out_dir)) expected_devices = GetLastDevices(os.path.abspath(options.out_dir))
devices = android_commands.GetAttachedDevices() devices = android_commands.GetAttachedDevices()
# Only restart usb if devices are missing # Only restart usb if devices are missing.
if set(expected_devices) != set(devices): if set(expected_devices) != set(devices):
KillAllAdb() KillAllAdb()
retries = 5 retries = 5
if RestartUsb(): usb_restarted = True
if not RestartUsb():
usb_restarted = False
bb_annotations.PrintWarning() bb_annotations.PrintWarning()
print "USB reset stage failed, continuing anyway." print 'USB reset stage failed, wait for any device to come back.'
retries = 0
while retries: while retries:
time.sleep(1) time.sleep(1)
devices = android_commands.GetAttachedDevices() devices = android_commands.GetAttachedDevices()
if set(expected_devices) == set(devices): if set(expected_devices) == set(devices):
# All devices are online, keep going.
break
if not usb_restarted and devices:
# The USB wasn't restarted, but there's at least one device online.
# No point in trying to wait for all devices.
break break
retries -= 1 retries -= 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment