OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Dispatches the instrumentation tests.""" |
| 6 |
| 7 import logging |
| 8 import os |
| 9 |
| 10 from pylib import android_commands |
| 11 from pylib.base import test_result |
| 12 |
| 13 import apk_info |
| 14 import test_sharder |
| 15 |
| 16 |
| 17 def Dispatch(options, apks): |
| 18 """Dispatches instrumentation tests onto connected device(s). |
| 19 |
| 20 If possible, this method will attempt to shard the tests to |
| 21 all connected devices. Otherwise, dispatch and run tests on one device. |
| 22 |
| 23 Args: |
| 24 options: Command line options. |
| 25 apks: list of APKs to use. |
| 26 |
| 27 Returns: |
| 28 A TestResults object holding the results of the Java tests. |
| 29 |
| 30 Raises: |
| 31 Exception: when there are no attached devices. |
| 32 """ |
| 33 test_apk = apks[0] |
| 34 # The default annotation for tests which do not have any sizes annotation. |
| 35 default_size_annotation = 'SmallTest' |
| 36 |
| 37 def _GetTestsMissingAnnotation(test_apk): |
| 38 test_size_annotations = frozenset(['Smoke', 'SmallTest', 'MediumTest', |
| 39 'LargeTest', 'EnormousTest', 'FlakyTest', |
| 40 'DisabledTest', 'Manual', 'PerfTest']) |
| 41 tests_missing_annotations = [] |
| 42 for test_method in test_apk.GetTestMethods(): |
| 43 annotations = frozenset(test_apk.GetTestAnnotations(test_method)) |
| 44 if (annotations.isdisjoint(test_size_annotations) and |
| 45 not apk_info.ApkInfo.IsPythonDrivenTest(test_method)): |
| 46 tests_missing_annotations.append(test_method) |
| 47 return sorted(tests_missing_annotations) |
| 48 |
| 49 if options.annotation: |
| 50 available_tests = test_apk.GetAnnotatedTests(options.annotation) |
| 51 if options.annotation.count(default_size_annotation) > 0: |
| 52 tests_missing_annotations = _GetTestsMissingAnnotation(test_apk) |
| 53 if tests_missing_annotations: |
| 54 logging.warning('The following tests do not contain any annotation. ' |
| 55 'Assuming "%s":\n%s', |
| 56 default_size_annotation, |
| 57 '\n'.join(tests_missing_annotations)) |
| 58 available_tests += tests_missing_annotations |
| 59 else: |
| 60 available_tests = [m for m in test_apk.GetTestMethods() |
| 61 if not apk_info.ApkInfo.IsPythonDrivenTest(m)] |
| 62 coverage = os.environ.get('EMMA_INSTRUMENT') == 'true' |
| 63 |
| 64 tests = [] |
| 65 if options.test_filter: |
| 66 # |available_tests| are in adb instrument format: package.path.class#test. |
| 67 filter_without_hash = options.test_filter.replace('#', '.') |
| 68 tests = [t for t in available_tests |
| 69 if filter_without_hash in t.replace('#', '.')] |
| 70 else: |
| 71 tests = available_tests |
| 72 |
| 73 if not tests: |
| 74 logging.warning('No Java tests to run with current args.') |
| 75 return test_result.TestResults() |
| 76 |
| 77 tests *= options.number_of_runs |
| 78 |
| 79 attached_devices = android_commands.GetAttachedDevices() |
| 80 test_results = test_result.TestResults() |
| 81 |
| 82 if not attached_devices: |
| 83 raise Exception('You have no devices attached or visible!') |
| 84 if options.device: |
| 85 attached_devices = [options.device] |
| 86 |
| 87 logging.info('Will run: %s', str(tests)) |
| 88 |
| 89 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): |
| 90 logging.warning('Coverage / debugger can not be sharded, ' |
| 91 'using first available device') |
| 92 attached_devices = attached_devices[:1] |
| 93 sharder = test_sharder.TestSharder(attached_devices, options, tests, apks) |
| 94 test_results = sharder.RunShardedTests() |
| 95 return test_results |
OLD | NEW |