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

Side by Side Diff: scripts/slave/recipe_modules/chromium_android/api.py

Issue 2059993002: [Android] Move to new device status and recovery scripts. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: rebase and retrain Created 4 years, 5 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
« no previous file with comments | « no previous file | scripts/slave/recipe_modules/chromium_android/example.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 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import contextlib 5 import contextlib
6 import datetime 6 import datetime
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 import sys 10 import sys
(...skipping 14 matching lines...) Expand all
25 25
26 def get_config_defaults(self): 26 def get_config_defaults(self):
27 return { 27 return {
28 'REVISION': self.m.properties.get('revision', ''), 28 'REVISION': self.m.properties.get('revision', ''),
29 'CHECKOUT_PATH': self.m.path['checkout'], 29 'CHECKOUT_PATH': self.m.path['checkout'],
30 } 30 }
31 31
32 @property 32 @property
33 def devices(self): 33 def devices(self):
34 assert self._devices is not None,\ 34 assert self._devices is not None,\
35 'devices is only available after device_status_check()' 35 'devices is only available after device_status()'
36 return self._devices 36 return self._devices
37 37
38 @property 38 @property
39 def out_path(self): 39 def out_path(self):
40 return self.m.path['checkout'].join('out') 40 return self.m.path['checkout'].join('out')
41 41
42 @property 42 @property
43 def coverage_dir(self): 43 def coverage_dir(self):
44 return self.out_path.join(self.c.BUILD_CONFIG, 'coverage') 44 return self.out_path.join(self.c.BUILD_CONFIG, 'coverage')
45 45
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 args = ['--verbose', '--adb-path', self.m.adb.adb_path()] 321 args = ['--verbose', '--adb-path', self.m.adb.adb_path()]
322 return self.m.python('authorize_adb_devices', script, args, infra_step=True, 322 return self.m.python('authorize_adb_devices', script, args, infra_step=True,
323 env=self.m.chromium.get_env()) 323 env=self.m.chromium.get_env())
324 324
325 def detect_and_setup_devices(self, restart_usb=False, skip_wipe=False, 325 def detect_and_setup_devices(self, restart_usb=False, skip_wipe=False,
326 disable_location=False, min_battery_level=None, 326 disable_location=False, min_battery_level=None,
327 disable_network=False, disable_java_debug=False, 327 disable_network=False, disable_java_debug=False,
328 reboot_timeout=None, max_battery_temp=None, 328 reboot_timeout=None, max_battery_temp=None,
329 remove_system_webview=False): 329 remove_system_webview=False):
330 self.authorize_adb_devices() 330 self.authorize_adb_devices()
331 self.device_status_check(restart_usb=restart_usb) 331 self.device_recovery()
332 self.provision_devices( 332 self.provision_devices(
333 skip_wipe=skip_wipe, disable_location=disable_location, 333 skip_wipe=skip_wipe, disable_location=disable_location,
334 min_battery_level=min_battery_level, disable_network=disable_network, 334 min_battery_level=min_battery_level, disable_network=disable_network,
335 disable_java_debug=disable_java_debug, reboot_timeout=reboot_timeout, 335 disable_java_debug=disable_java_debug, reboot_timeout=reboot_timeout,
336 max_battery_temp=max_battery_temp, 336 max_battery_temp=max_battery_temp,
337 remove_system_webview=remove_system_webview) 337 remove_system_webview=remove_system_webview)
338 self.device_status()
338 339
339 @property 340 @property
340 def blacklist_file(self): 341 def blacklist_file(self):
341 return self.out_path.join('bad_devices.json') 342 return self.out_path.join('bad_devices.json')
342 343
343
344 def revert_device_file_format(self): 344 def revert_device_file_format(self):
345 # If current device file is jsonified, revert it back to original format. 345 # If current device file is jsonified, revert it back to original format.
346 if self.m.path.exists(self.known_devices_file): 346 if self.m.path.exists(self.known_devices_file):
347 with self.m.step.nest('fix_device_file_format'): 347 with self.m.step.nest('fix_device_file_format'):
348 file_contents = self.m.file.read( 348 file_contents = self.m.file.read(
349 'read_device_file', self.known_devices_file, 349 'read_device_file', self.known_devices_file,
350 test_data='device1\ndevice2\ndevice3') 350 test_data='device1\ndevice2\ndevice3')
351 try: 351 try:
352 devices = json.loads(file_contents) 352 devices = json.loads(file_contents)
353 self.m.step.active_result.presentation.step_text += ( 353 self.m.step.active_result.presentation.step_text += (
354 'file format is json, reverting') 354 'file format is json, reverting')
355 old_format = '\n'.join(devices) 355 old_format = '\n'.join(devices)
356 self.m.file.write( 356 self.m.file.write(
357 'revert_device_file', self.known_devices_file, old_format) 357 'revert_device_file', self.known_devices_file, old_format)
358 except ValueError: 358 except ValueError:
359 # File wasn't json, so no need to revert. 359 # File wasn't json, so no need to revert.
360 self.m.step.active_result.presentation.step_text += ( 360 self.m.step.active_result.presentation.step_text += (
361 'file format is compatible') 361 'file format is compatible')
362 362
363 def device_status_check(self, restart_usb=False, **kwargs): 363 # TODO(rnephew): Get rid of this when everything calls device_recovery and
364 # TODO(bpastene): Remove once chromium revisions prior to 364 # device_status directly.
365 # crrev.com/1faecde0c03013b6cd725da413339c60223f8948 are no longer tested. 365 def device_status_check(self):
366 # See crbug.com/619707 for context. 366 self.device_recovery()
367 self.device_status()
368
369
370 def device_recovery(self, restart_usb=False, **kwargs):
367 self.revert_device_file_format() 371 self.revert_device_file_format()
372 args = [
373 '--blacklist-file', self.blacklist_file,
374 '--known-devices-file', self.known_devices_file,
375 '--adb-path', self.m.adb.adb_path(),
376 '-v'
377 ]
378 self.m.step(
379 'device_recovery',
380 [self.m.path['checkout'].join('third_party', 'catapult', 'devil',
381 'devil', 'android', 'tools',
382 'device_recovery.py')] + args,
383 env=self.m.chromium.get_env(),
384 infra_step=True,
385 **kwargs)
368 386
369 # TODO(phajdan.jr): Remove path['build'] usage, http://crbug.com/437264 . 387 def device_status(self, **kwargs):
388 self.revert_device_file_format()
389 buildbot_file = '/home/chrome-bot/.adb_device_info'
370 args = [ 390 args = [
391 '--json-output', self.m.json.output(),
392 '--blacklist-file', self.blacklist_file,
393 '--known-devices-file', self.known_devices_file,
394 '--buildbot-path', buildbot_file,
371 '--adb-path', self.m.adb.adb_path(), 395 '--adb-path', self.m.adb.adb_path(),
372 '--blacklist-file', self.blacklist_file, 396 '-v', '--overwrite-known-devices-files',
373 '--json-output', self.m.json.output(),
374 '--known-devices-file', self.known_devices_file
375 ] 397 ]
376 if restart_usb:
377 args += ['--restart-usb']
378
379 try: 398 try:
380 result = self.m.step( 399 result = self.m.step(
381 'device_status_check', 400 'device_status',
382 [self.m.path['checkout'].join('build', 'android', 'buildbot', 401 [self.m.path['checkout'].join('third_party', 'catapult', 'devil',
383 'bb_device_status_check.py')] + args, 402 'devil', 'android', 'tools',
403 'device_status.py')] + args,
384 step_test_data=lambda: self.m.json.test_api.output([ 404 step_test_data=lambda: self.m.json.test_api.output([
385 { 405 {
386 "battery": { 406 "battery": {
387 "status": "5", 407 "status": "5",
388 "scale": "100", 408 "scale": "100",
389 "temperature": "249", 409 "temperature": "249",
390 "level": "100", 410 "level": "100",
391 "AC powered": "false", 411 "AC powered": "false",
392 "health": "2", 412 "health": "2",
393 "voltage": "4286", 413 "voltage": "4286",
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 if emulators: 527 if emulators:
508 args.append('--emulators') 528 args.append('--emulators')
509 result = self.m.python( 529 result = self.m.python(
510 'provision_devices', 530 'provision_devices',
511 self.m.path['checkout'].join( 531 self.m.path['checkout'].join(
512 'build', 'android', 'provision_devices.py'), 532 'build', 'android', 'provision_devices.py'),
513 args=args, 533 args=args,
514 env=self.m.chromium.get_env(), 534 env=self.m.chromium.get_env(),
515 infra_step=True, 535 infra_step=True,
516 **kwargs) 536 **kwargs)
517 blacklisted_devices = result.json.output
518 if blacklisted_devices:
519 result.presentation.status = self.m.step.WARNING
520 for d in blacklisted_devices:
521 key = 'blacklisted %s' % d
522 result.presentation.logs[key] = [d]
523 537
524 def apk_path(self, apk): 538 def apk_path(self, apk):
525 return self.m.chromium.output_dir.join('apks', apk) if apk else None 539 return self.m.chromium.output_dir.join('apks', apk) if apk else None
526 540
527 def adb_install_apk(self, apk, allow_downgrade=False, devices=None): 541 def adb_install_apk(self, apk, allow_downgrade=False, devices=None):
528 install_cmd = [ 542 install_cmd = [
529 self.m.path['checkout'].join('build', 543 self.m.path['checkout'].join('build',
530 'android', 544 'android',
531 'adb_install_apk.py'), 545 'adb_install_apk.py'),
532 apk, '-v', '--blacklist-file', self.blacklist_file, 546 apk, '-v', '--blacklist-file', self.blacklist_file,
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 self.create_adb_symlink() 940 self.create_adb_symlink()
927 if self.c.gce_setup: 941 if self.c.gce_setup:
928 self.launch_gce_instances(snapshot=self.c.gce_snapshot, 942 self.launch_gce_instances(snapshot=self.c.gce_snapshot,
929 count=self.c.gce_count) 943 count=self.c.gce_count)
930 self.spawn_logcat_monitor() 944 self.spawn_logcat_monitor()
931 self.provision_devices(emulators=True, 945 self.provision_devices(emulators=True,
932 remove_system_webview=remove_system_webview) 946 remove_system_webview=remove_system_webview)
933 else: 947 else:
934 self.spawn_logcat_monitor() 948 self.spawn_logcat_monitor()
935 self.authorize_adb_devices() 949 self.authorize_adb_devices()
936 self.device_status_check() 950 self.device_recovery()
937 if perf_setup: 951 if perf_setup:
938 kwargs = { 952 kwargs = {
939 'min_battery_level': 95, 953 'min_battery_level': 95,
940 'disable_network': True, 954 'disable_network': True,
941 'disable_java_debug': True, 955 'disable_java_debug': True,
942 'max_battery_temp': 350} 956 'max_battery_temp': 350}
943 else: 957 else:
944 kwargs = {} 958 kwargs = {}
945 self.provision_devices(remove_system_webview=remove_system_webview, 959 self.provision_devices(remove_system_webview=remove_system_webview,
946 **kwargs) 960 **kwargs)
961 self.device_status()
947 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1: 962 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1:
948 self.asan_device_setup() 963 self.asan_device_setup()
949 964
950 self.spawn_device_monitor() 965 self.spawn_device_monitor()
951 966
952 def common_tests_final_steps(self, logcat_gs_bucket='chromium-android'): 967 def common_tests_final_steps(self, logcat_gs_bucket='chromium-android'):
953 if not self.c.gce_setup: 968 if not self.c.gce_setup:
954 self.shutdown_device_monitor() 969 self.shutdown_device_monitor()
955 self.logcat_dump(gs_bucket=logcat_gs_bucket) 970 self.logcat_dump(gs_bucket=logcat_gs_bucket)
956 self.stack_tool_steps() 971 self.stack_tool_steps()
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 script = self.c.test_runner 1374 script = self.c.test_runner
1360 if wrapper_script_suite_name: 1375 if wrapper_script_suite_name:
1361 script = self.m.chromium.output_dir.join('bin', 'run_%s' % 1376 script = self.m.chromium.output_dir.join('bin', 'run_%s' %
1362 wrapper_script_suite_name) 1377 wrapper_script_suite_name)
1363 else: 1378 else:
1364 env = kwargs.get('env', {}) 1379 env = kwargs.get('env', {})
1365 env['CHROMIUM_OUTPUT_DIR'] = env.get('CHROMIUM_OUTPUT_DIR', 1380 env['CHROMIUM_OUTPUT_DIR'] = env.get('CHROMIUM_OUTPUT_DIR',
1366 self.m.chromium.output_dir) 1381 self.m.chromium.output_dir)
1367 kwargs['env'] = env 1382 kwargs['env'] = env
1368 return self.m.python(step_name, script, args, **kwargs) 1383 return self.m.python(step_name, script, args, **kwargs)
OLDNEW
« no previous file with comments | « no previous file | scripts/slave/recipe_modules/chromium_android/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698