| Index: build/android/pylib/instrumentation/instrumentation_test_instance.py
|
| diff --git a/build/android/pylib/instrumentation/instrumentation_test_instance.py b/build/android/pylib/instrumentation/instrumentation_test_instance.py
|
| index 2443384e51864c28c3a3c22d2b19f34704ae8aca..83ec583b9243ced6b63481618cbcc2b35085d978 100644
|
| --- a/build/android/pylib/instrumentation/instrumentation_test_instance.py
|
| +++ b/build/android/pylib/instrumentation/instrumentation_test_instance.py
|
| @@ -3,12 +3,14 @@
|
| # found in the LICENSE file.
|
|
|
| import copy
|
| +import json
|
| import logging
|
| import os
|
| import pickle
|
| import re
|
|
|
| from devil.android import apk_helper
|
| +from devil.android import device_temp_file
|
| from devil.android import md5sum
|
| from pylib import constants
|
| from pylib.base import base_test_result
|
| @@ -20,6 +22,7 @@ from pylib.instrumentation import instrumentation_parser
|
| from pylib.utils import dexdump
|
| from pylib.utils import proguard
|
| from pylib.utils import shared_preference_utils
|
| +from py_utils import tempfile_ext
|
|
|
| with host_paths.SysPath(host_paths.BUILD_COMMON_PATH):
|
| import unittest_util # pylint: disable=import-error
|
| @@ -45,6 +48,8 @@ _EXTRA_DRIVER_TARGET_CLASS = (
|
| 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass')
|
| _EXTRA_TIMEOUT_SCALE = (
|
| 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TimeoutScale')
|
| +_EXTRA_TEST_LIST = (
|
| + 'org.chromium.base.test.BaseChromiumAndroidJUnitRunner.TestList')
|
|
|
| _SKIP_PARAMETERIZATION = 'SkipCommandLineParameterization'
|
| _COMMANDLINE_PARAMETERIZATION = 'CommandLineParameter'
|
| @@ -185,6 +190,12 @@ def FilterTests(tests, test_filter=None, annotations=None,
|
| GetUniqueTestName(t, sep='.')
|
| ]
|
|
|
| + if t['is_junit4']:
|
| + names += [
|
| + GetTestNameWithoutParameterPostfix(t, sep='.'),
|
| + GetTestNameWithoutParameterPostfix(unqualified_class_test, sep='.')
|
| + ]
|
| +
|
| pattern_groups = test_filter.split('-')
|
| if len(pattern_groups) > 1:
|
| negative_filter = pattern_groups[1]
|
| @@ -239,6 +250,21 @@ def FilterTests(tests, test_filter=None, annotations=None,
|
| return filtered_tests
|
|
|
|
|
| +def GetAllTestsFromRunner(device, test_apk_path, test_package,
|
| + test_runner=None, test_runner_junit4=None):
|
| + pickle_path = '%s-runner.pickle' % test_apk_path
|
| + try:
|
| + tests = _GetTestsFromPickle(pickle_path, test_apk_path)
|
| + except TestListPickleException as e:
|
| + logging.info('Could not get tests from pickle: %s', e)
|
| + logging.info('Getting tests by print tests in instrumentation runner')
|
| + tests = _GetAllTestsFromRunner(device, test_package, test_runner,
|
| + test_runner_junit4)
|
| + _SaveTestsToPickle(pickle_path, test_apk_path, tests)
|
| + return tests
|
| +
|
| +
|
| +# TODO(yolandyan): remove this once the tests are converted to junit4
|
| def GetAllTestsFromJar(test_jar):
|
| pickle_path = '%s-proguard.pickle' % test_jar
|
| try:
|
| @@ -336,6 +362,32 @@ def _GetTestsFromDexdump(test_apk):
|
| })
|
| return tests
|
|
|
| +def _GetAllTestsFromRunner(device, test_package, test_runner=None,
|
| + test_runner_junit4=None):
|
| + with device_temp_file.DeviceTempFile(
|
| + device.adb, suffix='.json', dir=device.GetExternalStoragePath()) as f:
|
| + if test_runner is None and test_runner_junit4 is None:
|
| + raise Exception('Test runner does NOT exist for this test apk')
|
| + if test_runner_junit4:
|
| + extras = {}
|
| + extras[_EXTRA_TEST_LIST] = f.name
|
| + extras['log'] = 'true'
|
| + extras['package'] = 'org.chromium'
|
| + target = '%s/%s' % (test_package, test_runner_junit4)
|
| + output_string = ''.join(device.StartInstrumentation(
|
| + target, extras=extras, timeout=30, retries=2))
|
| + if output_string:
|
| + raise Exception('Test listing through %s failed on device:\n%s' % (
|
| + test_runner_junit4, output_string))
|
| + else:
|
| + raise Exception('JUnit4 Runner is not present in this apk')
|
| + with tempfile_ext.NamedTemporaryDirectory() as host_dir:
|
| + host_file = os.path.join(host_dir, 'list_tests.json')
|
| + device.PullFile(f.name, host_file)
|
| + with open(host_file, 'r') as host_file:
|
| + json_string = host_file.read()
|
| + return json.loads(json_string)
|
| +
|
|
|
| def _SaveTestsToPickle(pickle_path, jar_path, tests):
|
| jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path]
|
| @@ -379,6 +431,28 @@ def GetTestName(test, sep='#'):
|
| return '%s%s%s' % (test['class'], sep, test['method'])
|
|
|
|
|
| +def GetTestNameWithoutParameterPostfix(
|
| + test, sep='#', parameter_postfix='__'):
|
| + """Gets the name of the given JUnit4 test withouth parameter postfix.
|
| +
|
| + For most WebView JUnit4 javatests, each test is parameterizatized with
|
| + "__sandboxed_mode" to run in both non-sandboxed mode and sandboxed mode.
|
| +
|
| + This function returns the name of the test without parameterization
|
| + so test filters can match both parameterized and non-parameterized tests.
|
| +
|
| + Args:
|
| + test: the instrumentation test dict.
|
| + sep: the character(s) that should join the class name and the method name.
|
| + parameterization_sep: the character(s) that seperate method name and method
|
| + parameterization postfix.
|
| + Returns:
|
| + The test name without parameter postfix as a string.
|
| + """
|
| + name = GetTestName(test, sep=sep)
|
| + return name.split(parameter_postfix)[0]
|
| +
|
| +
|
| def GetUniqueTestName(test, sep='#'):
|
| """Gets the unique name of the given test.
|
|
|
| @@ -768,8 +842,13 @@ class InstrumentationTestInstance(test_instance.TestInstance):
|
| def GetDataDependencies(self):
|
| return self._data_deps
|
|
|
| - def GetTests(self):
|
| - if self.test_jar:
|
| + def GetTests(self, device=None):
|
| + if self._test_runner_junit4:
|
| + tests = GetAllTestsFromRunner(
|
| + device, self.test_apk.path, self.test_package,
|
| + test_runner=self._test_runner,
|
| + test_runner_junit4=self.test_runner_junit4)
|
| + elif self.test_jar:
|
| tests = GetAllTestsFromJar(self.test_jar)
|
| else:
|
| tests = GetAllTestsFromApk(self.test_apk.path)
|
|
|