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 |
21 from pylib.utils import proguard | 22 from pylib.utils import proguard |
22 | 23 |
23 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): | 24 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
24 import unittest_util # pylint: disable=import-error | 25 import unittest_util # pylint: disable=import-error |
25 | 26 |
26 # Ref: http://developer.android.com/reference/android/app/Activity.html | 27 # Ref: http://developer.android.com/reference/android/app/Activity.html |
27 _ACTIVITY_RESULT_CANCELED = 0 | 28 _ACTIVITY_RESULT_CANCELED = 0 |
28 _ACTIVITY_RESULT_OK = -1 | 29 _ACTIVITY_RESULT_OK = -1 |
29 | 30 |
30 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' | 31 _COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 flags = test['flags'] | 393 flags = test['flags'] |
393 if flags.add: | 394 if flags.add: |
394 display_name = '%s with {%s}' % (display_name, ' '.join(flags.add)) | 395 display_name = '%s with {%s}' % (display_name, ' '.join(flags.add)) |
395 if flags.remove: | 396 if flags.remove: |
396 display_name = '%s without {%s}' % (display_name, ' '.join(flags.remove)) | 397 display_name = '%s without {%s}' % (display_name, ' '.join(flags.remove)) |
397 return display_name | 398 return display_name |
398 | 399 |
399 | 400 |
400 class InstrumentationTestInstance(test_instance.TestInstance): | 401 class InstrumentationTestInstance(test_instance.TestInstance): |
401 | 402 |
402 def __init__(self, args, data_deps_delegate, error_func): | 403 def __init__(self, args, isolate_delegate, error_func): |
403 super(InstrumentationTestInstance, self).__init__() | 404 super(InstrumentationTestInstance, self).__init__() |
404 | 405 |
405 self._additional_apks = [] | 406 self._additional_apks = [] |
406 self._apk_under_test = None | 407 self._apk_under_test = None |
407 self._apk_under_test_incremental_install_script = None | 408 self._apk_under_test_incremental_install_script = None |
408 self._package_info = None | 409 self._package_info = None |
409 self._suite = None | 410 self._suite = None |
410 self._test_apk = None | 411 self._test_apk = None |
411 self._test_apk_incremental_install_script = None | 412 self._test_apk_incremental_install_script = None |
412 self._test_jar = None | 413 self._test_jar = None |
413 self._test_package = None | 414 self._test_package = None |
414 self._test_runner = None | 415 self._test_runner = None |
415 self._test_support_apk = None | 416 self._test_support_apk = None |
416 self._initializeApkAttributes(args, error_func) | 417 self._initializeApkAttributes(args, error_func) |
417 | 418 |
418 self._data_deps = None | 419 self._data_deps = None |
419 self._data_deps_delegate = None | 420 self._isolate_abs_path = None |
420 self._runtime_deps_path = None | 421 self._isolate_delegate = None |
421 self._initializeDataDependencyAttributes(args, data_deps_delegate) | 422 self._isolated_abs_path = None |
| 423 self._initializeDataDependencyAttributes(args, isolate_delegate) |
422 | 424 |
423 self._annotations = None | 425 self._annotations = None |
424 self._excluded_annotations = None | 426 self._excluded_annotations = None |
425 self._test_filter = None | 427 self._test_filter = None |
426 self._initializeTestFilterAttributes(args) | 428 self._initializeTestFilterAttributes(args) |
427 | 429 |
428 self._flags = None | 430 self._flags = None |
429 self._initializeFlagAttributes(args) | 431 self._initializeFlagAttributes(args) |
430 | 432 |
431 self._driver_apk = None | 433 self._driver_apk = None |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 break | 513 break |
512 if not self._package_info: | 514 if not self._package_info: |
513 logging.warning('Unable to find package info for %s', self._test_package) | 515 logging.warning('Unable to find package info for %s', self._test_package) |
514 | 516 |
515 for apk in args.additional_apks: | 517 for apk in args.additional_apks: |
516 if not os.path.exists(apk): | 518 if not os.path.exists(apk): |
517 error_func('Unable to find additional APK: %s' % apk) | 519 error_func('Unable to find additional APK: %s' % apk) |
518 self._additional_apks = ( | 520 self._additional_apks = ( |
519 [apk_helper.ToHelper(x) for x in args.additional_apks]) | 521 [apk_helper.ToHelper(x) for x in args.additional_apks]) |
520 | 522 |
521 def _initializeDataDependencyAttributes(self, args, data_deps_delegate): | 523 def _initializeDataDependencyAttributes(self, args, isolate_delegate): |
522 self._data_deps = [] | 524 self._data_deps = [] |
523 self._data_deps_delegate = data_deps_delegate | 525 if (args.isolate_file_path and |
524 self._runtime_deps_path = args.runtime_deps_path | 526 not isolator.IsIsolateEmpty(args.isolate_file_path)): |
| 527 if os.path.isabs(args.isolate_file_path): |
| 528 self._isolate_abs_path = args.isolate_file_path |
| 529 else: |
| 530 self._isolate_abs_path = os.path.join( |
| 531 constants.DIR_SOURCE_ROOT, args.isolate_file_path) |
| 532 self._isolate_delegate = isolate_delegate |
| 533 self._isolated_abs_path = os.path.join( |
| 534 constants.GetOutDirectory(), '%s.isolated' % self._test_package) |
| 535 else: |
| 536 self._isolate_delegate = None |
525 | 537 |
526 if not self._runtime_deps_path: | 538 if not self._isolate_delegate: |
527 logging.warning('No data dependencies will be pushed.') | 539 logging.warning('No data dependencies will be pushed.') |
528 | 540 |
529 def _initializeTestFilterAttributes(self, args): | 541 def _initializeTestFilterAttributes(self, args): |
530 if args.test_filter: | 542 if args.test_filter: |
531 self._test_filter = _CMDLINE_NAME_SEGMENT_RE.sub( | 543 self._test_filter = _CMDLINE_NAME_SEGMENT_RE.sub( |
532 '', args.test_filter.replace('#', '.')) | 544 '', args.test_filter.replace('#', '.')) |
533 | 545 |
534 def annotation_element(a): | 546 def annotation_element(a): |
535 a = a.split('=', 1) | 547 a = a.split('=', 1) |
536 return (a[0], a[1] if len(a) == 2 else None) | 548 return (a[0], a[1] if len(a) == 2 else None) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 @property | 681 @property |
670 def timeout_scale(self): | 682 def timeout_scale(self): |
671 return self._timeout_scale | 683 return self._timeout_scale |
672 | 684 |
673 #override | 685 #override |
674 def TestType(self): | 686 def TestType(self): |
675 return 'instrumentation' | 687 return 'instrumentation' |
676 | 688 |
677 #override | 689 #override |
678 def SetUp(self): | 690 def SetUp(self): |
679 self._data_deps.extend( | 691 if self._isolate_delegate: |
680 self._data_deps_delegate(self._runtime_deps_path)) | 692 self._isolate_delegate.Remap( |
| 693 self._isolate_abs_path, self._isolated_abs_path) |
| 694 self._isolate_delegate.MoveOutputDeps() |
| 695 self._data_deps.extend([(self._isolate_delegate.isolate_deps_dir, None)]) |
681 | 696 |
682 def GetDataDependencies(self): | 697 def GetDataDependencies(self): |
683 return self._data_deps | 698 return self._data_deps |
684 | 699 |
685 def GetTests(self): | 700 def GetTests(self): |
686 tests = GetAllTests(self.test_jar) | 701 tests = GetAllTests(self.test_jar) |
687 inflated_tests = self._ParametrizeTestsWithFlags(self._InflateTests(tests)) | 702 inflated_tests = self._ParametrizeTestsWithFlags(self._InflateTests(tests)) |
688 filtered_tests = FilterTests( | 703 filtered_tests = FilterTests( |
689 inflated_tests, self._test_filter, self._annotations, | 704 inflated_tests, self._test_filter, self._annotations, |
690 self._excluded_annotations) | 705 self._excluded_annotations) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 return ParseAmInstrumentRawOutput(raw_output) | 757 return ParseAmInstrumentRawOutput(raw_output) |
743 | 758 |
744 @staticmethod | 759 @staticmethod |
745 def GenerateTestResults( | 760 def GenerateTestResults( |
746 result_code, result_bundle, statuses, start_ms, duration_ms): | 761 result_code, result_bundle, statuses, start_ms, duration_ms): |
747 return GenerateTestResults(result_code, result_bundle, statuses, | 762 return GenerateTestResults(result_code, result_bundle, statuses, |
748 start_ms, duration_ms) | 763 start_ms, duration_ms) |
749 | 764 |
750 #override | 765 #override |
751 def TearDown(self): | 766 def TearDown(self): |
752 pass | 767 if self._isolate_delegate: |
| 768 self._isolate_delegate.Clear() |
OLD | NEW |