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 a650a7c48f8c507234facdc26c1ae778c4224ff5..2c8d5484cbe17209474c1dc2e0c1418ae9d22e02 100644 |
--- a/build/android/pylib/instrumentation/instrumentation_test_instance.py |
+++ b/build/android/pylib/instrumentation/instrumentation_test_instance.py |
@@ -3,6 +3,7 @@ |
# found in the LICENSE file. |
import copy |
+import json |
import logging |
import os |
import pickle |
@@ -20,6 +21,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 |
@@ -244,6 +246,22 @@ def FilterTests(tests, test_filter=None, annotations=None, |
return filtered_tests |
+ |
+def GetAllTestsFromRunner(device, test_apk_path, test_package, filename, |
+ 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, filename, |
+ 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: |
@@ -341,6 +359,28 @@ def _GetTestsFromDexdump(test_apk): |
}) |
return tests |
+def _GetAllTestsFromRunner(device, test_package, filename, |
+ test_runner=None, test_runner_junit4=None): |
+ device_path = os.path.join(device.GetExternalStoragePath(), |
+ 'chromium_tests_root', filename) |
+ device.RunShellCommand(['rm', device_path], check_return=False) |
+ 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: |
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
|
+ extras = {} |
+ extras['listAllTests'] = filename |
+ extras['log'] = 'true' |
+ extras['package'] = 'org.chromium' |
+ target = '%s/%s' % (test_package, test_runner_junit4) |
+ device.StartInstrumentation( |
+ 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
|
+ with tempfile_ext.NamedTemporaryDirectory() as host_dir: |
+ host_file = os.path.join(host_dir, filename) |
+ device.PullFile(device_path, host_dir) |
+ with open(host_file, 'r') as f: |
+ json_string = f.read() |
+ return json.loads(json_string) |
+ |
def _SaveTestsToPickle(pickle_path, jar_path, tests): |
jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] |
@@ -443,6 +483,8 @@ class InstrumentationTestInstance(test_instance.TestInstance): |
self._test_support_apk = None |
self._initializeApkAttributes(args, error_func) |
+ self._tests_from_file = [] |
+ |
self._data_deps = None |
self._data_deps_delegate = None |
self._runtime_deps_path = None |
@@ -795,8 +837,14 @@ class InstrumentationTestInstance(test_instance.TestInstance): |
def GetDataDependencies(self): |
return self._data_deps |
- def GetTests(self): |
- if self.test_jar: |
+ def GetTests(self, device=None): |
+ filename = 'list_all_tests.json' |
+ if self._test_runner_junit4 and device: |
+ tests = GetAllTestsFromRunner( |
+ device, self.test_apk.path, self.test_package, filename, |
+ 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) |
@@ -872,6 +920,10 @@ class InstrumentationTestInstance(test_instance.TestInstance): |
return GenerateTestResults(result_code, result_bundle, statuses, |
start_ms, duration_ms) |
+ 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
|
+ with open(host_file, 'r') as f: |
+ self._tests_from_file = f.readlines() |
+ |
#override |
def TearDown(self): |
pass |