Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: build/android/buildbot/bb_device_status_check.py

Issue 301183004: Android: adds device affinity for perf tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | build/android/pylib/device/device_list.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """A class to keep track of devices across builds and report state.""" 7 """A class to keep track of devices across builds and report state."""
8 import logging 8 import logging
9 import optparse 9 import optparse
10 import os 10 import os
(...skipping 13 matching lines...) Expand all
24 os.pardir, os.pardir, 'util', 'lib', 24 os.pardir, os.pardir, 'util', 'lib',
25 'common')) 25 'common'))
26 import perf_tests_results_helper # pylint: disable=F0401 26 import perf_tests_results_helper # pylint: disable=F0401
27 27
28 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 28 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
29 from pylib import android_commands 29 from pylib import android_commands
30 from pylib import constants 30 from pylib import constants
31 from pylib.cmd_helper import GetCmdOutput 31 from pylib.cmd_helper import GetCmdOutput
32 from pylib.device import device_blacklist 32 from pylib.device import device_blacklist
33 from pylib.device import device_errors 33 from pylib.device import device_errors
34 from pylib.device import device_list
34 from pylib.device import device_utils 35 from pylib.device import device_utils
35 36
36 def DeviceInfo(serial, options): 37 def DeviceInfo(serial, options):
37 """Gathers info on a device via various adb calls. 38 """Gathers info on a device via various adb calls.
38 39
39 Args: 40 Args:
40 serial: The serial of the attached device to construct info about. 41 serial: The serial of the attached device to construct info about.
41 42
42 Returns: 43 Returns:
43 Tuple of device type, build id, report as a string, error messages, and 44 Tuple of device type, build id, report as a string, error messages, and
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 except device_errors.CommandFailedError as e: 102 except device_errors.CommandFailedError as e:
102 # Attempt shutdown anyway. 103 # Attempt shutdown anyway.
103 # TODO(jbudorick) Handle this exception appropriately after interface 104 # TODO(jbudorick) Handle this exception appropriately after interface
104 # conversions are finished. 105 # conversions are finished.
105 logging.error(str(e)) 106 logging.error(str(e))
106 device_adb.old_interface.Shutdown() 107 device_adb.old_interface.Shutdown()
107 full_report = '\n'.join(report) 108 full_report = '\n'.join(report)
108 return device_type, device_build, battery_level, full_report, errors, True 109 return device_type, device_build, battery_level, full_report, errors, True
109 110
110 111
111 def GetLastDevices(out_dir):
112 """Returns a list of devices that have been seen on the bot.
113
114 Args:
115 options: out_dir parameter of options argument is used as the base
116 directory to load and update the cache file.
117
118 Returns: List of device serial numbers that were on the bot.
119 """
120 devices_path = os.path.join(out_dir, '.last_devices')
121 devices = []
122 try:
123 with open(devices_path) as f:
124 devices = f.read().splitlines()
125 except IOError:
126 # Ignore error, file might not exist
127 pass
128 return devices
129
130
131 def CheckForMissingDevices(options, adb_online_devs): 112 def CheckForMissingDevices(options, adb_online_devs):
132 """Uses file of previous online devices to detect broken phones. 113 """Uses file of previous online devices to detect broken phones.
133 114
134 Args: 115 Args:
135 options: out_dir parameter of options argument is used as the base 116 options: out_dir parameter of options argument is used as the base
136 directory to load and update the cache file. 117 directory to load and update the cache file.
137 adb_online_devs: A list of serial numbers of the currently visible 118 adb_online_devs: A list of serial numbers of the currently visible
138 and online attached devices. 119 and online attached devices.
139 """ 120 """
140 # TODO(navabi): remove this once the bug that causes different number 121 # TODO(navabi): remove this once the bug that causes different number
141 # of devices to be detected between calls is fixed. 122 # of devices to be detected between calls is fixed.
142 logger = logging.getLogger() 123 logger = logging.getLogger()
143 logger.setLevel(logging.INFO) 124 logger.setLevel(logging.INFO)
144 125
145 out_dir = os.path.abspath(options.out_dir) 126 out_dir = os.path.abspath(options.out_dir)
146 127
147 def WriteDeviceList(file_name, device_list): 128 last_devices_path = os.path.join(out_dir, device_list.LAST_DEVICES_FILENAME)
148 path = os.path.join(out_dir, file_name) 129 try:
149 if not os.path.exists(out_dir): 130 last_devices = device_list.GetPersistentDeviceList(last_devices_path)
150 os.makedirs(out_dir) 131 except IOError:
151 with open(path, 'w') as f: 132 # Ignore error, file might not exist
152 # Write devices currently visible plus devices previously seen. 133 last_devices = []
153 f.write('\n'.join(set(device_list)))
154
155 last_devices_path = os.path.join(out_dir, '.last_devices')
156 last_devices = GetLastDevices(out_dir)
157 missing_devs = list(set(last_devices) - set(adb_online_devs)) 134 missing_devs = list(set(last_devices) - set(adb_online_devs))
158 135
159 all_known_devices = list(set(adb_online_devs) | set(last_devices)) 136 all_known_devices = list(set(adb_online_devs) | set(last_devices))
160 WriteDeviceList('.last_devices', all_known_devices) 137 device_list.WritePersistentDeviceList(last_devices_path, all_known_devices)
161 WriteDeviceList('.last_missing', missing_devs) 138 device_list.WritePersistentDeviceList(
139 os.path.join(out_dir, device_list.LAST_MISSING_DEVICES_FILENAME),
140 missing_devs)
162 141
163 if not all_known_devices: 142 if not all_known_devices:
164 # This can happen if for some reason the .last_devices file is not 143 # This can happen if for some reason the .last_devices file is not
165 # present or if it was empty. 144 # present or if it was empty.
166 return ['No online devices. Have any devices been plugged in?'] 145 return ['No online devices. Have any devices been plugged in?']
167 if missing_devs: 146 if missing_devs:
168 devices_missing_msg = '%d devices not detected.' % len(missing_devs) 147 devices_missing_msg = '%d devices not detected.' % len(missing_devs)
169 bb_annotations.PrintSummaryText(devices_missing_msg) 148 bb_annotations.PrintSummaryText(devices_missing_msg)
170 149
171 # TODO(navabi): Debug by printing both output from GetCmdOutput and 150 # TODO(navabi): Debug by printing both output from GetCmdOutput and
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 parser.add_option('--restart-usb', action='store_true', 261 parser.add_option('--restart-usb', action='store_true',
283 help='Restart USB ports before running device check.') 262 help='Restart USB ports before running device check.')
284 options, args = parser.parse_args() 263 options, args = parser.parse_args()
285 if args: 264 if args:
286 parser.error('Unknown options %s' % args) 265 parser.error('Unknown options %s' % args)
287 266
288 # Remove the last build's "bad devices" before checking device statuses. 267 # Remove the last build's "bad devices" before checking device statuses.
289 device_blacklist.ResetBlacklist() 268 device_blacklist.ResetBlacklist()
290 269
291 if options.restart_usb: 270 if options.restart_usb:
292 expected_devices = GetLastDevices(os.path.abspath(options.out_dir)) 271 try:
272 expected_devices = device_list.GetPersistentDeviceList(
273 os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME))
274 except IOError:
275 expected_devices = []
293 devices = android_commands.GetAttachedDevices() 276 devices = android_commands.GetAttachedDevices()
294 # Only restart usb if devices are missing. 277 # Only restart usb if devices are missing.
295 if set(expected_devices) != set(devices): 278 if set(expected_devices) != set(devices):
296 KillAllAdb() 279 KillAllAdb()
297 retries = 5 280 retries = 5
298 usb_restarted = True 281 usb_restarted = True
299 if not RestartUsb(): 282 if not RestartUsb():
300 usb_restarted = False 283 usb_restarted = False
301 bb_annotations.PrintWarning() 284 bb_annotations.PrintWarning()
302 print 'USB reset stage failed, wait for any device to come back.' 285 print 'USB reset stage failed, wait for any device to come back.'
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 # devices with critically low battery. Remove those devices from testing, 342 # devices with critically low battery. Remove those devices from testing,
360 # allowing build to continue with good devices. 343 # allowing build to continue with good devices.
361 return 1 344 return 1
362 345
363 if not devices: 346 if not devices:
364 return 1 347 return 1
365 348
366 349
367 if __name__ == '__main__': 350 if __name__ == '__main__':
368 sys.exit(main()) 351 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device/device_list.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698