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

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

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

Powered by Google App Engine
This is Rietveld 408576698