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 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 |
| 12 from devil.android import md5sum | 13 from devil.android import md5sum |
| 13 from pylib import constants | 14 from pylib import constants |
| 14 from pylib.base import base_test_result | 15 from pylib.base import base_test_result |
| 15 from pylib.base import test_exception | 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 dexdump | 21 from pylib.utils import dexdump |
| 21 from pylib.utils import proguard | 22 from pylib.utils import proguard |
| 22 from pylib.utils import shared_preference_utils | 23 from pylib.utils import shared_preference_utils |
| 24 from py_utils import tempfile_ext | |
| 23 | 25 |
| 24 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): | 26 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
| 25 import unittest_util # pylint: disable=import-error | 27 import unittest_util # pylint: disable=import-error |
| 26 | 28 |
| 27 # Ref: http://developer.android.com/reference/android/app/Activity.html | 29 # Ref: http://developer.android.com/reference/android/app/Activity.html |
| 28 _ACTIVITY_RESULT_CANCELED = 0 | 30 _ACTIVITY_RESULT_CANCELED = 0 |
| 29 _ACTIVITY_RESULT_OK = -1 | 31 _ACTIVITY_RESULT_OK = -1 |
| 30 | 32 |
| 31 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' | 33 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' |
| 32 _DEFAULT_ANNOTATIONS = [ | 34 _DEFAULT_ANNOTATIONS = [ |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 raise MissingSizeAnnotationError(GetTestName(t)) | 239 raise MissingSizeAnnotationError(GetTestName(t)) |
| 238 | 240 |
| 239 if (not annotation_filter(t['annotations']) | 241 if (not annotation_filter(t['annotations']) |
| 240 or not excluded_annotation_filter(t['annotations'])): | 242 or not excluded_annotation_filter(t['annotations'])): |
| 241 continue | 243 continue |
| 242 | 244 |
| 243 filtered_tests.append(t) | 245 filtered_tests.append(t) |
| 244 | 246 |
| 245 return filtered_tests | 247 return filtered_tests |
| 246 | 248 |
| 249 | |
| 250 def GetAllTestsFromRunner(device, test_apk_path, test_package, filename, | |
| 251 test_runner=None, test_runner_junit4=None): | |
| 252 pickle_path = '%s-runner.pickle' % test_apk_path | |
| 253 try: | |
| 254 tests = _GetTestsFromPickle(pickle_path, test_apk_path) | |
| 255 except TestListPickleException as e: | |
| 256 logging.info('Could not get tests from pickle: %s', e) | |
| 257 logging.info('Getting tests by print tests in instrumentation runner') | |
| 258 tests = _GetAllTestsFromRunner(device, test_package, filename, | |
| 259 test_runner, test_runner_junit4) | |
| 260 _SaveTestsToPickle(pickle_path, test_apk_path, tests) | |
| 261 return tests | |
| 262 | |
| 263 | |
| 264 # TODO(yolandyan): remove this once the tests are converted to junit4 | |
| 247 def GetAllTestsFromJar(test_jar): | 265 def GetAllTestsFromJar(test_jar): |
| 248 pickle_path = '%s-proguard.pickle' % test_jar | 266 pickle_path = '%s-proguard.pickle' % test_jar |
| 249 try: | 267 try: |
| 250 tests = _GetTestsFromPickle(pickle_path, test_jar) | 268 tests = _GetTestsFromPickle(pickle_path, test_jar) |
| 251 except TestListPickleException as e: | 269 except TestListPickleException as e: |
| 252 logging.info('Could not get tests from pickle: %s', e) | 270 logging.info('Could not get tests from pickle: %s', e) |
| 253 logging.info('Getting tests from JAR via proguard.') | 271 logging.info('Getting tests from JAR via proguard.') |
| 254 tests = _GetTestsFromProguard(test_jar) | 272 tests = _GetTestsFromProguard(test_jar) |
| 255 _SaveTestsToPickle(pickle_path, test_jar, tests) | 273 _SaveTestsToPickle(pickle_path, test_jar, tests) |
| 256 return tests | 274 return tests |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 for class_name, class_info in package_info['classes'].iteritems(): | 352 for class_name, class_info in package_info['classes'].iteritems(): |
| 335 if class_name.endswith('Test'): | 353 if class_name.endswith('Test'): |
| 336 tests.append({ | 354 tests.append({ |
| 337 'class': '%s.%s' % (package_name, class_name), | 355 'class': '%s.%s' % (package_name, class_name), |
| 338 'annotations': {}, | 356 'annotations': {}, |
| 339 'methods': get_test_methods(class_info['methods']), | 357 'methods': get_test_methods(class_info['methods']), |
| 340 'superclass': class_info['superclass'], | 358 'superclass': class_info['superclass'], |
| 341 }) | 359 }) |
| 342 return tests | 360 return tests |
| 343 | 361 |
| 362 def _GetAllTestsFromRunner(device, test_package, filename, | |
| 363 test_runner=None, test_runner_junit4=None): | |
| 364 device_path = os.path.join(device.GetExternalStoragePath(), | |
| 365 'chromium_tests_root', filename) | |
| 366 device.RunShellCommand(['rm', device_path], check_return=False) | |
| 367 if test_runner is None and test_runner_junit4 is None: | |
| 368 raise Exception('Test runner does NOT exist for this test apk') | |
| 369 if test_runner_junit4: | |
|
mikecase (-- gone --)
2017/07/11 21:14:51
Question. Where are junit3 test listed out? I dont
the real yoland
2017/07/14 03:15:46
JUnit3 tests are now listed together with JUnit4 t
| |
| 370 extras = {} | |
| 371 extras['listAllTests'] = filename | |
| 372 extras['log'] = 'true' | |
| 373 extras['package'] = 'org.chromium' | |
| 374 target = '%s/%s' % (test_package, test_runner_junit4) | |
| 375 device.StartInstrumentation( | |
| 376 target, extras=extras, timeout=10000, retries=0) | |
|
mikecase (-- gone --)
2017/07/11 21:14:51
isnt timeout in seconds? 10000 seems intense!
the real yoland
2017/07/14 03:15:46
Done
| |
| 377 with tempfile_ext.NamedTemporaryDirectory() as host_dir: | |
| 378 host_file = os.path.join(host_dir, filename) | |
| 379 device.PullFile(device_path, host_dir) | |
| 380 with open(host_file, 'r') as f: | |
| 381 json_string = f.read() | |
| 382 return json.loads(json_string) | |
| 383 | |
| 344 | 384 |
| 345 def _SaveTestsToPickle(pickle_path, jar_path, tests): | 385 def _SaveTestsToPickle(pickle_path, jar_path, tests): |
| 346 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] | 386 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] |
| 347 pickle_data = { | 387 pickle_data = { |
| 348 'VERSION': _PICKLE_FORMAT_VERSION, | 388 'VERSION': _PICKLE_FORMAT_VERSION, |
| 349 'JAR_MD5SUM': jar_md5, | 389 'JAR_MD5SUM': jar_md5, |
| 350 'TEST_METHODS': tests, | 390 'TEST_METHODS': tests, |
| 351 } | 391 } |
| 352 with open(pickle_path, 'w') as pickle_file: | 392 with open(pickle_path, 'w') as pickle_file: |
| 353 pickle.dump(pickle_data, pickle_file) | 393 pickle.dump(pickle_data, pickle_file) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 self._suite = None | 476 self._suite = None |
| 437 self._test_apk = None | 477 self._test_apk = None |
| 438 self._test_apk_incremental_install_script = None | 478 self._test_apk_incremental_install_script = None |
| 439 self._test_jar = None | 479 self._test_jar = None |
| 440 self._test_package = None | 480 self._test_package = None |
| 441 self._test_runner = None | 481 self._test_runner = None |
| 442 self._test_runner_junit4 = None | 482 self._test_runner_junit4 = None |
| 443 self._test_support_apk = None | 483 self._test_support_apk = None |
| 444 self._initializeApkAttributes(args, error_func) | 484 self._initializeApkAttributes(args, error_func) |
| 445 | 485 |
| 486 self._tests_from_file = [] | |
| 487 | |
| 446 self._data_deps = None | 488 self._data_deps = None |
| 447 self._data_deps_delegate = None | 489 self._data_deps_delegate = None |
| 448 self._runtime_deps_path = None | 490 self._runtime_deps_path = None |
| 449 self._initializeDataDependencyAttributes(args, data_deps_delegate) | 491 self._initializeDataDependencyAttributes(args, data_deps_delegate) |
| 450 | 492 |
| 451 self._annotations = None | 493 self._annotations = None |
| 452 self._excluded_annotations = None | 494 self._excluded_annotations = None |
| 453 self._test_filter = None | 495 self._test_filter = None |
| 454 self._initializeTestFilterAttributes(args) | 496 self._initializeTestFilterAttributes(args) |
| 455 | 497 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 return 'instrumentation' | 830 return 'instrumentation' |
| 789 | 831 |
| 790 #override | 832 #override |
| 791 def SetUp(self): | 833 def SetUp(self): |
| 792 self._data_deps.extend( | 834 self._data_deps.extend( |
| 793 self._data_deps_delegate(self._runtime_deps_path)) | 835 self._data_deps_delegate(self._runtime_deps_path)) |
| 794 | 836 |
| 795 def GetDataDependencies(self): | 837 def GetDataDependencies(self): |
| 796 return self._data_deps | 838 return self._data_deps |
| 797 | 839 |
| 798 def GetTests(self): | 840 def GetTests(self, device=None): |
| 799 if self.test_jar: | 841 filename = 'list_all_tests.json' |
| 842 if self._test_runner_junit4 and device: | |
| 843 tests = GetAllTestsFromRunner( | |
| 844 device, self.test_apk.path, self.test_package, filename, | |
| 845 test_runner=self._test_runner, | |
| 846 test_runner_junit4=self.test_runner_junit4) | |
| 847 elif self.test_jar: | |
| 800 tests = GetAllTestsFromJar(self.test_jar) | 848 tests = GetAllTestsFromJar(self.test_jar) |
| 801 else: | 849 else: |
| 802 tests = GetAllTestsFromApk(self.test_apk.path) | 850 tests = GetAllTestsFromApk(self.test_apk.path) |
| 803 inflated_tests = self._ParameterizeTestsWithFlags(self._InflateTests(tests)) | 851 inflated_tests = self._ParameterizeTestsWithFlags(self._InflateTests(tests)) |
| 804 if self._test_runner_junit4 is None and any( | 852 if self._test_runner_junit4 is None and any( |
| 805 t['is_junit4'] for t in inflated_tests): | 853 t['is_junit4'] for t in inflated_tests): |
| 806 raise MissingJUnit4RunnerException() | 854 raise MissingJUnit4RunnerException() |
| 807 filtered_tests = FilterTests( | 855 filtered_tests = FilterTests( |
| 808 inflated_tests, self._test_filter, self._annotations, | 856 inflated_tests, self._test_filter, self._annotations, |
| 809 self._excluded_annotations) | 857 self._excluded_annotations) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 @staticmethod | 913 @staticmethod |
| 866 def ParseAmInstrumentRawOutput(raw_output): | 914 def ParseAmInstrumentRawOutput(raw_output): |
| 867 return ParseAmInstrumentRawOutput(raw_output) | 915 return ParseAmInstrumentRawOutput(raw_output) |
| 868 | 916 |
| 869 @staticmethod | 917 @staticmethod |
| 870 def GenerateTestResults( | 918 def GenerateTestResults( |
| 871 result_code, result_bundle, statuses, start_ms, duration_ms): | 919 result_code, result_bundle, statuses, start_ms, duration_ms): |
| 872 return GenerateTestResults(result_code, result_bundle, statuses, | 920 return GenerateTestResults(result_code, result_bundle, statuses, |
| 873 start_ms, duration_ms) | 921 start_ms, duration_ms) |
| 874 | 922 |
| 923 def ReadAndSetTests(self, host_file): | |
|
mikecase (-- gone --)
2017/07/11 21:14:51
Is this used?
the real yoland
2017/07/14 03:15:46
My bad, removed
| |
| 924 with open(host_file, 'r') as f: | |
| 925 self._tests_from_file = f.readlines() | |
| 926 | |
| 875 #override | 927 #override |
| 876 def TearDown(self): | 928 def TearDown(self): |
| 877 pass | 929 pass |
| OLD | NEW |