Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1612)

Unified Diff: build/android/pylib/instrumentation/instrumentation_test_instance.py

Issue 2935503002: List Java Instru Test Information From JUnit Runner (Closed)
Patch Set: address comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..675df4c644a61317761dc0eeb9baee80656bdbc7 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
@@ -185,6 +187,12 @@ def FilterTests(tests, test_filter=None, annotations=None,
GetUniqueTestName(t, sep='.')
]
+ if t['is_junit4']:
+ names += [
+ GetTestNameWithoutParameterPostfix(t, sep='.'),
jbudorick 2017/07/14 18:43:55 These make it so that, if someone passes the test
the real yoland 2017/07/18 04:20:21 I think this just makes that if someone pass in te
+ GetTestNameWithoutParameterPostfix(unqualified_class_test, sep='.')
+ ]
+
pattern_groups = test_filter.split('-')
if len(pattern_groups) > 1:
negative_filter = pattern_groups[1]
@@ -239,6 +247,23 @@ 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 = _GetAllTestsFromRunner(device, test_package, filename,
jbudorick 2017/07/14 18:43:55 What's going on here? Why does it get the tests fr
the real yoland 2017/07/18 04:20:21 oops, my bad Done
+ test_runner, test_runner_junit4)
+ 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:
@@ -336,6 +361,31 @@ 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(),
jbudorick 2017/07/14 18:43:55 just use a device temp file: https://codesearch.ch
the real yoland 2017/07/18 04:20:22 Done
+ '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:
jbudorick 2017/07/14 18:43:56 If there is no test_runner_junit4, it looks like w
the real yoland 2017/07/18 04:20:21 Done
+ extras = {}
+ extras['listAllTests'] = filename
+ 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=0))
jbudorick 2017/07/14 18:43:55 No retries?
the real yoland 2017/07/18 04:20:22 Set retries to 2? Done
+ if output_string:
+ raise Exception('Test listing through %s failed on device:\n%s' % (
+ test_runner_junit4, output_string))
+ 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]
@@ -379,6 +429,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 +840,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)

Powered by Google App Engine
This is Rietveld 408576698