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

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

Issue 2935503002: List Java Instru Test Information From JUnit Runner (Closed)
Patch Set: compiling error fix 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 copy 5 import copy
6 import json
6 import logging 7 import logging
7 import os 8 import os
8 import pickle 9 import pickle
9 import re 10 import re
10 11
11 from devil.android import apk_helper 12 from devil.android import apk_helper
13 from devil.android import device_temp_file
12 from devil.android import md5sum 14 from devil.android import md5sum
13 from pylib import constants 15 from pylib import constants
14 from pylib.base import base_test_result 16 from pylib.base import base_test_result
15 from pylib.base import test_exception 17 from pylib.base import test_exception
16 from pylib.base import test_instance 18 from pylib.base import test_instance
17 from pylib.constants import host_paths 19 from pylib.constants import host_paths
18 from pylib.instrumentation import test_result 20 from pylib.instrumentation import test_result
19 from pylib.instrumentation import instrumentation_parser 21 from pylib.instrumentation import instrumentation_parser
20 from pylib.utils import dexdump 22 from pylib.utils import dexdump
21 from pylib.utils import instrumentation_tracing 23 from pylib.utils import instrumentation_tracing
22 from pylib.utils import proguard 24 from pylib.utils import proguard
23 from pylib.utils import shared_preference_utils 25 from pylib.utils import shared_preference_utils
26 from py_utils import tempfile_ext
24 27
25 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): 28 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH):
26 import unittest_util # pylint: disable=import-error 29 import unittest_util # pylint: disable=import-error
27 30
28 # Ref: http://developer.android.com/reference/android/app/Activity.html 31 # Ref: http://developer.android.com/reference/android/app/Activity.html
29 _ACTIVITY_RESULT_CANCELED = 0 32 _ACTIVITY_RESULT_CANCELED = 0
30 _ACTIVITY_RESULT_OK = -1 33 _ACTIVITY_RESULT_OK = -1
31 34
32 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' 35 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter'
33 _DEFAULT_ANNOTATIONS = [ 36 _DEFAULT_ANNOTATIONS = [
34 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', 'IntegrationTest'] 37 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', 'IntegrationTest']
35 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [ 38 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS = [
36 'DisabledTest', 'FlakyTest'] 39 'DisabledTest', 'FlakyTest']
37 _VALID_ANNOTATIONS = set(['Manual'] + _DEFAULT_ANNOTATIONS + 40 _VALID_ANNOTATIONS = set(['Manual'] + _DEFAULT_ANNOTATIONS +
38 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS) 41 _EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS)
39 _EXTRA_DRIVER_TEST_LIST = ( 42 _EXTRA_DRIVER_TEST_LIST = (
40 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList') 43 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList')
41 _EXTRA_DRIVER_TEST_LIST_FILE = ( 44 _EXTRA_DRIVER_TEST_LIST_FILE = (
42 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile') 45 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestListFile')
43 _EXTRA_DRIVER_TARGET_PACKAGE = ( 46 _EXTRA_DRIVER_TARGET_PACKAGE = (
44 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') 47 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage')
45 _EXTRA_DRIVER_TARGET_CLASS = ( 48 _EXTRA_DRIVER_TARGET_CLASS = (
46 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') 49 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass')
47 _EXTRA_TIMEOUT_SCALE = ( 50 _EXTRA_TIMEOUT_SCALE = (
48 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale') 51 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale')
52 _EXTRA_TEST_LIST = (
53 'org.chromium.base.test.BaseChromiumAndroidJUnitRunner.TestList')
49 54
50 _SKIP_PARAMETERIZATION = 'SkipCommandLineParameterization' 55 _SKIP_PARAMETERIZATION = 'SkipCommandLineParameterization'
51 _COMMANDLINE_PARAMETERIZATION = 'CommandLineParameter' 56 _COMMANDLINE_PARAMETERIZATION = 'CommandLineParameter'
52 _NATIVE_CRASH_RE = re.compile('(process|native) crash', re.IGNORECASE) 57 _NATIVE_CRASH_RE = re.compile('(process|native) crash', re.IGNORECASE)
53 _CMDLINE_NAME_SEGMENT_RE = re.compile( 58 _CMDLINE_NAME_SEGMENT_RE = re.compile(
54 r' with(?:out)? \{[^\}]*\}') 59 r' with(?:out)? \{[^\}]*\}')
55 _PICKLE_FORMAT_VERSION = 12 60 _PICKLE_FORMAT_VERSION = 12
56 61
57 62
58 class MissingSizeAnnotationError(test_exception.TestException): 63 class MissingSizeAnnotationError(test_exception.TestException):
59 def __init__(self, class_name): 64 def __init__(self, class_name):
60 super(MissingSizeAnnotationError, self).__init__(class_name + 65 super(MissingSizeAnnotationError, self).__init__(class_name +
61 ': Test method is missing required size annotation. Add one of: ' + 66 ': Test method is missing required size annotation. Add one of: ' +
62 ', '.join('@' + a for a in _VALID_ANNOTATIONS)) 67 ', '.join('@' + a for a in _VALID_ANNOTATIONS))
63 68
64 69
65 class TestListPickleException(test_exception.TestException): 70 class TestListPickleException(test_exception.TestException):
66 pass 71 pass
67 72
68 73
69 # TODO(jbudorick): Make these private class methods of 74 # TODO(jbudorick): Make these private class methods of
70 # InstrumentationTestInstance once the instrumentation test_runner is 75 # InstrumentationTestInstance once the instrumentation junit3_runner_class is
71 # deprecated. 76 # deprecated.
72 def ParseAmInstrumentRawOutput(raw_output): 77 def ParseAmInstrumentRawOutput(raw_output):
73 """Parses the output of an |am instrument -r| call. 78 """Parses the output of an |am instrument -r| call.
74 79
75 Args: 80 Args:
76 raw_output: the output of an |am instrument -r| call as a list of lines 81 raw_output: the output of an |am instrument -r| call as a list of lines
77 Returns: 82 Returns:
78 A 3-tuple containing: 83 A 3-tuple containing:
79 - the instrumentation code as an integer 84 - the instrumentation code as an integer
80 - the instrumentation result as a list of lines 85 - the instrumentation result as a list of lines
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 161
157 return results 162 return results
158 163
159 164
160 def FilterTests(tests, test_filter=None, annotations=None, 165 def FilterTests(tests, test_filter=None, annotations=None,
161 excluded_annotations=None): 166 excluded_annotations=None):
162 """Filter a list of tests 167 """Filter a list of tests
163 168
164 Args: 169 Args:
165 tests: a list of tests. e.g. [ 170 tests: a list of tests. e.g. [
166 {'annotations": {}, 'class': 'com.example.TestA', 'methods':[]}, 171 {'annotations": {}, 'class': 'com.example.TestA', 'method':'test1'},
167 {'annotations": {}, 'class': 'com.example.TestB', 'methods':[]}] 172 {'annotations": {}, 'class': 'com.example.TestB', 'method':'test2'}]
168 test_filter: googletest-style filter string. 173 test_filter: googletest-style filter string.
169 annotations: a dict of wanted annotations for test methods. 174 annotations: a dict of wanted annotations for test methods.
170 exclude_annotations: a dict of annotations to exclude. 175 exclude_annotations: a dict of annotations to exclude.
171 176
172 Return: 177 Return:
173 A list of filtered tests 178 A list of filtered tests
174 """ 179 """
175 def gtest_filter(t): 180 def gtest_filter(t):
176 if not test_filter: 181 if not test_filter:
177 return True 182 return True
178 # Allow fully-qualified name as well as an omitted package. 183 # Allow fully-qualified name as well as an omitted package.
179 unqualified_class_test = { 184 unqualified_class_test = {
180 'class': t['class'].split('.')[-1], 185 'class': t['class'].split('.')[-1],
181 'method': t['method'] 186 'method': t['method']
182 } 187 }
183 names = [ 188 names = [
184 GetTestName(t, sep='.'), 189 GetTestName(t, sep='.'),
185 GetTestName(unqualified_class_test, sep='.'), 190 GetTestName(unqualified_class_test, sep='.'),
186 GetUniqueTestName(t, sep='.') 191 GetUniqueTestName(t, sep='.')
187 ] 192 ]
188 193
194 if t['is_junit4']:
195 names += [
196 GetTestNameWithoutParameterPostfix(t, sep='.'),
197 GetTestNameWithoutParameterPostfix(unqualified_class_test, sep='.')
198 ]
199
189 pattern_groups = test_filter.split('-') 200 pattern_groups = test_filter.split('-')
190 if len(pattern_groups) > 1: 201 if len(pattern_groups) > 1:
191 negative_filter = pattern_groups[1] 202 negative_filter = pattern_groups[1]
192 if unittest_util.FilterTestNames(names, negative_filter): 203 if unittest_util.FilterTestNames(names, negative_filter):
193 return [] 204 return []
194 205
195 positive_filter = pattern_groups[0] 206 positive_filter = pattern_groups[0]
196 return unittest_util.FilterTestNames(names, positive_filter) 207 return unittest_util.FilterTestNames(names, positive_filter)
197 208
198 def annotation_filter(all_annotations): 209 def annotation_filter(all_annotations):
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 244
234 if (not annotation_filter(t['annotations']) 245 if (not annotation_filter(t['annotations'])
235 or not excluded_annotation_filter(t['annotations'])): 246 or not excluded_annotation_filter(t['annotations'])):
236 continue 247 continue
237 248
238 filtered_tests.append(t) 249 filtered_tests.append(t)
239 250
240 return filtered_tests 251 return filtered_tests
241 252
242 253
254 def GetAllTestsFromRunner(device, test_apk, test_package, junit4_runner_class):
255 pickle_path = '%s-runner.pickle' % test_apk.path
256 try:
257 tests = _GetTestsFromPickle(pickle_path, test_apk.path)
258 except TestListPickleException as e:
259 logging.info('Could not get tests from pickle: %s', e)
260 logging.info('Getting tests by print tests in instrumentation runner')
jbudorick 2017/07/19 20:43:34 nit: 'Getting tests by having %s list them.' % jun
the real yoland 2017/07/20 02:04:33 Done.
261 tests = _GetAllTestsFromRunner(device, test_package, junit4_runner_class)
262 _SaveTestsToPickle(pickle_path, test_apk.path, tests)
263 return tests
264
265
266 # TODO(yolandyan): remove this once the tests are converted to junit4
243 def GetAllTestsFromJar(test_jar): 267 def GetAllTestsFromJar(test_jar):
244 pickle_path = '%s-proguard.pickle' % test_jar 268 pickle_path = '%s-proguard.pickle' % test_jar
245 try: 269 try:
246 tests = _GetTestsFromPickle(pickle_path, test_jar) 270 tests = _GetTestsFromPickle(pickle_path, test_jar)
247 except TestListPickleException as e: 271 except TestListPickleException as e:
248 logging.info('Could not get tests from pickle: %s', e) 272 logging.info('Could not get tests from pickle: %s', e)
249 logging.info('Getting tests from JAR via proguard.') 273 logging.info('Getting tests from JAR via proguard.')
250 tests = _GetTestsFromProguard(test_jar) 274 tests = _GetTestsFromProguard(test_jar)
251 _SaveTestsToPickle(pickle_path, test_jar, tests) 275 _SaveTestsToPickle(pickle_path, test_jar, tests)
252 return tests 276 return tests
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 for class_name, class_info in package_info['classes'].iteritems(): 355 for class_name, class_info in package_info['classes'].iteritems():
332 if class_name.endswith('Test'): 356 if class_name.endswith('Test'):
333 tests.append({ 357 tests.append({
334 'class': '%s.%s' % (package_name, class_name), 358 'class': '%s.%s' % (package_name, class_name),
335 'annotations': {}, 359 'annotations': {},
336 'methods': get_test_methods(class_info['methods']), 360 'methods': get_test_methods(class_info['methods']),
337 'superclass': class_info['superclass'], 361 'superclass': class_info['superclass'],
338 }) 362 })
339 return tests 363 return tests
340 364
365 def _GetAllTestsFromRunner(device, test_package, junit4_runner_class):
jbudorick 2017/07/19 20:43:34 Sorry, missed this the first time around. Device-s
the real yoland 2017/07/20 02:04:33 Done
366 with device_temp_file.DeviceTempFile(
367 device.adb, suffix='.json', dir=device.GetExternalStoragePath()) as f:
jbudorick 2017/07/19 20:43:34 nit: this needs a more descriptive name than "f" g
the real yoland 2017/07/20 02:04:33 Done
368 extras = {}
369 extras[_EXTRA_TEST_LIST] = f.name
370 extras['log'] = 'true'
371 extras['package'] = '.'.join(test_package.split('.')[:2])
372 target = '%s/%s' % (test_package, junit4_runner_class)
373 output_string = ''.join(device.StartInstrumentation(
374 target, extras=extras, timeout=30, retries=2))
jbudorick 2017/07/19 20:43:34 I mentioned retries here, but I should say that ne
the real yoland 2017/07/20 02:04:33 Done
375 if output_string:
376 raise Exception('Test listing through %s failed on device:\n%s' % (
377 junit4_runner_class, output_string))
378 with tempfile_ext.NamedTemporaryDirectory() as host_dir:
379 host_file = os.path.join(host_dir, 'list_tests.json')
380 device.PullFile(f.name, host_file)
381 with open(host_file, 'r') as host_file:
382 json_string = host_file.read()
383 return json.loads(json_string)
384
341 385
342 def _SaveTestsToPickle(pickle_path, jar_path, tests): 386 def _SaveTestsToPickle(pickle_path, jar_path, tests):
343 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] 387 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path]
344 pickle_data = { 388 pickle_data = {
345 'VERSION': _PICKLE_FORMAT_VERSION, 389 'VERSION': _PICKLE_FORMAT_VERSION,
346 'JAR_MD5SUM': jar_md5, 390 'JAR_MD5SUM': jar_md5,
347 'TEST_METHODS': tests, 391 'TEST_METHODS': tests,
348 } 392 }
349 with open(pickle_path, 'w') as pickle_file: 393 with open(pickle_path, 'w') as pickle_file:
350 pickle.dump(pickle_data, pickle_file) 394 pickle.dump(pickle_data, pickle_file)
(...skipping 23 matching lines...) Expand all
374 418
375 Args: 419 Args:
376 test: the instrumentation test dict. 420 test: the instrumentation test dict.
377 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.
378 Returns: 422 Returns:
379 The test name as a string. 423 The test name as a string.
380 """ 424 """
381 return '%s%s%s' % (test['class'], sep, test['method']) 425 return '%s%s%s' % (test['class'], sep, test['method'])
382 426
383 427
428 def GetTestNameWithoutParameterPostfix(
429 test, sep='#', parameterization_sep='__'):
430 """Gets the name of the given JUnit4 test without parameter postfix.
431
432 For most WebView JUnit4 javatests, each test is parameterizatized with
433 "__sandboxed_mode" to run in both non-sandboxed mode and sandboxed mode.
434
435 This function returns the name of the test without parameterization
436 so test filters can match both parameterized and non-parameterized tests.
437
438 Args:
439 test: the instrumentation test dict.
440 sep: the character(s) that should join the class name and the method name.
441 parameterization_sep: the character(s) that seperate method name and method
442 parameterization postfix.
443 Returns:
444 The test name without parameter postfix as a string.
445 """
446 name = GetTestName(test, sep=sep)
447 return name.split(parameterization_sep)[0]
448
449
384 def GetUniqueTestName(test, sep='#'): 450 def GetUniqueTestName(test, sep='#'):
385 """Gets the unique name of the given test. 451 """Gets the unique name of the given test.
386 452
387 This will include text to disambiguate between tests for which GetTestName 453 This will include text to disambiguate between tests for which GetTestName
388 would return the same name. 454 would return the same name.
389 455
390 Args: 456 Args:
391 test: the instrumentation test dict. 457 test: the instrumentation test dict.
392 sep: the character(s) that should join the class name and the method name. 458 sep: the character(s) that should join the class name and the method name.
393 Returns: 459 Returns:
(...skipping 12 matching lines...) Expand all
406 472
407 self._additional_apks = [] 473 self._additional_apks = []
408 self._apk_under_test = None 474 self._apk_under_test = None
409 self._apk_under_test_incremental_install_script = None 475 self._apk_under_test_incremental_install_script = None
410 self._package_info = None 476 self._package_info = None
411 self._suite = None 477 self._suite = None
412 self._test_apk = None 478 self._test_apk = None
413 self._test_apk_incremental_install_script = None 479 self._test_apk_incremental_install_script = None
414 self._test_jar = None 480 self._test_jar = None
415 self._test_package = None 481 self._test_package = None
416 self._test_runner = None 482 self._junit3_runner_class = None
417 self._test_runner_junit4 = None 483 self._junit4_runner_class = None
418 self._test_support_apk = None 484 self._test_support_apk = None
419 self._initializeApkAttributes(args, error_func) 485 self._initializeApkAttributes(args, error_func)
420 486
421 self._data_deps = None 487 self._data_deps = None
422 self._data_deps_delegate = None 488 self._data_deps_delegate = None
423 self._runtime_deps_path = None 489 self._runtime_deps_path = None
424 self._initializeDataDependencyAttributes(args, data_deps_delegate) 490 self._initializeDataDependencyAttributes(args, data_deps_delegate)
425 491
426 self._annotations = None 492 self._annotations = None
427 self._excluded_annotations = None 493 self._excluded_annotations = None
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 error_func('Unable to find test APK: %s' % self._test_apk.path) 580 error_func('Unable to find test APK: %s' % self._test_apk.path)
515 if not self._test_jar: 581 if not self._test_jar:
516 logging.warning('Test jar not specified. Test runner will not have ' 582 logging.warning('Test jar not specified. Test runner will not have '
517 'Java annotation info available. May not handle test ' 583 'Java annotation info available. May not handle test '
518 'timeouts correctly.') 584 'timeouts correctly.')
519 elif not os.path.exists(self._test_jar): 585 elif not os.path.exists(self._test_jar):
520 error_func('Unable to find test JAR: %s' % self._test_jar) 586 error_func('Unable to find test JAR: %s' % self._test_jar)
521 587
522 self._test_package = self._test_apk.GetPackageName() 588 self._test_package = self._test_apk.GetPackageName()
523 all_instrumentations = self._test_apk.GetAllInstrumentations() 589 all_instrumentations = self._test_apk.GetAllInstrumentations()
524 test_runners = [ 590 all_junit3_runner_classes = [
525 x for x in all_instrumentations if ('true' not in x.get( 591 x for x in all_instrumentations if ('true' not in x.get(
526 'chromium-junit4', ''))] 592 'chromium-junit4', ''))]
527 test_runners_junit4 = [ 593 all_junit4_test_runner_classes = [
528 x for x in all_instrumentations if ('true' in x.get( 594 x for x in all_instrumentations if ('true' in x.get(
529 'chromium-junit4', ''))] 595 'chromium-junit4', ''))]
530 596
531 if len(test_runners) > 1: 597 if len(all_junit3_runner_classes) > 1:
532 logging.warning('This test apk has more than one JUnit3 instrumentation') 598 logging.warning('This test apk has more than one JUnit3 instrumentation')
533 if len(test_runners_junit4) > 1: 599 if len(all_junit4_test_runner_classes) > 1:
534 logging.warning('This test apk has more than one JUnit4 instrumentation') 600 logging.warning('This test apk has more than one JUnit4 instrumentation')
535 601
536 self._test_runner = ( 602 self._junit3_runner_class = (
537 test_runners[0]['android:name'] if test_runners else 603 all_junit3_runner_classes[0]['android:name']
538 self.test_apk.GetInstrumentationName()) 604 if all_junit3_runner_classes else self.test_apk.GetInstrumentationName())
539 self._test_runner_junit4 = ( 605
540 test_runners_junit4[0]['android:name'] if test_runners_junit4 else None) 606 self._junit4_runner_class = (
607 all_junit4_test_runner_classes[0]['android:name']
608 if all_junit4_test_runner_classes else None)
541 609
542 self._package_info = None 610 self._package_info = None
543 if self._apk_under_test: 611 if self._apk_under_test:
544 package_under_test = self._apk_under_test.GetPackageName() 612 package_under_test = self._apk_under_test.GetPackageName()
545 for package_info in constants.PACKAGE_INFO.itervalues(): 613 for package_info in constants.PACKAGE_INFO.itervalues():
546 if package_under_test == package_info.package: 614 if package_under_test == package_info.package:
547 self._package_info = package_info 615 self._package_info = package_info
548 break 616 break
549 if not self._package_info: 617 if not self._package_info:
550 logging.warning('Unable to find package info for %s', self._test_package) 618 logging.warning('Unable to find package info for %s', self._test_package)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 800
733 @property 801 @property
734 def test_support_apk(self): 802 def test_support_apk(self):
735 return self._test_support_apk 803 return self._test_support_apk
736 804
737 @property 805 @property
738 def test_package(self): 806 def test_package(self):
739 return self._test_package 807 return self._test_package
740 808
741 @property 809 @property
742 def test_runner(self): 810 def junit3_runner_class(self):
743 return self._test_runner 811 return self._junit3_runner_class
744 812
745 @property 813 @property
746 def test_runner_junit4(self): 814 def junit4_runner_class(self):
747 return self._test_runner_junit4 815 return self._junit4_runner_class
748 816
749 @property 817 @property
750 def timeout_scale(self): 818 def timeout_scale(self):
751 return self._timeout_scale 819 return self._timeout_scale
752 820
753 @property 821 @property
754 def total_external_shards(self): 822 def total_external_shards(self):
755 return self._total_external_shards 823 return self._total_external_shards
756 824
757 @property 825 @property
758 def ui_screenshot_dir(self): 826 def ui_screenshot_dir(self):
759 return self._ui_screenshot_dir 827 return self._ui_screenshot_dir
760 828
761 #override 829 #override
762 def TestType(self): 830 def TestType(self):
763 return 'instrumentation' 831 return 'instrumentation'
764 832
765 #override 833 #override
766 def SetUp(self): 834 def SetUp(self):
767 self._data_deps.extend( 835 self._data_deps.extend(
768 self._data_deps_delegate(self._runtime_deps_path)) 836 self._data_deps_delegate(self._runtime_deps_path))
769 837
770 def GetDataDependencies(self): 838 def GetDataDependencies(self):
771 return self._data_deps 839 return self._data_deps
772 840
773 def GetTests(self): 841 def GetTests(self, device=None):
774 if self.test_jar: 842 if self._junit4_runner_class:
843 tests = GetAllTestsFromRunner(
844 device, self.test_apk, self.test_package, self.junit4_runner_class)
845 elif self.test_jar:
775 tests = GetAllTestsFromJar(self.test_jar) 846 tests = GetAllTestsFromJar(self.test_jar)
776 else: 847 else:
777 tests = GetAllTestsFromApk(self.test_apk.path) 848 tests = GetAllTestsFromApk(self.test_apk.path)
778 inflated_tests = self._ParameterizeTestsWithFlags(self._InflateTests(tests)) 849 inflated_tests = self._ParameterizeTestsWithFlags(self._InflateTests(tests))
779 if self._test_runner_junit4 is None and any( 850 if self._junit4_runner_class is None and any(
780 t['is_junit4'] for t in inflated_tests): 851 t['is_junit4'] for t in inflated_tests):
781 raise MissingJUnit4RunnerException() 852 raise MissingJUnit4RunnerException()
782 filtered_tests = FilterTests( 853 filtered_tests = FilterTests(
783 inflated_tests, self._test_filter, self._annotations, 854 inflated_tests, self._test_filter, self._annotations,
784 self._excluded_annotations) 855 self._excluded_annotations)
785 if self._test_filter and not filtered_tests: 856 if self._test_filter and not filtered_tests:
786 for t in inflated_tests: 857 for t in inflated_tests:
787 logging.debug(' %s', GetUniqueTestName(t)) 858 logging.debug(' %s', GetUniqueTestName(t))
788 raise UnmatchedFilterException(self._test_filter) 859 raise UnmatchedFilterException(self._test_filter)
789 return filtered_tests 860 return filtered_tests
(...skipping 26 matching lines...) Expand all
816 for p in parameters[1:]: 887 for p in parameters[1:]:
817 parameterized_t = copy.copy(t) 888 parameterized_t = copy.copy(t)
818 parameterized_t['flags'] = ['--%s' % p] 889 parameterized_t['flags'] = ['--%s' % p]
819 new_tests.append(parameterized_t) 890 new_tests.append(parameterized_t)
820 return tests + new_tests 891 return tests + new_tests
821 892
822 def GetDriverEnvironmentVars( 893 def GetDriverEnvironmentVars(
823 self, test_list=None, test_list_file_path=None): 894 self, test_list=None, test_list_file_path=None):
824 env = { 895 env = {
825 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package, 896 _EXTRA_DRIVER_TARGET_PACKAGE: self.test_package,
826 _EXTRA_DRIVER_TARGET_CLASS: self.test_runner, 897 _EXTRA_DRIVER_TARGET_CLASS: self.junit3_runner_class,
827 _EXTRA_TIMEOUT_SCALE: self._timeout_scale, 898 _EXTRA_TIMEOUT_SCALE: self._timeout_scale,
828 } 899 }
829 900
830 if test_list: 901 if test_list:
831 env[_EXTRA_DRIVER_TEST_LIST] = ','.join(test_list) 902 env[_EXTRA_DRIVER_TEST_LIST] = ','.join(test_list)
832 903
833 if test_list_file_path: 904 if test_list_file_path:
834 env[_EXTRA_DRIVER_TEST_LIST_FILE] = ( 905 env[_EXTRA_DRIVER_TEST_LIST_FILE] = (
835 os.path.basename(test_list_file_path)) 906 os.path.basename(test_list_file_path))
836 907
837 return env 908 return env
838 909
839 @staticmethod 910 @staticmethod
840 def ParseAmInstrumentRawOutput(raw_output): 911 def ParseAmInstrumentRawOutput(raw_output):
841 return ParseAmInstrumentRawOutput(raw_output) 912 return ParseAmInstrumentRawOutput(raw_output)
842 913
843 @staticmethod 914 @staticmethod
844 def GenerateTestResults( 915 def GenerateTestResults(
845 result_code, result_bundle, statuses, start_ms, duration_ms): 916 result_code, result_bundle, statuses, start_ms, duration_ms):
846 return GenerateTestResults(result_code, result_bundle, statuses, 917 return GenerateTestResults(result_code, result_bundle, statuses,
847 start_ms, duration_ms) 918 start_ms, duration_ms)
848 919
849 #override 920 #override
850 def TearDown(self): 921 def TearDown(self):
851 pass 922 pass
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698