Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: build/android/pylib/instrumentation/instrumentation_test_instance.py

Issue 2963683002: Simplify CommandLine parameterizing J3 Instrumentation Tests (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
6 import copy 5 import copy
7 import json 6 import json
8 import logging 7 import logging
9 import os 8 import os
10 import pickle 9 import pickle
11 import re 10 import re
12 11
13 from devil.android import apk_helper 12 from devil.android import apk_helper
14 from devil.android import md5sum 13 from devil.android import md5sum
15 from pylib import constants 14 from pylib import constants
(...skipping 11 matching lines...) Expand all
27 26
28 # Ref: http://developer.android.com/reference/android/app/Activity.html 27 # Ref: http://developer.android.com/reference/android/app/Activity.html
29 _ACTIVITY_RESULT_CANCELED = 0 28 _ACTIVITY_RESULT_CANCELED = 0
30 _ACTIVITY_RESULT_OK = -1 29 _ACTIVITY_RESULT_OK = -1
31 30
32 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' 31 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter'
33 _DEFAULT_ANNOTATIONS = [ 32 _DEFAULT_ANNOTATIONS = [
34 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', 'IntegrationTest'] 33 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', 'IntegrationTest']
35 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [ 34 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [
36 'DisabledTest', 'FlakyTest'] 35 'DisabledTest', 'FlakyTest']
37 _VALID_ANNOTATIONS = set(['Manual'] + _DEFAULT_ANNOTATIONS + 36 _VALID_ANNOTATIONS = set(['Manual', 'PerfTest'] + _DEFAULT_ANNOTATIONS +
38 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS) 37 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS)
39 _EXTRA_DRIVER_TEST_LIST = ( 38 _EXTRA_DRIVER_TEST_LIST = (
40 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') 39 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList')
41 _EXTRA_DRIVER_TEST_LIST_FILE = ( 40 _EXTRA_DRIVER_TEST_LIST_FILE = (
42 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') 41 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile')
43 _EXTRA_DRIVER_TARGET_PACKAGE = ( 42 _EXTRA_DRIVER_TARGET_PACKAGE = (
44 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') 43 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage')
45 _EXTRA_DRIVER_TARGET_CLASS = ( 44 _EXTRA_DRIVER_TARGET_CLASS = (
46 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') 45 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass')
47 _EXTRA_TIMEOUT_SCALE = ( 46 _EXTRA_TIMEOUT_SCALE = (
48 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') 47 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale')
49 48
50 _PARAMETERIZED_TEST_ANNOTATION = 'ParameterizedTest' 49 _TEST_LIST_JSON_NAME = 'list_all_test.json'
51 _PARAMETERIZED_TEST_SET_ANNOTATION = 'ParameterizedTest$Set' 50
51
52 _SKIP_PARAMETERIZATION_ANNOTATION = 'SkipParameterization'
53 _PARAMETERIZED_TEST_SET_ANNOTATION = 'JUnit3CommandLineParameter'
54
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 = 12
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):
60 super(MissingSizeAnnotationError, self).__init__(class_name + 63 super(MissingSizeAnnotationError, self).__init__(class_name +
61 ': Test method is missing required size annotation. Add one of: ' + 64 ': Test method is missing required size annotation. Add one of: ' +
62 ', '.join('@' + a for a in _VALID_ANNOTATIONS)) 65 ', '.join('@' + a for a in _VALID_ANNOTATIONS))
63 66
64 67
65 class TestListPickleException(test_exception.TestException): 68 class TestListPickleException(test_exception.TestException):
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 and any(_NATIVE_CRASH_RE.search(l) 153 and any(_NATIVE_CRASH_RE.search(l)
151 for l in result_bundle.itervalues())) 154 for l in result_bundle.itervalues()))
152 if crashed: 155 if crashed:
153 current_result.SetType(base_test_result.ResultType.CRASH) 156 current_result.SetType(base_test_result.ResultType.CRASH)
154 157
155 results.append(current_result) 158 results.append(current_result)
156 159
157 return results 160 return results
158 161
159 162
160 def ParseCommandLineFlagParameters(annotations):
161 """Determines whether the test is parameterized to be run with different
162 command-line flags.
163
164 Args:
165 annotations: The annotations of the test.
166
167 Returns:
168 If the test is parameterized, returns a list of named tuples
169 with lists of flags, e.g.:
170
171 [(add=['--flag-to-add']), (remove=['--flag-to-remove']), ()]
172
173 That means, the test must be run three times, the first time with
174 "--flag-to-add" added to command-line, the second time with
175 "--flag-to-remove" to be removed from command-line, and the third time
176 with default command-line args. If the same flag is listed both for adding
177 and for removing, it is left unchanged.
178
179 If the test is not parametrized, returns None.
180
181 """
182 ParamsTuple = collections.namedtuple('ParamsTuple', ['add', 'remove'])
183 parameterized_tests = []
184 if _PARAMETERIZED_TEST_SET_ANNOTATION in annotations:
185 if annotations[_PARAMETERIZED_TEST_SET_ANNOTATION]:
186 parameterized_tests = annotations[
187 _PARAMETERIZED_TEST_SET_ANNOTATION].get('tests', [])
188 elif _PARAMETERIZED_TEST_ANNOTATION in annotations:
189 parameterized_tests = [annotations[_PARAMETERIZED_TEST_ANNOTATION]]
190 else:
191 return None
192
193 result = []
194 for pt in parameterized_tests:
195 if not pt:
196 continue
197 for p in pt['parameters']:
198 if p['tag'] == _COMMAND_LINE_PARAMETER:
199 to_add = []
200 to_remove = []
201 for a in p.get('arguments', []):
202 if a['name'] == 'add':
203 to_add = ['--%s' % f for f in a['stringArray']]
204 elif a['name'] == 'remove':
205 to_remove = ['--%s' % f for f in a['stringArray']]
206 result.append(ParamsTuple(to_add, to_remove))
207 return result if result else None
208
209
210 def FilterTests(tests, test_filter=None, annotations=None, 163 def FilterTests(tests, test_filter=None, annotations=None,
211 excluded_annotations=None): 164 excluded_annotations=None):
212 """Filter a list of tests 165 """Filter a list of tests
213 166
214 Args: 167 Args:
215 tests: a list of tests. e.g. [ 168 tests: a list of tests. e.g. [
216 {'annotations": {}, 'class': 'com.example.TestA', 'methods':[]}, 169 {'annotations": {}, 'class': 'com.example.TestA', 'methods':[]},
217 {'annotations": {}, 'class': 'com.example.TestB', 'methods':[]}] 170 {'annotations": {}, 'class': 'com.example.TestB', 'methods':[]}]
218 test_filter: googletest-style filter string. 171 test_filter: googletest-style filter string.
219 annotations: a dict of wanted annotations for test methods. 172 annotations: a dict of wanted annotations for test methods.
220 exclude_annotations: a dict of annotations to exclude. 173 exclude_annotations: a dict of annotations to exclude.
221 174
222 Return: 175 Return:
223 A list of filtered tests 176 A list of filtered tests
224 """ 177 """
225 def gtest_filter(t): 178 def gtest_filter(t):
226 if not test_filter: 179 if not test_filter:
227 return True 180 return True
228 # Allow fully-qualified name as well as an omitted package. 181 # Allow fully-qualified name as well as an omitted package.
229 unqualified_class_test = { 182 unqualified_class_test = {
230 'class': t['class'].split('.')[-1], 183 'class': t['class'].split('.')[-1],
231 'method': t['method'] 184 'method': t['method']
232 } 185 }
233 names = [ 186 names = [
234 GetTestName(t, sep='.'), 187 GetTestName(t, sep='.'),
235 GetTestName(unqualified_class_test, sep='.'), 188 GetTestName(unqualified_class_test, sep='.'),
236 GetUniqueTestName(t, sep='.') 189 GetUniqueTestName(t, sep='.')
237 ] 190 ]
238 191
192 if t['is_junit4']:
193 names += [
194 GetTestNameWithoutParameterPostfix(t, sep='.'),
195 GetTestNameWithoutParameterPostfix(unqualified_class_test, sep='.')
196 ]
197
239 pattern_groups = test_filter.split('-') 198 pattern_groups = test_filter.split('-')
240 if len(pattern_groups) > 1: 199 if len(pattern_groups) > 1:
241 negative_filter = pattern_groups[1] 200 negative_filter = pattern_groups[1]
242 if unittest_util.FilterTestNames(names, negative_filter): 201 if unittest_util.FilterTestNames(names, negative_filter):
243 return [] 202 return []
244 203
245 positive_filter = pattern_groups[0] 204 positive_filter = pattern_groups[0]
246 return unittest_util.FilterTestNames(names, positive_filter) 205 return unittest_util.FilterTestNames(names, positive_filter)
247 206
248 def annotation_filter(all_annotations): 207 def annotation_filter(all_annotations):
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 raise MissingSizeAnnotationError(GetTestName(t)) 241 raise MissingSizeAnnotationError(GetTestName(t))
283 242
284 if (not annotation_filter(t['annotations']) 243 if (not annotation_filter(t['annotations'])
285 or not excluded_annotation_filter(t['annotations'])): 244 or not excluded_annotation_filter(t['annotations'])):
286 continue 245 continue
287 246
288 filtered_tests.append(t) 247 filtered_tests.append(t)
289 248
290 return filtered_tests 249 return filtered_tests
291 250
292
293 def GetAllTestsFromJar(test_jar): 251 def GetAllTestsFromJar(test_jar):
294 pickle_path = '%s-proguard.pickle' % test_jar 252 pickle_path = '%s-proguard.pickle' % test_jar
295 try: 253 try:
296 tests = _GetTestsFromPickle(pickle_path, test_jar) 254 tests = _GetTestsFromPickle(pickle_path, test_jar)
297 except TestListPickleException as e: 255 except TestListPickleException as e:
298 logging.info('Could not get tests from pickle: %s', e) 256 logging.info('Could not get tests from pickle: %s', e)
299 logging.info('Getting tests from JAR via proguard.') 257 logging.info('Getting tests from JAR via proguard.')
300 tests = _GetTestsFromProguard(test_jar) 258 tests = _GetTestsFromProguard(test_jar)
301 _SaveTestsToPickle(pickle_path, test_jar, tests) 259 _SaveTestsToPickle(pickle_path, test_jar, tests)
302 return tests 260 return tests
303 261
304 262
305 def GetAllTestsFromApk(test_apk): 263 def GetAllTestsFromApk(test_apk):
306 pickle_path = '%s-dexdump.pickle' % test_apk 264 pickle_path = '%s-dexdump.pickle' % test_apk
307 try: 265 try:
308 tests = _GetTestsFromPickle(pickle_path, test_apk) 266 tests = _GetTestsFromPickle(pickle_path, test_apk)
309 except TestListPickleException as e: 267 except TestListPickleException as e:
310 logging.info('Could not get tests from pickle: %s', e) 268 logging.info('Could not get tests from pickle: %s', e)
311 logging.info('Getting tests from dex via dexdump.') 269 logging.info('Getting tests from dex via dexdump.')
312 tests = _GetTestsFromDexdump(test_apk) 270 tests = _GetTestsFromDexdump(test_apk)
313 _SaveTestsToPickle(pickle_path, test_apk, tests) 271 _SaveTestsToPickle(pickle_path, test_apk, tests)
314 return tests 272 return tests
315 273
316
317 def _GetTestsFromPickle(pickle_path, jar_path): 274 def _GetTestsFromPickle(pickle_path, jar_path):
318 if not os.path.exists(pickle_path): 275 if not os.path.exists(pickle_path):
319 raise TestListPickleException('%s does not exist.' % pickle_path) 276 raise TestListPickleException('%s does not exist.' % pickle_path)
320 if os.path.getmtime(pickle_path) <= os.path.getmtime(jar_path): 277 if os.path.getmtime(pickle_path) <= os.path.getmtime(jar_path):
321 raise TestListPickleException( 278 raise TestListPickleException(
322 '%s newer than %s.' % (jar_path, pickle_path)) 279 '%s newer than %s.' % (jar_path, pickle_path))
323 280
324 with open(pickle_path, 'r') as f: 281 with open(pickle_path, 'r') as f:
325 pickle_data = pickle.load(f) 282 pickle_data = pickle.load(f)
326 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] 283 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path]
327 284
328 if pickle_data['VERSION'] != _PICKLE_FORMAT_VERSION: 285 if pickle_data['VERSION'] != _PICKLE_FORMAT_VERSION:
329 raise TestListPickleException('PICKLE_FORMAT_VERSION has changed.') 286 raise TestListPickleException('PICKLE_FORMAT_VERSION has changed.')
330 if pickle_data['JAR_MD5SUM'] != jar_md5: 287 if pickle_data['JAR_MD5SUM'] != jar_md5:
331 raise TestListPickleException('JAR file MD5 sum differs.') 288 raise TestListPickleException('JAR file MD5 sum differs.')
332 return pickle_data['TEST_METHODS'] 289 return pickle_data['TEST_METHODS']
333 290
334 291
292 # TODO(yolandyan): remove this once the test listing from java runner lands
335 def _GetTestsFromProguard(jar_path): 293 def _GetTestsFromProguard(jar_path):
336 p = proguard.Dump(jar_path) 294 p = proguard.Dump(jar_path)
337 class_lookup = dict((c['class'], c) for c in p['classes']) 295 class_lookup = dict((c['class'], c) for c in p['classes'])
338 296
339 def is_test_class(c): 297 def is_test_class(c):
340 return c['class'].endswith('Test') 298 return c['class'].endswith('Test')
341 299
342 def is_test_method(m): 300 def is_test_method(m):
343 return m['method'].startswith('test') 301 return m['method'].startswith('test')
344 302
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 381
424 Args: 382 Args:
425 test: the instrumentation test dict. 383 test: the instrumentation test dict.
426 sep: the character(s) that should join the class name and the method name. 384 sep: the character(s) that should join the class name and the method name.
427 Returns: 385 Returns:
428 The test name as a string. 386 The test name as a string.
429 """ 387 """
430 return '%s%s%s' % (test['class'], sep, test['method']) 388 return '%s%s%s' % (test['class'], sep, test['method'])
431 389
432 390
391 def GetTestNameWithoutParameterPostfix(
392 test, sep='#', parameter_postfix='__'):
393 """Gets the name of the given JUnit4 test withouth parameter postfix.
394
395 For most WebView JUnit4 javatests, each test is parameterizatized with
396 "__sandboxed_mode" to run in both non-sandboxed mode and sandboxed mode.
397
398 This function returns the name of the test without parameterization
399 so test filters can match both parameterized and non-parameterized tests.
400
401 Args:
402 test: the instrumentation test dict.
403 sep: the character(s) that should join the class name and the method name.
404 parameterization_sep: the character(s) that seperate method name and method
405 parameterization postfix.
406 Returns:
407 The test name without parameter postfix as a string.
408 """
409 name = GetTestName(test, sep=sep)
410 return name.split(parameter_postfix)[0]
411
412
433 def GetUniqueTestName(test, sep='#'): 413 def GetUniqueTestName(test, sep='#'):
434 """Gets the unique name of the given test. 414 """Gets the unique name of the given test.
435 415
436 This will include text to disambiguate between tests for which GetTestName 416 This will include text to disambiguate between tests for which GetTestName
437 would return the same name. 417 would return the same name.
438 418
439 Args: 419 Args:
440 test: the instrumentation test dict. 420 test: the instrumentation test dict.
441 sep: the character(s) that should join the class name and the method name. 421 sep: the character(s) that should join the class name and the method name.
442 Returns: 422 Returns:
443 The unique test name as a string. 423 The unique test name as a string.
444 """ 424 """
445 display_name = GetTestName(test, sep=sep) 425 display_name = GetTestName(test, sep=sep)
446 if 'flags' in test: 426 if 'flags' in test and test['flags']:
447 flags = test['flags'] 427 display_name = '%s__%s' % (display_name, test['flags'])
the real yoland 2017/06/28 01:23:09 this change is to be consistent with JUnit4 test p
448 if flags.add:
449 display_name = '%s with {%s}' % (display_name, ' '.join(flags.add))
450 if flags.remove:
451 display_name = '%s without {%s}' % (display_name, ' '.join(flags.remove))
452 return display_name 428 return display_name
453 429
454 430
455 class InstrumentationTestInstance(test_instance.TestInstance): 431 class InstrumentationTestInstance(test_instance.TestInstance):
456 432
457 def __init__(self, args, data_deps_delegate, error_func): 433 def __init__(self, args, data_deps_delegate, error_func):
458 super(InstrumentationTestInstance, self).__init__() 434 super(InstrumentationTestInstance, self).__init__()
459 435
460 self._additional_apks = [] 436 self._additional_apks = []
461 self._apk_under_test = None 437 self._apk_under_test = None
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 error_func('Unable to find test APK: %s' % self._test_apk.path) 540 error_func('Unable to find test APK: %s' % self._test_apk.path)
565 if not self._test_jar: 541 if not self._test_jar:
566 logging.warning('Test jar not specified. Test runner will not have ' 542 logging.warning('Test jar not specified. Test runner will not have '
567 'Java annotation info available. May not handle test ' 543 'Java annotation info available. May not handle test '
568 'timeouts correctly.') 544 'timeouts correctly.')
569 elif not os.path.exists(self._test_jar): 545 elif not os.path.exists(self._test_jar):
570 error_func('Unable to find test JAR: %s' % self._test_jar) 546 error_func('Unable to find test JAR: %s' % self._test_jar)
571 547
572 self._test_package = self._test_apk.GetPackageName() 548 self._test_package = self._test_apk.GetPackageName()
573 all_instrumentations = self._test_apk.GetAllInstrumentations() 549 all_instrumentations = self._test_apk.GetAllInstrumentations()
574 junit3_runners = [ 550 test_runners = [
575 x for x in all_instrumentations if ('true' not in x.get( 551 x for x in all_instrumentations if ('true' not in x.get(
576 'chromium-junit4', ''))] 552 'chromium-junit4', ''))]
577 junit4_runners = [ 553 test_runners_junit4 = [
578 x for x in all_instrumentations if ('true' in x.get( 554 x for x in all_instrumentations if ('true' in x.get(
579 'chromium-junit4', ''))] 555 'chromium-junit4', ''))]
580 556
581 if len(junit3_runners) > 1: 557 if len(test_runners) > 1:
582 logging.warning('This test apk has more than one JUnit3 instrumentation') 558 logging.warning('This test apk has more than one JUnit3 instrumentation')
583 if len(junit4_runners) > 1: 559 if len(test_runners_junit4) > 1:
584 logging.warning('This test apk has more than one JUnit4 instrumentation') 560 logging.warning('This test apk has more than one JUnit4 instrumentation')
585 561
586 self._test_runner = ( 562 self._test_runner = (
587 junit3_runners[0]['android:name'] if junit3_runners else 563 test_runners[0]['android:name'] if test_runners else
588 self.test_apk.GetInstrumentationName()) 564 self.test_apk.GetInstrumentationName())
589 self._test_runner_junit4 = ( 565 self._test_runner_junit4 = (
590 junit4_runners[0]['android:name'] if junit4_runners else None) 566 test_runners_junit4[0]['android:name'] if test_runners_junit4 else None)
591 567
592 self._package_info = None 568 self._package_info = None
593 if self._apk_under_test: 569 if self._apk_under_test:
594 package_under_test = self._apk_under_test.GetPackageName() 570 package_under_test = self._apk_under_test.GetPackageName()
595 for package_info in constants.PACKAGE_INFO.itervalues(): 571 for package_info in constants.PACKAGE_INFO.itervalues():
596 if package_under_test == package_info.package: 572 if package_under_test == package_info.package:
597 self._package_info = package_info 573 self._package_info = package_info
598 break 574 break
599 if not self._package_info: 575 if not self._package_info:
600 logging.warning('Unable to find package info for %s', self._test_package) 576 logging.warning('Unable to find package info for %s', self._test_package)
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 self._data_deps_delegate(self._runtime_deps_path)) 797 self._data_deps_delegate(self._runtime_deps_path))
822 798
823 def GetDataDependencies(self): 799 def GetDataDependencies(self):
824 return self._data_deps 800 return self._data_deps
825 801
826 def GetTests(self): 802 def GetTests(self):
827 if self.test_jar: 803 if self.test_jar:
828 tests = GetAllTestsFromJar(self.test_jar) 804 tests = GetAllTestsFromJar(self.test_jar)
829 else: 805 else:
830 tests = GetAllTestsFromApk(self.test_apk.path) 806 tests = GetAllTestsFromApk(self.test_apk.path)
831 inflated_tests = self._ParametrizeTestsWithFlags(self._InflateTests(tests)) 807 inflated_tests = self._ParameterizeTestsWithFlags(self._InflateTests(tests))
832 if self._test_runner_junit4 is None and any( 808 if self._test_runner_junit4 is None and any(
833 t['is_junit4'] for t in inflated_tests): 809 t['is_junit4'] for t in inflated_tests):
834 raise MissingJUnit4RunnerException() 810 raise MissingJUnit4RunnerException()
835 filtered_tests = FilterTests( 811 filtered_tests = FilterTests(
836 inflated_tests, self._test_filter, self._annotations, 812 inflated_tests, self._test_filter, self._annotations,
837 self._excluded_annotations) 813 self._excluded_annotations)
838 if self._test_filter and not filtered_tests: 814 if self._test_filter and not filtered_tests:
839 for t in inflated_tests: 815 for t in inflated_tests:
840 logging.debug(' %s', GetUniqueTestName(t)) 816 logging.debug(' %s', GetUniqueTestName(t))
841 raise UnmatchedFilterException(self._test_filter) 817 raise UnmatchedFilterException(self._test_filter)
842 return filtered_tests 818 return filtered_tests
843 819
844 # pylint: disable=no-self-use 820 # pylint: disable=no-self-use
845 def _InflateTests(self, tests): 821 def _InflateTests(self, tests):
846 inflated_tests = [] 822 inflated_tests = []
847 for c in tests: 823 for c in tests:
848 for m in c['methods']: 824 for m in c['methods']:
849 a = dict(c['annotations']) 825 a = dict(c['annotations'])
850 a.update(m['annotations']) 826 a.update(m['annotations'])
851 inflated_tests.append({ 827 inflated_tests.append({
852 'class': c['class'], 828 'class': c['class'],
853 'method': m['method'], 829 'method': m['method'],
854 'annotations': a, 830 'annotations': a,
855 'is_junit4': c['superclass'] == 'java.lang.Object' 831 'is_junit4': c['superclass'] == 'java.lang.Object'
856 }) 832 })
857 return inflated_tests 833 return inflated_tests
858 834
859 def _ParametrizeTestsWithFlags(self, tests): 835 def _ParameterizeTestsWithFlags(self, tests):
860 new_tests = [] 836 new_tests = []
861 for t in tests: 837 for t in tests:
862 parameters = ParseCommandLineFlagParameters(t['annotations']) 838 annotations = t['annotations']
839 parameters = (
840 annotations[_PARAMETERIZED_TEST_SET_ANNOTATION]['value']
841 if (annotations.get(_PARAMETERIZED_TEST_SET_ANNOTATION) and
842 annotations.get(_SKIP_PARAMETERIZATION_ANNOTATION) is None)
843 else None)
863 if parameters: 844 if parameters:
864 t['flags'] = parameters[0] 845 t['flags'] = [parameters[0]]
865 for p in parameters[1:]: 846 for p in parameters[1:]:
866 parameterized_t = copy.copy(t) 847 parameterized_t = copy.copy(t)
867 parameterized_t['flags'] = p 848 parameterized_t['flags'] = [p]
868 new_tests.append(parameterized_t) 849 new_tests.append(parameterized_t)
869 return tests + new_tests 850 return tests + new_tests
870 851
871 def GetDriverEnvironmentVars( 852 def GetDriverEnvironmentVars(
872 self, test_list=None, test_list_file_path=None): 853 self, test_list=None, test_list_file_path=None):
873 env = { 854 env = {
874 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package, 855 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package,
875 _EXTRA_DRIVER_TARGET_CLASS: self.test_runner, 856 _EXTRA_DRIVER_TARGET_CLASS: self.test_runner,
876 _EXTRA_TIMEOUT_SCALE: self._timeout_scale, 857 _EXTRA_TIMEOUT_SCALE: self._timeout_scale,
877 } 858 }
(...skipping 13 matching lines...) Expand all
891 872
892 @staticmethod 873 @staticmethod
893 def GenerateTestResults( 874 def GenerateTestResults(
894 result_code, result_bundle, statuses, start_ms, duration_ms): 875 result_code, result_bundle, statuses, start_ms, duration_ms):
895 return GenerateTestResults(result_code, result_bundle, statuses, 876 return GenerateTestResults(result_code, result_bundle, statuses,
896 start_ms, duration_ms) 877 start_ms, duration_ms)
897 878
898 #override 879 #override
899 def TearDown(self): 880 def TearDown(self):
900 pass 881 pass
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698