| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 """Dispatches the instrumentation tests.""" | 5 """Dispatches the instrumentation tests.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 | 9 |
| 10 from pylib import android_commands | 10 from pylib import android_commands |
| 11 from pylib.base import shard | 11 from pylib.base import shard |
| 12 from pylib.base import test_result | 12 from pylib.base import test_result |
| 13 from pylib.uiautomator import test_package as uiautomator_package |
| 13 | 14 |
| 14 import apk_info | 15 import test_package |
| 15 import test_runner | 16 import test_runner |
| 16 | 17 |
| 17 | 18 |
| 18 def Dispatch(options, apks): | 19 def Dispatch(options): |
| 19 """Dispatches instrumentation tests onto connected device(s). | 20 """Dispatches instrumentation tests onto connected device(s). |
| 20 | 21 |
| 21 If possible, this method will attempt to shard the tests to | 22 If possible, this method will attempt to shard the tests to |
| 22 all connected devices. Otherwise, dispatch and run tests on one device. | 23 all connected devices. Otherwise, dispatch and run tests on one device. |
| 23 | 24 |
| 24 Args: | 25 Args: |
| 25 options: Command line options. | 26 options: Command line options. |
| 26 apks: list of APKs to use. | |
| 27 | 27 |
| 28 Returns: | 28 Returns: |
| 29 A TestResults object holding the results of the Java tests. | 29 A TestResults object holding the results of the Java tests. |
| 30 | 30 |
| 31 Raises: | 31 Raises: |
| 32 Exception: when there are no attached devices. | 32 Exception: when there are no attached devices. |
| 33 """ | 33 """ |
| 34 test_apk = apks[0] | 34 is_uiautomator_test = False |
| 35 if hasattr(options, 'uiautomator_jar'): |
| 36 test_pkg = uiautomator_package.TestPackage( |
| 37 options.uiautomator_jar, options.uiautomator_info_jar) |
| 38 is_uiautomator_test = True |
| 39 else: |
| 40 test_pkg = test_package.TestPackage(options.test_apk_path, |
| 41 options.test_apk_jar_path) |
| 35 # The default annotation for tests which do not have any sizes annotation. | 42 # The default annotation for tests which do not have any sizes annotation. |
| 36 default_size_annotation = 'SmallTest' | 43 default_size_annotation = 'SmallTest' |
| 37 | 44 |
| 38 def _GetTestsMissingAnnotation(test_apk): | 45 def _GetTestsMissingAnnotation(test_pkg): |
| 39 test_size_annotations = frozenset(['Smoke', 'SmallTest', 'MediumTest', | 46 test_size_annotations = frozenset(['Smoke', 'SmallTest', 'MediumTest', |
| 40 'LargeTest', 'EnormousTest', 'FlakyTest', | 47 'LargeTest', 'EnormousTest', 'FlakyTest', |
| 41 'DisabledTest', 'Manual', 'PerfTest']) | 48 'DisabledTest', 'Manual', 'PerfTest']) |
| 42 tests_missing_annotations = [] | 49 tests_missing_annotations = [] |
| 43 for test_method in test_apk.GetTestMethods(): | 50 for test_method in test_pkg.GetTestMethods(): |
| 44 annotations = frozenset(test_apk.GetTestAnnotations(test_method)) | 51 annotations = frozenset(test_pkg.GetTestAnnotations(test_method)) |
| 45 if (annotations.isdisjoint(test_size_annotations) and | 52 if (annotations.isdisjoint(test_size_annotations) and |
| 46 not apk_info.ApkInfo.IsPythonDrivenTest(test_method)): | 53 not test_pkg.IsPythonDrivenTest(test_method)): |
| 47 tests_missing_annotations.append(test_method) | 54 tests_missing_annotations.append(test_method) |
| 48 return sorted(tests_missing_annotations) | 55 return sorted(tests_missing_annotations) |
| 49 | 56 |
| 50 if options.annotation: | 57 if options.annotation: |
| 51 available_tests = test_apk.GetAnnotatedTests(options.annotation) | 58 available_tests = test_pkg.GetAnnotatedTests(options.annotation) |
| 52 if options.annotation.count(default_size_annotation) > 0: | 59 if options.annotation.count(default_size_annotation) > 0: |
| 53 tests_missing_annotations = _GetTestsMissingAnnotation(test_apk) | 60 tests_missing_annotations = _GetTestsMissingAnnotation(test_pkg) |
| 54 if tests_missing_annotations: | 61 if tests_missing_annotations: |
| 55 logging.warning('The following tests do not contain any annotation. ' | 62 logging.warning('The following tests do not contain any annotation. ' |
| 56 'Assuming "%s":\n%s', | 63 'Assuming "%s":\n%s', |
| 57 default_size_annotation, | 64 default_size_annotation, |
| 58 '\n'.join(tests_missing_annotations)) | 65 '\n'.join(tests_missing_annotations)) |
| 59 available_tests += tests_missing_annotations | 66 available_tests += tests_missing_annotations |
| 60 else: | 67 else: |
| 61 available_tests = [m for m in test_apk.GetTestMethods() | 68 available_tests = [m for m in test_pkg.GetTestMethods() |
| 62 if not apk_info.ApkInfo.IsPythonDrivenTest(m)] | 69 if not test_pkg.IsPythonDrivenTest(m)] |
| 63 coverage = os.environ.get('EMMA_INSTRUMENT') == 'true' | 70 coverage = os.environ.get('EMMA_INSTRUMENT') == 'true' |
| 64 | 71 |
| 65 tests = [] | 72 tests = [] |
| 66 if options.test_filter: | 73 if options.test_filter: |
| 67 # |available_tests| are in adb instrument format: package.path.class#test. | 74 # |available_tests| are in adb instrument format: package.path.class#test. |
| 68 filter_without_hash = options.test_filter.replace('#', '.') | 75 filter_without_hash = options.test_filter.replace('#', '.') |
| 69 tests = [t for t in available_tests | 76 tests = [t for t in available_tests |
| 70 if filter_without_hash in t.replace('#', '.')] | 77 if filter_without_hash in t.replace('#', '.')] |
| 71 else: | 78 else: |
| 72 tests = available_tests | 79 tests = available_tests |
| (...skipping 12 matching lines...) Expand all Loading... |
| 85 attached_devices = [options.device] | 92 attached_devices = [options.device] |
| 86 | 93 |
| 87 logging.info('Will run: %s', str(tests)) | 94 logging.info('Will run: %s', str(tests)) |
| 88 | 95 |
| 89 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): | 96 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): |
| 90 logging.warning('Coverage / debugger can not be sharded, ' | 97 logging.warning('Coverage / debugger can not be sharded, ' |
| 91 'using first available device') | 98 'using first available device') |
| 92 attached_devices = attached_devices[:1] | 99 attached_devices = attached_devices[:1] |
| 93 | 100 |
| 94 def TestRunnerFactory(device, shard_index): | 101 def TestRunnerFactory(device, shard_index): |
| 95 return test_runner.TestRunner(options, device, shard_index, False, apks, []) | 102 return test_runner.TestRunner( |
| 103 options, device, shard_index, False, test_pkg, [], is_uiautomator_test) |
| 96 | 104 |
| 97 return shard.ShardAndRunTests(TestRunnerFactory, attached_devices, tests, | 105 return shard.ShardAndRunTests(TestRunnerFactory, attached_devices, tests, |
| 98 options.build_type) | 106 options.build_type) |
| OLD | NEW |