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: http://src.chromium.org/svn/trunk/src/build@244145 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
bulach@chromium.org 2014-01-10 11:12:52 +00:00
Родитель e214b96ebe
Коммит 3474356f4f
1 изменённых файлов: 14 добавлений и 11 удалений

Просмотреть файл

@ -225,7 +225,7 @@ def RestartUsb():
if not os.path.isfile('/usr/bin/restart_usb'):
print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed '
'on host (see BUG=305769).')
return 1
return False
lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE)
lsusb_output, _ = lsusb_proc.communicate()
@ -236,7 +236,7 @@ def RestartUsb():
usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0]
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
# 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
@ -247,14 +247,11 @@ def RestartUsb():
return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev])
if return_code:
print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev)
failed_restart = True
all_restarted = False
else:
print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev)
if failed_restart:
return 1
return 0
return all_restarted
def KillAllAdb():
@ -299,18 +296,24 @@ def main():
if options.restart_usb:
expected_devices = GetLastDevices(os.path.abspath(options.out_dir))
devices = android_commands.GetAttachedDevices()
# Only restart usb if devices are missing
# Only restart usb if devices are missing.
if set(expected_devices) != set(devices):
KillAllAdb()
retries = 5
if RestartUsb():
usb_restarted = True
if not RestartUsb():
usb_restarted = False
bb_annotations.PrintWarning()
print "USB reset stage failed, continuing anyway."
retries = 0
print 'USB reset stage failed, wait for any device to come back.'
while retries:
time.sleep(1)
devices = android_commands.GetAttachedDevices()
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
retries -= 1