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

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

Issue 39833003: Android: kill all adb instances before trying to restart usb. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | no next file » | 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
11 import psutil
12 import signal
11 import smtplib 13 import smtplib
12 import subprocess 14 import subprocess
13 import sys 15 import sys
14 import re 16 import re
15 import urllib 17 import urllib
16 18
17 import bb_annotations 19 import bb_annotations
18 import bb_utils 20 import bb_utils
19 21
20 sys.path.append(os.path.join(os.path.dirname(__file__), 22 sys.path.append(os.path.join(os.path.dirname(__file__),
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 failed_restart = True 236 failed_restart = True
235 else: 237 else:
236 print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev) 238 print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev)
237 239
238 if failed_restart: 240 if failed_restart:
239 return 1 241 return 1
240 242
241 return 0 243 return 0
242 244
243 245
246 def KillAllAdb():
247 def GetAllAdb():
248 for p in psutil.process_iter():
249 if 'adb' in p.name or 'adb' in ' '.join(p.cmdline):
250 yield p
251
252 for sig in [signal.SIGTERM, signal.SIGQUIT, signal.SIGKILL]:
253 for p in GetAllAdb():
254 try:
255 print 'kill %d %d (%s [%s])' % (sig, p.pid, p.name,
256 ' '.join(p.cmdline))
257 p.send_signal(sig)
258 except psutil.error.NoSuchProcess:
259 pass
260 for p in GetAllAdb():
261 print 'Unable to kill %d (%s [%s])' % (p.pid, p.name, ' '.join(p.cmdline))
262
263
244 def main(): 264 def main():
245 parser = optparse.OptionParser() 265 parser = optparse.OptionParser()
246 parser.add_option('', '--out-dir', 266 parser.add_option('', '--out-dir',
247 help='Directory where the device path is stored', 267 help='Directory where the device path is stored',
248 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) 268 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out'))
249 parser.add_option('--no-provisioning-check', action='store_true', 269 parser.add_option('--no-provisioning-check', action='store_true',
250 help='Will not check if devices are provisioned properly.') 270 help='Will not check if devices are provisioned properly.')
251 parser.add_option('--device-status-dashboard', action='store_true', 271 parser.add_option('--device-status-dashboard', action='store_true',
252 help='Output device status data for dashboard.') 272 help='Output device status data for dashboard.')
253 parser.add_option('--restart-usb', action='store_true', 273 parser.add_option('--restart-usb', action='store_true',
254 help='Restart USB ports before running device check.') 274 help='Restart USB ports before running device check.')
255 options, args = parser.parse_args() 275 options, args = parser.parse_args()
256 if args: 276 if args:
257 parser.error('Unknown options %s' % args) 277 parser.error('Unknown options %s' % args)
258 278
259 if options.restart_usb: 279 if options.restart_usb:
280 KillAllAdb()
260 rc = RestartUsb() 281 rc = RestartUsb()
261 if rc: 282 if rc:
262 return 1 283 return 1
263 284
264 devices = android_commands.GetAttachedDevices() 285 devices = android_commands.GetAttachedDevices()
265 # TODO(navabi): Test to make sure this fails and then fix call 286 # TODO(navabi): Test to make sure this fails and then fix call
266 offline_devices = android_commands.GetAttachedDevices(hardware=False, 287 offline_devices = android_commands.GetAttachedDevices(hardware=False,
267 emulator=False, 288 emulator=False,
268 offline=True) 289 offline=True)
269 290
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 # devices with critically low battery or install speed. Remove those devices 330 # devices with critically low battery or install speed. Remove those devices
310 # from testing, allowing build to continue with good devices. 331 # from testing, allowing build to continue with good devices.
311 return 1 332 return 1
312 333
313 if not devices: 334 if not devices:
314 return 1 335 return 1
315 336
316 337
317 if __name__ == '__main__': 338 if __name__ == '__main__':
318 sys.exit(main()) 339 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698