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