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

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: Comments 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
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 last_devices = device_list.GetDeviceList(last_devices_path)
149 if not os.path.exists(out_dir):
150 os.makedirs(out_dir)
151 with open(path, 'w') as f:
152 # Write devices currently visible plus devices previously seen.
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)) 130 missing_devs = list(set(last_devices) - set(adb_online_devs))
158 131
159 all_known_devices = list(set(adb_online_devs) | set(last_devices)) 132 all_known_devices = list(set(adb_online_devs) | set(last_devices))
160 WriteDeviceList('.last_devices', all_known_devices) 133 device_list.WriteDeviceList(last_devices_path, all_known_devices)
161 WriteDeviceList('.last_missing', missing_devs) 134 device_list.WriteDeviceList(
135 os.path.join(out_dir, device_list.LAST_MISSING_DEVICES_FILENAME),
136 missing_devs)
162 137
163 if not all_known_devices: 138 if not all_known_devices:
164 # This can happen if for some reason the .last_devices file is not 139 # This can happen if for some reason the .last_devices file is not
165 # present or if it was empty. 140 # present or if it was empty.
166 return ['No online devices. Have any devices been plugged in?'] 141 return ['No online devices. Have any devices been plugged in?']
167 if missing_devs: 142 if missing_devs:
168 devices_missing_msg = '%d devices not detected.' % len(missing_devs) 143 devices_missing_msg = '%d devices not detected.' % len(missing_devs)
169 bb_annotations.PrintSummaryText(devices_missing_msg) 144 bb_annotations.PrintSummaryText(devices_missing_msg)
170 145
171 # TODO(navabi): Debug by printing both output from GetCmdOutput and 146 # 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', 257 parser.add_option('--restart-usb', action='store_true',
283 help='Restart USB ports before running device check.') 258 help='Restart USB ports before running device check.')
284 options, args = parser.parse_args() 259 options, args = parser.parse_args()
285 if args: 260 if args:
286 parser.error('Unknown options %s' % args) 261 parser.error('Unknown options %s' % args)
287 262
288 # Remove the last build's "bad devices" before checking device statuses. 263 # Remove the last build's "bad devices" before checking device statuses.
289 device_blacklist.ResetBlacklist() 264 device_blacklist.ResetBlacklist()
290 265
291 if options.restart_usb: 266 if options.restart_usb:
292 expected_devices = GetLastDevices(os.path.abspath(options.out_dir)) 267 expected_devices = device_list.GetDeviceList(
268 os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME))
293 devices = android_commands.GetAttachedDevices() 269 devices = android_commands.GetAttachedDevices()
294 # Only restart usb if devices are missing. 270 # Only restart usb if devices are missing.
295 if set(expected_devices) != set(devices): 271 if set(expected_devices) != set(devices):
296 KillAllAdb() 272 KillAllAdb()
297 retries = 5 273 retries = 5
298 usb_restarted = True 274 usb_restarted = True
299 if not RestartUsb(): 275 if not RestartUsb():
300 usb_restarted = False 276 usb_restarted = False
301 bb_annotations.PrintWarning() 277 bb_annotations.PrintWarning()
302 print 'USB reset stage failed, wait for any device to come back.' 278 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, 335 # devices with critically low battery. Remove those devices from testing,
360 # allowing build to continue with good devices. 336 # allowing build to continue with good devices.
361 return 1 337 return 1
362 338
363 if not devices: 339 if not devices:
364 return 1 340 return 1
365 341
366 342
367 if __name__ == '__main__': 343 if __name__ == '__main__':
368 sys.exit(main()) 344 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device/device_list.py » ('j') | build/android/pylib/device/device_list.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698