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 collections | 5 import collections |
6 import copy | 6 import copy |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import pickle | 9 import pickle |
10 import re | 10 import re |
11 | 11 |
12 from devil.android import apk_helper | 12 from devil.android import apk_helper |
13 from devil.android import md5sum | 13 from devil.android import md5sum |
14 from pylib import constants | 14 from pylib import constants |
15 from pylib.base import base_test_result | 15 from pylib.base import base_test_result |
| 16 from pylib.base import test_exception |
16 from pylib.base import test_instance | 17 from pylib.base import test_instance |
17 from pylib.constants import host_paths | 18 from pylib.constants import host_paths |
18 from pylib.instrumentation import test_result | 19 from pylib.instrumentation import test_result |
19 from pylib.instrumentation import instrumentation_parser | 20 from pylib.instrumentation import instrumentation_parser |
20 from pylib.utils import isolator | 21 from pylib.utils import isolator |
21 from pylib.utils import proguard | 22 from pylib.utils import proguard |
22 | 23 |
23 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): | 24 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
24 import unittest_util # pylint: disable=import-error | 25 import unittest_util # pylint: disable=import-error |
25 | 26 |
(...skipping 19 matching lines...) Expand all Loading... |
45 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') | 46 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') |
46 _EXTRA_TIMEOUT_SCALE = ( | 47 _EXTRA_TIMEOUT_SCALE = ( |
47 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') | 48 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') |
48 | 49 |
49 _PARAMETERIZED_TEST_ANNOTATION = 'ParameterizedTest' | 50 _PARAMETERIZED_TEST_ANNOTATION = 'ParameterizedTest' |
50 _PARAMETERIZED_TEST_SET_ANNOTATION = 'ParameterizedTest$Set' | 51 _PARAMETERIZED_TEST_SET_ANNOTATION = 'ParameterizedTest$Set' |
51 _NATIVE_CRASH_RE = re.compile('(process|native) crash', re.IGNORECASE) | 52 _NATIVE_CRASH_RE = re.compile('(process|native) crash', re.IGNORECASE) |
52 _PICKLE_FORMAT_VERSION = 10 | 53 _PICKLE_FORMAT_VERSION = 10 |
53 | 54 |
54 | 55 |
55 class MissingSizeAnnotationError(Exception): | 56 class MissingSizeAnnotationError(test_exception.TestException): |
56 def __init__(self, class_name): | 57 def __init__(self, class_name): |
57 super(MissingSizeAnnotationError, self).__init__(class_name + | 58 super(MissingSizeAnnotationError, self).__init__(class_name + |
58 ': Test method is missing required size annotation. Add one of: ' + | 59 ': Test method is missing required size annotation. Add one of: ' + |
59 ', '.join('@' + a for a in _VALID_ANNOTATIONS)) | 60 ', '.join('@' + a for a in _VALID_ANNOTATIONS)) |
60 | 61 |
61 | 62 |
62 class ProguardPickleException(Exception): | 63 class ProguardPickleException(test_exception.TestException): |
63 pass | 64 pass |
64 | 65 |
65 | 66 |
66 # TODO(jbudorick): Make these private class methods of | 67 # TODO(jbudorick): Make these private class methods of |
67 # InstrumentationTestInstance once the instrumentation test_runner is | 68 # InstrumentationTestInstance once the instrumentation test_runner is |
68 # deprecated. | 69 # deprecated. |
69 def ParseAmInstrumentRawOutput(raw_output): | 70 def ParseAmInstrumentRawOutput(raw_output): |
70 """Parses the output of an |am instrument -r| call. | 71 """Parses the output of an |am instrument -r| call. |
71 | 72 |
72 Args: | 73 Args: |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] | 346 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] |
346 pickle_data = { | 347 pickle_data = { |
347 'VERSION': _PICKLE_FORMAT_VERSION, | 348 'VERSION': _PICKLE_FORMAT_VERSION, |
348 'JAR_MD5SUM': jar_md5, | 349 'JAR_MD5SUM': jar_md5, |
349 'TEST_METHODS': tests, | 350 'TEST_METHODS': tests, |
350 } | 351 } |
351 with open(pickle_path, 'w') as pickle_file: | 352 with open(pickle_path, 'w') as pickle_file: |
352 pickle.dump(pickle_data, pickle_file) | 353 pickle.dump(pickle_data, pickle_file) |
353 | 354 |
354 | 355 |
| 356 class UnmatchedFilterException(test_exception.TestException): |
| 357 """Raised when a user specifies a filter that doesn't match any tests.""" |
| 358 |
| 359 def __init__(self, test_filter): |
| 360 super(UnmatchedFilterException, self).__init__( |
| 361 'Test filter "%s" matched no tests.' % test_filter) |
| 362 |
| 363 |
355 class InstrumentationTestInstance(test_instance.TestInstance): | 364 class InstrumentationTestInstance(test_instance.TestInstance): |
356 | 365 |
357 def __init__(self, args, isolate_delegate, error_func): | 366 def __init__(self, args, isolate_delegate, error_func): |
358 super(InstrumentationTestInstance, self).__init__() | 367 super(InstrumentationTestInstance, self).__init__() |
359 | 368 |
360 self._additional_apks = [] | 369 self._additional_apks = [] |
361 self._apk_under_test = None | 370 self._apk_under_test = None |
362 self._apk_under_test_incremental_install_script = None | 371 self._apk_under_test_incremental_install_script = None |
363 self._package_info = None | 372 self._package_info = None |
364 self._suite = None | 373 self._suite = None |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 self._isolate_delegate.MoveOutputDeps() | 656 self._isolate_delegate.MoveOutputDeps() |
648 self._data_deps.extend([(self._isolate_delegate.isolate_deps_dir, None)]) | 657 self._data_deps.extend([(self._isolate_delegate.isolate_deps_dir, None)]) |
649 | 658 |
650 def GetDataDependencies(self): | 659 def GetDataDependencies(self): |
651 return self._data_deps | 660 return self._data_deps |
652 | 661 |
653 def GetTests(self): | 662 def GetTests(self): |
654 tests = GetAllTests(self.test_jar) | 663 tests = GetAllTests(self.test_jar) |
655 filtered_tests = FilterTests( | 664 filtered_tests = FilterTests( |
656 tests, self._test_filter, self._annotations, self._excluded_annotations) | 665 tests, self._test_filter, self._annotations, self._excluded_annotations) |
| 666 if self._test_filter and not filtered_tests: |
| 667 raise UnmatchedFilterException(self._test_filter) |
657 return self._ParametrizeTestsWithFlags(self._InflateTests(filtered_tests)) | 668 return self._ParametrizeTestsWithFlags(self._InflateTests(filtered_tests)) |
658 | 669 |
659 # pylint: disable=no-self-use | 670 # pylint: disable=no-self-use |
660 def _InflateTests(self, tests): | 671 def _InflateTests(self, tests): |
661 inflated_tests = [] | 672 inflated_tests = [] |
662 for c in tests: | 673 for c in tests: |
663 for m in c['methods']: | 674 for m in c['methods']: |
664 a = dict(c['annotations']) | 675 a = dict(c['annotations']) |
665 a.update(m['annotations']) | 676 a.update(m['annotations']) |
666 inflated_tests.append({ | 677 inflated_tests.append({ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 @staticmethod | 717 @staticmethod |
707 def GenerateTestResults( | 718 def GenerateTestResults( |
708 result_code, result_bundle, statuses, start_ms, duration_ms): | 719 result_code, result_bundle, statuses, start_ms, duration_ms): |
709 return GenerateTestResults(result_code, result_bundle, statuses, | 720 return GenerateTestResults(result_code, result_bundle, statuses, |
710 start_ms, duration_ms) | 721 start_ms, duration_ms) |
711 | 722 |
712 #override | 723 #override |
713 def TearDown(self): | 724 def TearDown(self): |
714 if self._isolate_delegate: | 725 if self._isolate_delegate: |
715 self._isolate_delegate.Clear() | 726 self._isolate_delegate.Clear() |
OLD | NEW |