| 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 sys | 10 import sys |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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()' | 35 'devices is only available after device_status_check()' |
| 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 Loading... |
| 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_recovery() | 331 self.device_status_check(restart_usb=restart_usb) |
| 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() | |
| 339 | 338 |
| 340 @property | 339 @property |
| 341 def blacklist_file(self): | 340 def blacklist_file(self): |
| 342 return self.out_path.join('bad_devices.json') | 341 return self.out_path.join('bad_devices.json') |
| 343 | 342 |
| 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 # TODO(rnephew): Get rid of this when everything calls device_recovery and | 363 def device_status_check(self, restart_usb=False, **kwargs): |
| 364 # device_status directly. | 364 # TODO(bpastene): Remove once chromium revisions prior to |
| 365 def device_status_check(self): | 365 # crrev.com/1faecde0c03013b6cd725da413339c60223f8948 are no longer tested. |
| 366 self.device_recovery() | 366 # See crbug.com/619707 for context. |
| 367 self.device_status() | 367 self.revert_device_file_format() |
| 368 | 368 |
| 369 # TODO(phajdan.jr): Remove path['build'] usage, http://crbug.com/437264 . |
| 370 args = [ |
| 371 '--adb-path', self.m.adb.adb_path(), |
| 372 '--blacklist-file', self.blacklist_file, |
| 373 '--json-output', self.m.json.output(), |
| 374 '--known-devices-file', self.known_devices_file |
| 375 ] |
| 376 if restart_usb: |
| 377 args += ['--restart-usb'] |
| 369 | 378 |
| 370 def device_recovery(self, restart_usb=False, **kwargs): | |
| 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) | |
| 386 | |
| 387 def device_status(self, **kwargs): | |
| 388 self.revert_device_file_format() | |
| 389 buildbot_file = '/home/chrome-bot/.adb_device_info' | |
| 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, | |
| 395 '--adb-path', self.m.adb.adb_path(), | |
| 396 '-v', '--overwrite-known-devices-files', | |
| 397 ] | |
| 398 try: | 379 try: |
| 399 result = self.m.step( | 380 result = self.m.step( |
| 400 'device_status', | 381 'device_status_check', |
| 401 [self.m.path['checkout'].join('third_party', 'catapult', 'devil', | 382 [self.m.path['checkout'].join('build', 'android', 'buildbot', |
| 402 'devil', 'android', 'tools', | 383 'bb_device_status_check.py')] + args, |
| 403 'device_status.py')] + args, | |
| 404 step_test_data=lambda: self.m.json.test_api.output([ | 384 step_test_data=lambda: self.m.json.test_api.output([ |
| 405 { | 385 { |
| 406 "battery": { | 386 "battery": { |
| 407 "status": "5", | 387 "status": "5", |
| 408 "scale": "100", | 388 "scale": "100", |
| 409 "temperature": "249", | 389 "temperature": "249", |
| 410 "level": "100", | 390 "level": "100", |
| 411 "AC powered": "false", | 391 "AC powered": "false", |
| 412 "health": "2", | 392 "health": "2", |
| 413 "voltage": "4286", | 393 "voltage": "4286", |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 if emulators: | 507 if emulators: |
| 528 args.append('--emulators') | 508 args.append('--emulators') |
| 529 result = self.m.python( | 509 result = self.m.python( |
| 530 'provision_devices', | 510 'provision_devices', |
| 531 self.m.path['checkout'].join( | 511 self.m.path['checkout'].join( |
| 532 'build', 'android', 'provision_devices.py'), | 512 'build', 'android', 'provision_devices.py'), |
| 533 args=args, | 513 args=args, |
| 534 env=self.m.chromium.get_env(), | 514 env=self.m.chromium.get_env(), |
| 535 infra_step=True, | 515 infra_step=True, |
| 536 **kwargs) | 516 **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] |
| 537 | 523 |
| 538 def apk_path(self, apk): | 524 def apk_path(self, apk): |
| 539 return self.m.chromium.output_dir.join('apks', apk) if apk else None | 525 return self.m.chromium.output_dir.join('apks', apk) if apk else None |
| 540 | 526 |
| 541 def adb_install_apk(self, apk, allow_downgrade=False, devices=None): | 527 def adb_install_apk(self, apk, allow_downgrade=False, devices=None): |
| 542 install_cmd = [ | 528 install_cmd = [ |
| 543 self.m.path['checkout'].join('build', | 529 self.m.path['checkout'].join('build', |
| 544 'android', | 530 'android', |
| 545 'adb_install_apk.py'), | 531 'adb_install_apk.py'), |
| 546 apk, '-v', '--blacklist-file', self.blacklist_file, | 532 apk, '-v', '--blacklist-file', self.blacklist_file, |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 self.create_adb_symlink() | 926 self.create_adb_symlink() |
| 941 if self.c.gce_setup: | 927 if self.c.gce_setup: |
| 942 self.launch_gce_instances(snapshot=self.c.gce_snapshot, | 928 self.launch_gce_instances(snapshot=self.c.gce_snapshot, |
| 943 count=self.c.gce_count) | 929 count=self.c.gce_count) |
| 944 self.spawn_logcat_monitor() | 930 self.spawn_logcat_monitor() |
| 945 self.provision_devices(emulators=True, | 931 self.provision_devices(emulators=True, |
| 946 remove_system_webview=remove_system_webview) | 932 remove_system_webview=remove_system_webview) |
| 947 else: | 933 else: |
| 948 self.spawn_logcat_monitor() | 934 self.spawn_logcat_monitor() |
| 949 self.authorize_adb_devices() | 935 self.authorize_adb_devices() |
| 950 self.device_recovery() | 936 self.device_status_check() |
| 951 if perf_setup: | 937 if perf_setup: |
| 952 kwargs = { | 938 kwargs = { |
| 953 'min_battery_level': 95, | 939 'min_battery_level': 95, |
| 954 'disable_network': True, | 940 'disable_network': True, |
| 955 'disable_java_debug': True, | 941 'disable_java_debug': True, |
| 956 'max_battery_temp': 350} | 942 'max_battery_temp': 350} |
| 957 else: | 943 else: |
| 958 kwargs = {} | 944 kwargs = {} |
| 959 self.provision_devices(remove_system_webview=remove_system_webview, | 945 self.provision_devices(remove_system_webview=remove_system_webview, |
| 960 **kwargs) | 946 **kwargs) |
| 961 self.device_status() | |
| 962 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1: | 947 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1: |
| 963 self.asan_device_setup() | 948 self.asan_device_setup() |
| 964 | 949 |
| 965 self.spawn_device_monitor() | 950 self.spawn_device_monitor() |
| 966 | 951 |
| 967 def common_tests_final_steps(self, logcat_gs_bucket='chromium-android'): | 952 def common_tests_final_steps(self, logcat_gs_bucket='chromium-android'): |
| 968 if not self.c.gce_setup: | 953 if not self.c.gce_setup: |
| 969 self.shutdown_device_monitor() | 954 self.shutdown_device_monitor() |
| 970 self.logcat_dump(gs_bucket=logcat_gs_bucket) | 955 self.logcat_dump(gs_bucket=logcat_gs_bucket) |
| 971 self.stack_tool_steps() | 956 self.stack_tool_steps() |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 script = self.c.test_runner | 1359 script = self.c.test_runner |
| 1375 if wrapper_script_suite_name: | 1360 if wrapper_script_suite_name: |
| 1376 script = self.m.chromium.output_dir.join('bin', 'run_%s' % | 1361 script = self.m.chromium.output_dir.join('bin', 'run_%s' % |
| 1377 wrapper_script_suite_name) | 1362 wrapper_script_suite_name) |
| 1378 else: | 1363 else: |
| 1379 env = kwargs.get('env', {}) | 1364 env = kwargs.get('env', {}) |
| 1380 env['CHROMIUM_OUTPUT_DIR'] = env.get('CHROMIUM_OUTPUT_DIR', | 1365 env['CHROMIUM_OUTPUT_DIR'] = env.get('CHROMIUM_OUTPUT_DIR', |
| 1381 self.m.chromium.output_dir) | 1366 self.m.chromium.output_dir) |
| 1382 kwargs['env'] = env | 1367 kwargs['env'] = env |
| 1383 return self.m.python(step_name, script, args, **kwargs) | 1368 return self.m.python(step_name, script, args, **kwargs) |
| OLD | NEW |