| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 json | |
| 7 import logging | 6 import logging |
| 8 import os | 7 import os |
| 9 import posixpath | 8 import posixpath |
| 10 import re | 9 import re |
| 11 import sys | 10 import sys |
| 12 import tempfile | 11 import tempfile |
| 13 import time | 12 import time |
| 14 | 13 |
| 15 from devil.android import crash_handler | 14 from devil.android import crash_handler |
| 16 from devil.android import device_errors | 15 from devil.android import device_errors |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 57 |
| 59 LOGCAT_FILTERS = ['*:e', 'chromium:v', 'cr_*:v', 'DEBUG:I', | 58 LOGCAT_FILTERS = ['*:e', 'chromium:v', 'cr_*:v', 'DEBUG:I', |
| 60 'StrictMode:D', '%s:I' % _TAG] | 59 'StrictMode:D', '%s:I' % _TAG] |
| 61 | 60 |
| 62 EXTRA_SCREENSHOT_FILE = ( | 61 EXTRA_SCREENSHOT_FILE = ( |
| 63 'org.chromium.base.test.ScreenshotOnFailureStatement.ScreenshotFile') | 62 'org.chromium.base.test.ScreenshotOnFailureStatement.ScreenshotFile') |
| 64 | 63 |
| 65 EXTRA_UI_CAPTURE_DIR = ( | 64 EXTRA_UI_CAPTURE_DIR = ( |
| 66 'org.chromium.base.test.util.Screenshooter.ScreenshotDir') | 65 'org.chromium.base.test.util.Screenshooter.ScreenshotDir') |
| 67 | 66 |
| 68 _EXTRA_TEST_LIST = ( | |
| 69 'org.chromium.base.test.BaseChromiumAndroidJUnitRunner.TestList') | |
| 70 | |
| 71 UI_CAPTURE_DIRS = ['chromium_tests_root', 'UiCapture'] | 67 UI_CAPTURE_DIRS = ['chromium_tests_root', 'UiCapture'] |
| 72 | 68 |
| 73 FEATURE_ANNOTATION = 'Feature' | 69 FEATURE_ANNOTATION = 'Feature' |
| 74 RENDER_TEST_FEATURE_ANNOTATION = 'RenderTest' | 70 RENDER_TEST_FEATURE_ANNOTATION = 'RenderTest' |
| 75 | 71 |
| 76 # This needs to be kept in sync with formatting in |RenderUtils.imageName| | 72 # This needs to be kept in sync with formatting in |RenderUtils.imageName| |
| 77 RE_RENDER_IMAGE_NAME = re.compile( | 73 RE_RENDER_IMAGE_NAME = re.compile( |
| 78 r'(?P<test_class>\w+)\.' | 74 r'(?P<test_class>\w+)\.' |
| 79 r'(?P<description>[-\w]+)\.' | 75 r'(?P<description>[-\w]+)\.' |
| 80 r'(?P<device_model_sdk>[-\w]+)\.png') | 76 r'(?P<device_model_sdk>[-\w]+)\.png') |
| 81 | 77 |
| 82 @contextlib.contextmanager | 78 @contextlib.contextmanager |
| 83 def _LogTestEndpoints(device, test_name): | 79 def _LogTestEndpoints(device, test_name): |
| 84 device.RunShellCommand( | 80 device.RunShellCommand( |
| 85 ['log', '-p', 'i', '-t', _TAG, 'START %s' % test_name], | 81 ['log', '-p', 'i', '-t', _TAG, 'START %s' % test_name], |
| 86 check_return=True) | 82 check_return=True) |
| 87 try: | 83 try: |
| 88 yield | 84 yield |
| 89 finally: | 85 finally: |
| 90 device.RunShellCommand( | 86 device.RunShellCommand( |
| 91 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], | 87 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], |
| 92 check_return=True) | 88 check_return=True) |
| 93 | 89 |
| 94 # TODO(jbudorick): Make this private once the instrumentation test_runner | 90 # TODO(jbudorick): Make this private once the instrumentation test_runner is |
| 95 # is deprecated. | 91 # deprecated. |
| 96 def DidPackageCrashOnDevice(package_name, device): | 92 def DidPackageCrashOnDevice(package_name, device): |
| 97 # Dismiss any error dialogs. Limit the number in case we have an error | 93 # Dismiss any error dialogs. Limit the number in case we have an error |
| 98 # loop or we are failing to dismiss. | 94 # loop or we are failing to dismiss. |
| 99 try: | 95 try: |
| 100 for _ in xrange(10): | 96 for _ in xrange(10): |
| 101 package = device.DismissCrashDialogIfNeeded() | 97 package = device.DismissCrashDialogIfNeeded() |
| 102 if not package: | 98 if not package: |
| 103 return False | 99 return False |
| 104 # Assume test package convention of ".test" suffix | 100 # Assume test package convention of ".test" suffix |
| 105 if package in package_name: | 101 if package in package_name: |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 if not str(device) in self._flag_changers: | 298 if not str(device) in self._flag_changers: |
| 303 self._flag_changers[str(device)] = flag_changer.FlagChanger( | 299 self._flag_changers[str(device)] = flag_changer.FlagChanger( |
| 304 device, self._test_instance.package_info.cmdline_file) | 300 device, self._test_instance.package_info.cmdline_file) |
| 305 | 301 |
| 306 #override | 302 #override |
| 307 def _CreateShards(self, tests): | 303 def _CreateShards(self, tests): |
| 308 return tests | 304 return tests |
| 309 | 305 |
| 310 #override | 306 #override |
| 311 def _GetTests(self): | 307 def _GetTests(self): |
| 312 tests = None | 308 tests = self._test_instance.GetTests() |
| 313 if self._test_instance.junit4_runner_class: | |
| 314 raw_tests = self._GetTestsFromRunner() | |
| 315 tests = self._test_instance.ProcessRawTests(raw_tests) | |
| 316 else: | |
| 317 tests = self._test_instance.GetTests() | |
| 318 tests = self._ApplyExternalSharding( | 309 tests = self._ApplyExternalSharding( |
| 319 tests, self._test_instance.external_shard_index, | 310 tests, self._test_instance.external_shard_index, |
| 320 self._test_instance.total_external_shards) | 311 self._test_instance.total_external_shards) |
| 321 return tests | 312 return tests |
| 322 | 313 |
| 323 #override | 314 #override |
| 324 def _GetUniqueTestName(self, test): | 315 def _GetUniqueTestName(self, test): |
| 325 return instrumentation_test_instance.GetUniqueTestName(test) | 316 return instrumentation_test_instance.GetUniqueTestName(test) |
| 326 | 317 |
| 327 #override | 318 #override |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 extras.update( | 363 extras.update( |
| 373 self._test_instance.GetDriverEnvironmentVars( | 364 self._test_instance.GetDriverEnvironmentVars( |
| 374 test_list=test_names)) | 365 test_list=test_names)) |
| 375 timeout = sum(timeouts) | 366 timeout = sum(timeouts) |
| 376 else: | 367 else: |
| 377 test_name = instrumentation_test_instance.GetTestName(test) | 368 test_name = instrumentation_test_instance.GetTestName(test) |
| 378 test_display_name = self._GetUniqueTestName(test) | 369 test_display_name = self._GetUniqueTestName(test) |
| 379 if test['is_junit4']: | 370 if test['is_junit4']: |
| 380 target = '%s/%s' % ( | 371 target = '%s/%s' % ( |
| 381 self._test_instance.test_package, | 372 self._test_instance.test_package, |
| 382 self._test_instance.junit4_runner_class) | 373 self._test_instance.test_runner_junit4) |
| 383 else: | 374 else: |
| 384 target = '%s/%s' % ( | 375 target = '%s/%s' % ( |
| 385 self._test_instance.test_package, | 376 self._test_instance.test_package, self._test_instance.test_runner) |
| 386 self._test_instance.junit3_runner_class) | |
| 387 extras['class'] = test_name | 377 extras['class'] = test_name |
| 388 if 'flags' in test and test['flags']: | 378 if 'flags' in test and test['flags']: |
| 389 flags_to_add.extend(test['flags']) | 379 flags_to_add.extend(test['flags']) |
| 390 timeout = self._GetTimeoutFromAnnotations( | 380 timeout = self._GetTimeoutFromAnnotations( |
| 391 test['annotations'], test_display_name) | 381 test['annotations'], test_display_name) |
| 392 | 382 |
| 393 test_timeout_scale = self._GetTimeoutScaleFromAnnotations( | 383 test_timeout_scale = self._GetTimeoutScaleFromAnnotations( |
| 394 test['annotations']) | 384 test['annotations']) |
| 395 if test_timeout_scale and test_timeout_scale != 1: | 385 if test_timeout_scale and test_timeout_scale != 1: |
| 396 valgrind_tools.SetChromeTimeoutScale( | 386 valgrind_tools.SetChromeTimeoutScale( |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()), | 543 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()), |
| 554 device.serial) | 544 device.serial) |
| 555 tombstones_url = logdog_helper.text( | 545 tombstones_url = logdog_helper.text( |
| 556 stream_name, '\n'.join(resolved_tombstones)) | 546 stream_name, '\n'.join(resolved_tombstones)) |
| 557 result.SetLink('tombstones', tombstones_url) | 547 result.SetLink('tombstones', tombstones_url) |
| 558 | 548 |
| 559 if self._env.concurrent_adb: | 549 if self._env.concurrent_adb: |
| 560 post_test_step_thread_group.JoinAll() | 550 post_test_step_thread_group.JoinAll() |
| 561 return results, None | 551 return results, None |
| 562 | 552 |
| 563 def _GetTestsFromRunner(self): | |
| 564 test_apk_path = self._test_instance.test_apk.path | |
| 565 pickle_path = '%s-runner.pickle' % test_apk_path | |
| 566 try: | |
| 567 return instrumentation_test_instance.GetTestsFromPickle( | |
| 568 pickle_path, test_apk_path) | |
| 569 except instrumentation_test_instance.TestListPickleException as e: | |
| 570 logging.info('Could not get tests from pickle: %s', e) | |
| 571 logging.info('Getting tests by having %s list them.', | |
| 572 self._test_instance.junit4_runner_class) | |
| 573 def list_tests(dev): | |
| 574 with device_temp_file.DeviceTempFile( | |
| 575 dev.adb, suffix='.json', | |
| 576 dir=dev.GetExternalStoragePath()) as dev_test_list_json: | |
| 577 junit4_runner_class = self._test_instance.junit4_runner_class | |
| 578 test_package = self._test_instance.test_package | |
| 579 extras = {} | |
| 580 extras['log'] = 'true' | |
| 581 extras['package'] = '.'.join(test_package.split('.')[:2]) | |
| 582 extras[_EXTRA_TEST_LIST] = dev_test_list_json.name | |
| 583 target = '%s/%s' % (test_package, junit4_runner_class) | |
| 584 output_string = ''.join(dev.StartInstrumentation( | |
| 585 target, extras=extras)) | |
| 586 if output_string: | |
| 587 error_message = ( | |
| 588 'List test through {} failed on dev:{} Are you using {}'.format( | |
| 589 junit4_runner_class, output_string, | |
| 590 'org.chromium.base.test.BaseChromiumAndroidJUnitRunner')) | |
| 591 raise device_errors.CommandFailedError(error_message, dev.serial) | |
| 592 with tempfile_ext.NamedTemporaryDirectory() as host_dir: | |
| 593 host_file = os.path.join(host_dir, 'list_tests.json') | |
| 594 dev.PullFile(dev_test_list_json.name, host_file) | |
| 595 with open(host_file, 'r') as host_file: | |
| 596 return json.load(host_file) | |
| 597 | |
| 598 raw_test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None) | |
| 599 | |
| 600 # If all devices failed to list tests, raise an exception. | |
| 601 # Check that tl is not None and is not empty. | |
| 602 if all(not tl for tl in raw_test_lists): | |
| 603 raise device_errors.CommandFailedError( | |
| 604 'Failed to list tests on any device') | |
| 605 | |
| 606 # Get the first viable list of raw tests | |
| 607 raw_tests = [tl for tl in raw_test_lists if tl][0] | |
| 608 | |
| 609 instrumentation_test_instance.SaveTestsToPickle( | |
| 610 pickle_path, test_apk_path, raw_tests) | |
| 611 return raw_tests | |
| 612 | |
| 613 def _SaveScreenshot(self, device, screenshot_host_dir, screenshot_device_file, | 553 def _SaveScreenshot(self, device, screenshot_host_dir, screenshot_device_file, |
| 614 test_name, results): | 554 test_name, results): |
| 615 if screenshot_host_dir: | 555 if screenshot_host_dir: |
| 616 screenshot_host_file = os.path.join( | 556 screenshot_host_file = os.path.join( |
| 617 screenshot_host_dir, | 557 screenshot_host_dir, |
| 618 '%s-%s.png' % ( | 558 '%s-%s.png' % ( |
| 619 test_name, | 559 test_name, |
| 620 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()))) | 560 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()))) |
| 621 if device.FileExists(screenshot_device_file.name): | 561 if device.FileExists(screenshot_device_file.name): |
| 622 try: | 562 try: |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 712 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
| 773 | 713 |
| 774 return timeout | 714 return timeout |
| 775 | 715 |
| 776 def _IsRenderTest(test): | 716 def _IsRenderTest(test): |
| 777 """Determines if a test or list of tests has a RenderTest amongst them.""" | 717 """Determines if a test or list of tests has a RenderTest amongst them.""" |
| 778 if not isinstance(test, list): | 718 if not isinstance(test, list): |
| 779 test = [test] | 719 test = [test] |
| 780 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( | 720 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( |
| 781 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) | 721 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) |
| OLD | NEW |