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 collections | 5 import collections |
| 6 import copy | 6 import copy |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import pickle | 10 import pickle |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') | 40 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') |
| 41 _EXTRA_DRIVER_TEST_LIST_FILE = ( | 41 _EXTRA_DRIVER_TEST_LIST_FILE = ( |
| 42 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') | 42 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') |
| 43 _EXTRA_DRIVER_TARGET_PACKAGE = ( | 43 _EXTRA_DRIVER_TARGET_PACKAGE = ( |
| 44 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') | 44 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') |
| 45 _EXTRA_DRIVER_TARGET_CLASS = ( | 45 _EXTRA_DRIVER_TARGET_CLASS = ( |
| 46 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') | 46 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') |
| 47 _EXTRA_TIMEOUT_SCALE = ( | 47 _EXTRA_TIMEOUT_SCALE = ( |
| 48 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') | 48 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') |
| 49 | 49 |
| 50 _WEBVIEW_JUNIT4_PARAMETERIZATION = 'WebViewParameterization' | |
| 51 _WEBVIEW_JUNIT4_SKIP_PARAMETERIZATION = 'SkipWebViewParameterization' | |
| 52 | |
| 50 _PARAMETERIZED_TEST_ANNOTATION = 'ParameterizedTest' | 53 _PARAMETERIZED_TEST_ANNOTATION = 'ParameterizedTest' |
| 51 _PARAMETERIZED_TEST_SET_ANNOTATION = 'ParameterizedTest$Set' | 54 _PARAMETERIZED_TEST_SET_ANNOTATION = 'ParameterizedTest$Set' |
| 52 _NATIVE_CRASH_RE = re.compile('(process|native) crash', re.IGNORECASE) | 55 _NATIVE_CRASH_RE = re.compile('(process|native) crash', re.IGNORECASE) |
| 53 _CMDLINE_NAME_SEGMENT_RE = re.compile( | 56 _CMDLINE_NAME_SEGMENT_RE = re.compile( |
| 54 r' with(?:out)? \{[^\}]*\}') | 57 r' with(?:out)? \{[^\}]*\}') |
| 55 _PICKLE_FORMAT_VERSION = 11 | 58 _PICKLE_FORMAT_VERSION = 11 |
| 56 | 59 |
| 57 | 60 |
| 58 class MissingSizeAnnotationError(test_exception.TestException): | 61 class MissingSizeAnnotationError(test_exception.TestException): |
| 59 def __init__(self, class_name): | 62 def __init__(self, class_name): |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 unqualified_class_test = { | 232 unqualified_class_test = { |
| 230 'class': t['class'].split('.')[-1], | 233 'class': t['class'].split('.')[-1], |
| 231 'method': t['method'] | 234 'method': t['method'] |
| 232 } | 235 } |
| 233 names = [ | 236 names = [ |
| 234 GetTestName(t, sep='.'), | 237 GetTestName(t, sep='.'), |
| 235 GetTestName(unqualified_class_test, sep='.'), | 238 GetTestName(unqualified_class_test, sep='.'), |
| 236 GetUniqueTestName(t, sep='.') | 239 GetUniqueTestName(t, sep='.') |
| 237 ] | 240 ] |
| 238 | 241 |
| 242 if t['is_junit4'] and t.get('webview_parameterization'): | |
|
jbudorick
2017/06/12 13:21:43
I'm not sure why this is necessary beyond what Get
| |
| 243 names += [ | |
| 244 GetTestNameWithoutParameterPostfix(t, sep='.'), | |
| 245 GetTestNameWithoutParameterPostfix(unqualified_class_test, sep='.') | |
| 246 ] | |
| 247 | |
| 239 pattern_groups = test_filter.split('-') | 248 pattern_groups = test_filter.split('-') |
| 240 if len(pattern_groups) > 1: | 249 if len(pattern_groups) > 1: |
| 241 negative_filter = pattern_groups[1] | 250 negative_filter = pattern_groups[1] |
| 242 if unittest_util.FilterTestNames(names, negative_filter): | 251 if unittest_util.FilterTestNames(names, negative_filter): |
| 243 return [] | 252 return [] |
| 244 | 253 |
| 245 positive_filter = pattern_groups[0] | 254 positive_filter = pattern_groups[0] |
| 246 return unittest_util.FilterTestNames(names, positive_filter) | 255 return unittest_util.FilterTestNames(names, positive_filter) |
| 247 | 256 |
| 248 def annotation_filter(all_annotations): | 257 def annotation_filter(all_annotations): |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 | 432 |
| 424 Args: | 433 Args: |
| 425 test: the instrumentation test dict. | 434 test: the instrumentation test dict. |
| 426 sep: the character(s) that should join the class name and the method name. | 435 sep: the character(s) that should join the class name and the method name. |
| 427 Returns: | 436 Returns: |
| 428 The test name as a string. | 437 The test name as a string. |
| 429 """ | 438 """ |
| 430 return '%s%s%s' % (test['class'], sep, test['method']) | 439 return '%s%s%s' % (test['class'], sep, test['method']) |
| 431 | 440 |
| 432 | 441 |
| 442 def GetTestNameWithoutParameterPostfix( | |
| 443 test, sep='#', parameter_postfix='__'): | |
| 444 """Gets the name of the given JUnit4 test withouth parameter postfix. | |
| 445 | |
| 446 For most WebView JUnit4 javatests, each test is parameterizatized with | |
| 447 "__sandboxed_mode" to run in both non-sandboxed mode and sandboxed mode. | |
| 448 | |
| 449 This function returns the name of the test without parameterization | |
| 450 so test filters can match both parameterized and non-parameterized tests. | |
| 451 | |
| 452 Args: | |
| 453 test: the instrumentation test dict. | |
| 454 sep: the character(s) that should join the class name and the method name. | |
| 455 parameterization_sep: the character(s) that seperate method name and method | |
| 456 parameterization postfix. | |
| 457 Returns: | |
| 458 The test name without parameter postfix as a string. | |
| 459 """ | |
| 460 name = GetTestName(test, sep=sep) | |
| 461 return name.split(parameter_postfix)[0] | |
| 462 | |
| 463 | |
| 433 def GetUniqueTestName(test, sep='#'): | 464 def GetUniqueTestName(test, sep='#'): |
| 434 """Gets the unique name of the given test. | 465 """Gets the unique name of the given test. |
| 435 | 466 |
| 436 This will include text to disambiguate between tests for which GetTestName | 467 This will include text to disambiguate between tests for which GetTestName |
| 437 would return the same name. | 468 would return the same name. |
| 438 | 469 |
| 439 Args: | 470 Args: |
| 440 test: the instrumentation test dict. | 471 test: the instrumentation test dict. |
| 441 sep: the character(s) that should join the class name and the method name. | 472 sep: the character(s) that should join the class name and the method name. |
| 442 Returns: | 473 Returns: |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 852 'class': c['class'], | 883 'class': c['class'], |
| 853 'method': m['method'], | 884 'method': m['method'], |
| 854 'annotations': a, | 885 'annotations': a, |
| 855 'is_junit4': c['superclass'] == 'java.lang.Object' | 886 'is_junit4': c['superclass'] == 'java.lang.Object' |
| 856 }) | 887 }) |
| 857 return inflated_tests | 888 return inflated_tests |
| 858 | 889 |
| 859 def _ParametrizeTestsWithFlags(self, tests): | 890 def _ParametrizeTestsWithFlags(self, tests): |
| 860 new_tests = [] | 891 new_tests = [] |
| 861 for t in tests: | 892 for t in tests: |
| 862 parameters = ParseCommandLineFlagParameters(t['annotations']) | 893 if (_WEBVIEW_JUNIT4_PARAMETERIZATION in t['annotations'] |
|
jbudorick
2017/06/12 13:21:43
This is too webview-specific. Let's talk about gen
| |
| 863 if parameters: | 894 and _WEBVIEW_JUNIT4_SKIP_PARAMETERIZATION not in t['annotations'] |
| 864 t['flags'] = parameters[0] | 895 and t['is_junit4']): |
| 865 for p in parameters[1:]: | 896 parameterized_t = copy.copy(t) |
| 866 parameterized_t = copy.copy(t) | 897 parameterized_t['webview_parameterization'] = True |
| 867 parameterized_t['flags'] = p | 898 parameterized_t['method'] += '__sandboxed_mode' |
| 868 new_tests.append(parameterized_t) | 899 new_tests.append(parameterized_t) |
| 900 else: | |
| 901 parameters = ParseCommandLineFlagParameters(t['annotations']) | |
| 902 if parameters: | |
| 903 t['flags'] = parameters[0] | |
| 904 for p in parameters[1:]: | |
| 905 parameterized_t = copy.copy(t) | |
| 906 parameterized_t['flags'] = p | |
| 907 new_tests.append(parameterized_t) | |
| 869 return tests + new_tests | 908 return tests + new_tests |
| 870 | 909 |
| 871 def GetDriverEnvironmentVars( | 910 def GetDriverEnvironmentVars( |
| 872 self, test_list=None, test_list_file_path=None): | 911 self, test_list=None, test_list_file_path=None): |
| 873 env = { | 912 env = { |
| 874 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package, | 913 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package, |
| 875 _EXTRA_DRIVER_TARGET_CLASS: self.test_runner, | 914 _EXTRA_DRIVER_TARGET_CLASS: self.test_runner, |
| 876 _EXTRA_TIMEOUT_SCALE: self._timeout_scale, | 915 _EXTRA_TIMEOUT_SCALE: self._timeout_scale, |
| 877 } | 916 } |
| 878 | 917 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 891 | 930 |
| 892 @staticmethod | 931 @staticmethod |
| 893 def GenerateTestResults( | 932 def GenerateTestResults( |
| 894 result_code, result_bundle, statuses, start_ms, duration_ms): | 933 result_code, result_bundle, statuses, start_ms, duration_ms): |
| 895 return GenerateTestResults(result_code, result_bundle, statuses, | 934 return GenerateTestResults(result_code, result_bundle, statuses, |
| 896 start_ms, duration_ms) | 935 start_ms, duration_ms) |
| 897 | 936 |
| 898 #override | 937 #override |
| 899 def TearDown(self): | 938 def TearDown(self): |
| 900 pass | 939 pass |
| OLD | NEW |