| 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 logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import pickle | 9 import pickle |
| 10 import re | 10 import re |
| 11 | 11 |
| 12 from devil.android import apk_helper | 12 from devil.android import apk_helper |
| 13 from devil.android import md5sum | 13 from devil.android import md5sum |
| 14 from pylib import constants | 14 from pylib import constants |
| 15 from pylib.base import base_test_result | 15 from pylib.base import base_test_result |
| 16 from pylib.base import test_exception | 16 from pylib.base import test_exception |
| 17 from pylib.base import test_instance | 17 from pylib.base import test_instance |
| 18 from pylib.constants import host_paths | 18 from pylib.constants import host_paths |
| 19 from pylib.instrumentation import test_result | 19 from pylib.instrumentation import test_result |
| 20 from pylib.instrumentation import instrumentation_parser | 20 from pylib.instrumentation import instrumentation_parser |
| 21 from pylib.utils import isolator | |
| 22 from pylib.utils import proguard | 21 from pylib.utils import proguard |
| 23 | 22 |
| 24 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): | 23 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
| 25 import unittest_util # pylint: disable=import-error | 24 import unittest_util # pylint: disable=import-error |
| 26 | 25 |
| 27 # Ref: http://developer.android.com/reference/android/app/Activity.html | 26 # Ref: http://developer.android.com/reference/android/app/Activity.html |
| 28 _ACTIVITY_RESULT_CANCELED = 0 | 27 _ACTIVITY_RESULT_CANCELED = 0 |
| 29 _ACTIVITY_RESULT_OK = -1 | 28 _ACTIVITY_RESULT_OK = -1 |
| 30 | 29 |
| 31 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' | 30 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 class UnmatchedFilterException(test_exception.TestException): | 355 class UnmatchedFilterException(test_exception.TestException): |
| 357 """Raised when a user specifies a filter that doesn't match any tests.""" | 356 """Raised when a user specifies a filter that doesn't match any tests.""" |
| 358 | 357 |
| 359 def __init__(self, test_filter): | 358 def __init__(self, test_filter): |
| 360 super(UnmatchedFilterException, self).__init__( | 359 super(UnmatchedFilterException, self).__init__( |
| 361 'Test filter "%s" matched no tests.' % test_filter) | 360 'Test filter "%s" matched no tests.' % test_filter) |
| 362 | 361 |
| 363 | 362 |
| 364 class InstrumentationTestInstance(test_instance.TestInstance): | 363 class InstrumentationTestInstance(test_instance.TestInstance): |
| 365 | 364 |
| 366 def __init__(self, args, isolate_delegate, error_func): | 365 def __init__(self, args, data_deps_delegate, error_func): |
| 367 super(InstrumentationTestInstance, self).__init__() | 366 super(InstrumentationTestInstance, self).__init__() |
| 368 | 367 |
| 369 self._additional_apks = [] | 368 self._additional_apks = [] |
| 370 self._apk_under_test = None | 369 self._apk_under_test = None |
| 371 self._apk_under_test_incremental_install_script = None | 370 self._apk_under_test_incremental_install_script = None |
| 372 self._package_info = None | 371 self._package_info = None |
| 373 self._suite = None | 372 self._suite = None |
| 374 self._test_apk = None | 373 self._test_apk = None |
| 375 self._test_apk_incremental_install_script = None | 374 self._test_apk_incremental_install_script = None |
| 376 self._test_jar = None | 375 self._test_jar = None |
| 377 self._test_package = None | 376 self._test_package = None |
| 378 self._test_runner = None | 377 self._test_runner = None |
| 379 self._test_support_apk = None | 378 self._test_support_apk = None |
| 380 self._initializeApkAttributes(args, error_func) | 379 self._initializeApkAttributes(args, error_func) |
| 381 | 380 |
| 382 self._data_deps = None | 381 self._data_deps = None |
| 382 self._data_deps_delegate = None |
| 383 self._isolate_abs_path = None | 383 self._isolate_abs_path = None |
| 384 self._isolate_delegate = None | 384 self._initializeDataDependencyAttributes(args, data_deps_delegate) |
| 385 self._isolated_abs_path = None | |
| 386 self._initializeDataDependencyAttributes(args, isolate_delegate) | |
| 387 | 385 |
| 388 self._annotations = None | 386 self._annotations = None |
| 389 self._excluded_annotations = None | 387 self._excluded_annotations = None |
| 390 self._test_filter = None | 388 self._test_filter = None |
| 391 self._initializeTestFilterAttributes(args) | 389 self._initializeTestFilterAttributes(args) |
| 392 | 390 |
| 393 self._flags = None | 391 self._flags = None |
| 394 self._initializeFlagAttributes(args) | 392 self._initializeFlagAttributes(args) |
| 395 | 393 |
| 396 self._driver_apk = None | 394 self._driver_apk = None |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 break | 474 break |
| 477 if not self._package_info: | 475 if not self._package_info: |
| 478 logging.warning('Unable to find package info for %s', self._test_package) | 476 logging.warning('Unable to find package info for %s', self._test_package) |
| 479 | 477 |
| 480 for apk in args.additional_apks: | 478 for apk in args.additional_apks: |
| 481 if not os.path.exists(apk): | 479 if not os.path.exists(apk): |
| 482 error_func('Unable to find additional APK: %s' % apk) | 480 error_func('Unable to find additional APK: %s' % apk) |
| 483 self._additional_apks = ( | 481 self._additional_apks = ( |
| 484 [apk_helper.ToHelper(x) for x in args.additional_apks]) | 482 [apk_helper.ToHelper(x) for x in args.additional_apks]) |
| 485 | 483 |
| 486 def _initializeDataDependencyAttributes(self, args, isolate_delegate): | 484 def _initializeDataDependencyAttributes(self, args, data_deps_delegate): |
| 487 self._data_deps = [] | 485 self._data_deps = [] |
| 488 if (args.isolate_file_path and | 486 self._data_deps_delegate = data_deps_delegate |
| 489 not isolator.IsIsolateEmpty(args.isolate_file_path)): | 487 self._isolate_abs_path = args.isolate_file_path |
| 490 if os.path.isabs(args.isolate_file_path): | |
| 491 self._isolate_abs_path = args.isolate_file_path | |
| 492 else: | |
| 493 self._isolate_abs_path = os.path.join( | |
| 494 constants.DIR_SOURCE_ROOT, args.isolate_file_path) | |
| 495 self._isolate_delegate = isolate_delegate | |
| 496 self._isolated_abs_path = os.path.join( | |
| 497 constants.GetOutDirectory(), '%s.isolated' % self._test_package) | |
| 498 else: | |
| 499 self._isolate_delegate = None | |
| 500 | 488 |
| 501 if not self._isolate_delegate: | 489 if not self._isolate_abs_path: |
| 502 logging.warning('No data dependencies will be pushed.') | 490 logging.warning('No data dependencies will be pushed.') |
| 503 | 491 |
| 504 def _initializeTestFilterAttributes(self, args): | 492 def _initializeTestFilterAttributes(self, args): |
| 505 if args.test_filter: | 493 if args.test_filter: |
| 506 self._test_filter = args.test_filter.replace('#', '.') | 494 self._test_filter = args.test_filter.replace('#', '.') |
| 507 | 495 |
| 508 def annotation_element(a): | 496 def annotation_element(a): |
| 509 a = a.split('=', 1) | 497 a = a.split('=', 1) |
| 510 return (a[0], a[1] if len(a) == 2 else None) | 498 return (a[0], a[1] if len(a) == 2 else None) |
| 511 | 499 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 @property | 631 @property |
| 644 def timeout_scale(self): | 632 def timeout_scale(self): |
| 645 return self._timeout_scale | 633 return self._timeout_scale |
| 646 | 634 |
| 647 #override | 635 #override |
| 648 def TestType(self): | 636 def TestType(self): |
| 649 return 'instrumentation' | 637 return 'instrumentation' |
| 650 | 638 |
| 651 #override | 639 #override |
| 652 def SetUp(self): | 640 def SetUp(self): |
| 653 if self._isolate_delegate: | 641 self._data_deps.extend( |
| 654 self._isolate_delegate.Remap( | 642 self._data_deps_delegate(self._isolate_abs_path)) |
| 655 self._isolate_abs_path, self._isolated_abs_path) | |
| 656 self._isolate_delegate.MoveOutputDeps() | |
| 657 self._data_deps.extend([(self._isolate_delegate.isolate_deps_dir, None)]) | |
| 658 | 643 |
| 659 def GetDataDependencies(self): | 644 def GetDataDependencies(self): |
| 660 return self._data_deps | 645 return self._data_deps |
| 661 | 646 |
| 662 def GetTests(self): | 647 def GetTests(self): |
| 663 tests = GetAllTests(self.test_jar) | 648 tests = GetAllTests(self.test_jar) |
| 664 filtered_tests = FilterTests( | 649 filtered_tests = FilterTests( |
| 665 tests, self._test_filter, self._annotations, self._excluded_annotations) | 650 tests, self._test_filter, self._annotations, self._excluded_annotations) |
| 666 if self._test_filter and not filtered_tests: | 651 if self._test_filter and not filtered_tests: |
| 667 raise UnmatchedFilterException(self._test_filter) | 652 raise UnmatchedFilterException(self._test_filter) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 return ParseAmInstrumentRawOutput(raw_output) | 700 return ParseAmInstrumentRawOutput(raw_output) |
| 716 | 701 |
| 717 @staticmethod | 702 @staticmethod |
| 718 def GenerateTestResults( | 703 def GenerateTestResults( |
| 719 result_code, result_bundle, statuses, start_ms, duration_ms): | 704 result_code, result_bundle, statuses, start_ms, duration_ms): |
| 720 return GenerateTestResults(result_code, result_bundle, statuses, | 705 return GenerateTestResults(result_code, result_bundle, statuses, |
| 721 start_ms, duration_ms) | 706 start_ms, duration_ms) |
| 722 | 707 |
| 723 #override | 708 #override |
| 724 def TearDown(self): | 709 def TearDown(self): |
| 725 if self._isolate_delegate: | 710 pass |
| 726 self._isolate_delegate.Clear() | |
| OLD | NEW |