Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 urllib | 10 import urllib |
| 11 | 11 |
| 12 from recipe_engine.types import freeze | 12 from recipe_engine.types import freeze |
| 13 from recipe_engine import recipe_api | 13 from recipe_engine import recipe_api |
| 14 | 14 |
| 15 | 15 |
| 16 def _TimestampToIsoFormat(timestamp): | 16 def _TimestampToIsoFormat(timestamp): |
| 17 return datetime.datetime.utcfromtimestamp(timestamp).strftime('%Y%m%dT%H%M%S') | 17 return datetime.datetime.utcfromtimestamp(timestamp).strftime('%Y%m%dT%H%M%S') |
| 18 | 18 |
| 19 | 19 |
| 20 class AndroidApi(recipe_api.RecipeApi): | 20 class AndroidApi(recipe_api.RecipeApi): |
| 21 def __init__(self, **kwargs): | 21 def __init__(self, **kwargs): |
| 22 super(AndroidApi, self).__init__(**kwargs) | 22 super(AndroidApi, self).__init__(**kwargs) |
| 23 self._devices = None | 23 self._devices = None |
| 24 self._file_changes_path = None | 24 self._file_changes_path = None |
| 25 self._known_devices_path = None | |
| 25 | 26 |
| 26 def get_config_defaults(self): | 27 def get_config_defaults(self): |
| 27 return { | 28 return { |
| 28 'REVISION': self.m.properties.get('revision', ''), | 29 'REVISION': self.m.properties.get('revision', ''), |
| 29 'CHECKOUT_PATH': self.m.path['checkout'], | 30 'CHECKOUT_PATH': self.m.path['checkout'], |
| 30 } | 31 } |
| 31 | 32 |
| 32 @property | 33 @property |
| 33 def devices(self): | 34 def devices(self): |
| 34 assert self._devices is not None,\ | 35 assert self._devices is not None,\ |
| 35 'devices is only available after device_status_check()' | 36 'devices is only available after device_status()' |
| 36 return self._devices | 37 return self._devices |
| 37 | 38 |
| 38 @property | 39 @property |
| 39 def out_path(self): | 40 def out_path(self): |
| 40 return self.m.path['checkout'].join('out') | 41 return self.m.path['checkout'].join('out') |
| 41 | 42 |
| 42 @property | 43 @property |
| 43 def coverage_dir(self): | 44 def coverage_dir(self): |
| 44 return self.out_path.join(self.c.BUILD_CONFIG, 'coverage') | 45 return self.out_path.join(self.c.BUILD_CONFIG, 'coverage') |
| 45 | 46 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 args = ['--verbose', '--adb-path', self.m.adb.adb_path()] | 318 args = ['--verbose', '--adb-path', self.m.adb.adb_path()] |
| 318 return self.m.python('authorize_adb_devices', script, args, infra_step=True, | 319 return self.m.python('authorize_adb_devices', script, args, infra_step=True, |
| 319 env=self.m.chromium.get_env()) | 320 env=self.m.chromium.get_env()) |
| 320 | 321 |
| 321 def detect_and_setup_devices(self, restart_usb=False, skip_wipe=False, | 322 def detect_and_setup_devices(self, restart_usb=False, skip_wipe=False, |
| 322 disable_location=False, min_battery_level=None, | 323 disable_location=False, min_battery_level=None, |
| 323 disable_network=False, disable_java_debug=False, | 324 disable_network=False, disable_java_debug=False, |
| 324 reboot_timeout=None, max_battery_temp=None, | 325 reboot_timeout=None, max_battery_temp=None, |
| 325 remove_system_webview=False): | 326 remove_system_webview=False): |
| 326 self.authorize_adb_devices() | 327 self.authorize_adb_devices() |
| 327 self.device_status_check(restart_usb=restart_usb) | 328 self.device_recovery() |
| 328 self.provision_devices( | 329 self.provision_devices( |
| 329 skip_wipe=skip_wipe, disable_location=disable_location, | 330 skip_wipe=skip_wipe, disable_location=disable_location, |
| 330 min_battery_level=min_battery_level, disable_network=disable_network, | 331 min_battery_level=min_battery_level, disable_network=disable_network, |
| 331 disable_java_debug=disable_java_debug, reboot_timeout=reboot_timeout, | 332 disable_java_debug=disable_java_debug, reboot_timeout=reboot_timeout, |
| 332 max_battery_temp=max_battery_temp, | 333 max_battery_temp=max_battery_temp, |
| 333 remove_system_webview=remove_system_webview) | 334 remove_system_webview=remove_system_webview) |
| 335 self.device_status() | |
| 334 | 336 |
| 335 @property | 337 @property |
| 336 def blacklist_file(self): | 338 def blacklist_file(self): |
| 337 return self.out_path.join('bad_devices.json') | 339 return self.out_path.join('bad_devices.json') |
| 338 | 340 |
| 339 def device_status_check(self, restart_usb=False, **kwargs): | 341 # TODO(rnephew): Get rid of this when everything calls device_recovery and |
| 340 # TODO(phajdan.jr): Remove path['build'] usage, http://crbug.com/437264 . | 342 # device_status directly. |
| 341 devices_path = self.m.path['build'].join('site_config', '.known_devices') | 343 def device_status_check(self): |
| 344 self.device_recovery() | |
| 345 self.device_status() | |
| 346 | |
| 347 @property | |
| 348 def known_devices_path(self): | |
| 349 if self._known_devices_path is None: | |
| 350 self._known_devices_path = self.m.path['build'].join('site_config', | |
| 351 '.known_devices') | |
| 352 return self._known_devices_path | |
| 353 | |
| 354 def device_recovery(self, restart_usb=False, **kwargs): | |
| 342 args = [ | 355 args = [ |
| 343 '--adb-path', self.m.adb.adb_path(), | |
| 344 '--blacklist-file', self.blacklist_file, | 356 '--blacklist-file', self.blacklist_file, |
|
jbudorick
2016/06/24 14:40:47
This should still be specifying --adb-path
rnephew (Reviews Here)
2016/06/24 17:35:06
Done.
| |
| 357 '--known-devices-file', self.known_devices_path, | |
| 358 '-v' | |
| 359 ] | |
| 360 self.m.step( | |
| 361 'device_recovery', | |
| 362 [self.m.path['checkout'].join('third_party', 'catapult', 'devil', | |
| 363 'devil', 'android', 'tools', | |
| 364 'device_recovery.py')] + args, | |
| 365 env=self.m.chromium.get_env(), | |
| 366 infra_step=True, | |
| 367 **kwargs) | |
| 368 | |
| 369 def device_status(self, **kwargs): | |
| 370 buildbot_file = '/home/chrome-bot/.adb_device_info' | |
| 371 args = [ | |
| 345 '--json-output', self.m.json.output(), | 372 '--json-output', self.m.json.output(), |
|
jbudorick
2016/06/24 14:40:47
This also should still be specifying --adb-path
rnephew (Reviews Here)
2016/06/24 17:35:06
Done.
| |
| 346 '--known-devices-file', devices_path, | 373 '--blacklist-file', self.blacklist_file, |
| 374 '--known-devices-file', self.known_devices_path, | |
| 375 '--buildbot-path', buildbot_file, | |
| 376 '-v', '--overwrite-known-devices-files', | |
| 347 ] | 377 ] |
| 348 if restart_usb: | |
| 349 args += ['--restart-usb'] | |
| 350 | |
| 351 try: | 378 try: |
| 352 result = self.m.step( | 379 result = self.m.step( |
| 353 'device_status_check', | 380 'device_status', |
| 354 [self.m.path['checkout'].join('build', 'android', 'buildbot', | 381 [self.m.path['checkout'].join('third_party', 'catapult', 'devil', |
| 355 'bb_device_status_check.py')] + args, | 382 'devil', 'android', 'tools', |
| 383 'device_status.py')] + args, | |
| 356 step_test_data=lambda: self.m.json.test_api.output([ | 384 step_test_data=lambda: self.m.json.test_api.output([ |
| 357 { | 385 { |
| 358 "battery": { | 386 "battery": { |
| 359 "status": "5", | 387 "status": "5", |
| 360 "scale": "100", | 388 "scale": "100", |
| 361 "temperature": "249", | 389 "temperature": "249", |
| 362 "level": "100", | 390 "level": "100", |
| 363 "AC powered": "false", | 391 "AC powered": "false", |
| 364 "health": "2", | 392 "health": "2", |
| 365 "voltage": "4286", | 393 "voltage": "4286", |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 if emulators: | 507 if emulators: |
| 480 args.append('--emulators') | 508 args.append('--emulators') |
| 481 result = self.m.python( | 509 result = self.m.python( |
| 482 'provision_devices', | 510 'provision_devices', |
| 483 self.m.path['checkout'].join( | 511 self.m.path['checkout'].join( |
| 484 'build', 'android', 'provision_devices.py'), | 512 'build', 'android', 'provision_devices.py'), |
| 485 args=args, | 513 args=args, |
| 486 env=self.m.chromium.get_env(), | 514 env=self.m.chromium.get_env(), |
| 487 infra_step=True, | 515 infra_step=True, |
| 488 **kwargs) | 516 **kwargs) |
| 489 blacklisted_devices = result.json.output | |
| 490 if blacklisted_devices: | |
| 491 result.presentation.status = self.m.step.WARNING | |
| 492 for d in blacklisted_devices: | |
| 493 key = 'blacklisted %s' % d | |
| 494 result.presentation.logs[key] = [d] | |
| 495 | 517 |
| 496 def apk_path(self, apk): | 518 def apk_path(self, apk): |
| 497 return self.m.chromium.output_dir.join('apks', apk) if apk else None | 519 return self.m.chromium.output_dir.join('apks', apk) if apk else None |
| 498 | 520 |
| 499 def adb_install_apk(self, apk, allow_downgrade=False, devices=None): | 521 def adb_install_apk(self, apk, allow_downgrade=False, devices=None): |
| 500 install_cmd = [ | 522 install_cmd = [ |
| 501 self.m.path['checkout'].join('build', | 523 self.m.path['checkout'].join('build', |
| 502 'android', | 524 'android', |
| 503 'adb_install_apk.py'), | 525 'adb_install_apk.py'), |
| 504 apk, '-v', '--blacklist-file', self.blacklist_file, | 526 apk, '-v', '--blacklist-file', self.blacklist_file, |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 self.create_adb_symlink() | 890 self.create_adb_symlink() |
| 869 if self.c.gce_setup: | 891 if self.c.gce_setup: |
| 870 self.launch_gce_instances(snapshot=self.c.gce_snapshot, | 892 self.launch_gce_instances(snapshot=self.c.gce_snapshot, |
| 871 count=self.c.gce_count) | 893 count=self.c.gce_count) |
| 872 self.spawn_logcat_monitor() | 894 self.spawn_logcat_monitor() |
| 873 self.provision_devices(emulators=True, | 895 self.provision_devices(emulators=True, |
| 874 remove_system_webview=remove_system_webview) | 896 remove_system_webview=remove_system_webview) |
| 875 else: | 897 else: |
| 876 self.spawn_logcat_monitor() | 898 self.spawn_logcat_monitor() |
| 877 self.authorize_adb_devices() | 899 self.authorize_adb_devices() |
| 878 self.device_status_check() | 900 self.device_recovery() |
| 879 if perf_setup: | 901 if perf_setup: |
| 880 kwargs = { | 902 kwargs = { |
| 881 'min_battery_level': 95, | 903 'min_battery_level': 95, |
| 882 'disable_network': True, | 904 'disable_network': True, |
| 883 'disable_java_debug': True, | 905 'disable_java_debug': True, |
| 884 'max_battery_temp': 350} | 906 'max_battery_temp': 350} |
| 885 else: | 907 else: |
| 886 kwargs = {} | 908 kwargs = {} |
| 887 self.provision_devices(remove_system_webview=remove_system_webview, | 909 self.provision_devices(remove_system_webview=remove_system_webview, |
| 888 **kwargs) | 910 **kwargs) |
| 911 self.device_status() | |
| 889 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1: | 912 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1: |
| 890 self.asan_device_setup() | 913 self.asan_device_setup() |
| 891 | 914 |
| 892 self.spawn_device_monitor() | 915 self.spawn_device_monitor() |
| 893 | 916 |
| 894 def common_tests_final_steps(self, logcat_gs_bucket='chromium-android'): | 917 def common_tests_final_steps(self, logcat_gs_bucket='chromium-android'): |
| 895 if not self.c.gce_setup: | 918 if not self.c.gce_setup: |
| 896 self.shutdown_device_monitor() | 919 self.shutdown_device_monitor() |
| 897 self.logcat_dump(gs_bucket=logcat_gs_bucket) | 920 self.logcat_dump(gs_bucket=logcat_gs_bucket) |
| 898 self.stack_tool_steps() | 921 self.stack_tool_steps() |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1301 script = self.c.test_runner | 1324 script = self.c.test_runner |
| 1302 if wrapper_script_suite_name: | 1325 if wrapper_script_suite_name: |
| 1303 script = self.m.chromium.output_dir.join('bin', 'run_%s' % | 1326 script = self.m.chromium.output_dir.join('bin', 'run_%s' % |
| 1304 wrapper_script_suite_name) | 1327 wrapper_script_suite_name) |
| 1305 else: | 1328 else: |
| 1306 env = kwargs.get('env', {}) | 1329 env = kwargs.get('env', {}) |
| 1307 env['CHROMIUM_OUTPUT_DIR'] = env.get('CHROMIUM_OUTPUT_DIR', | 1330 env['CHROMIUM_OUTPUT_DIR'] = env.get('CHROMIUM_OUTPUT_DIR', |
| 1308 self.m.chromium.output_dir) | 1331 self.m.chromium.output_dir) |
| 1309 kwargs['env'] = env | 1332 kwargs['env'] = env |
| 1310 return self.m.python(step_name, script, args, **kwargs) | 1333 return self.m.python(step_name, script, args, **kwargs) |
| OLD | NEW |