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

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

Issue 20210002: [Android] Sets up a coverage system for java using EMMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Gets code coverage for non-apk java working Created 7 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/test_runner.py
diff --git a/build/android/pylib/instrumentation/test_runner.py b/build/android/pylib/instrumentation/test_runner.py
index b4ad7f44ddf20449c1fc2dc06e3a89d5e86ca799..186ba80629eeb396aa60276c3806e4f8a1823b5d 100644
--- a/build/android/pylib/instrumentation/test_runner.py
+++ b/build/android/pylib/instrumentation/test_runner.py
@@ -47,6 +47,7 @@ class TestRunner(base_test_runner.BaseTestRunner):
"""Responsible for running a series of tests connected to a single device."""
_DEVICE_DATA_DIR = 'chrome/test/data'
+ _DEVICE_COVERAGE_DIR = 'chrome/test/coverage'
_HOSTMACHINE_PERF_OUTPUT_FILE = '/tmp/chrome-profile'
_DEVICE_PERF_OUTPUT_SEARCH_PREFIX = (constants.DEVICE_PERF_OUTPUT_DIR +
'/chrome-profile*')
@@ -55,7 +56,7 @@ class TestRunner(base_test_runner.BaseTestRunner):
def __init__(self, build_type, test_data, save_perf_json, screenshot_failures,
tool, wait_for_debugger, disable_assertions, push_deps,
cleanup_test_files, device, shard_index, test_pkg,
- ports_to_forward):
+ ports_to_forward, coverage_dir):
"""Create a new TestRunner.
Args:
@@ -73,6 +74,8 @@ class TestRunner(base_test_runner.BaseTestRunner):
test_pkg: A TestPackage object.
ports_to_forward: A list of port numbers for which to set up forwarders.
Can be optionally requested by a test case.
+ coverage_dir: Directory to pull all EMMA coverage files into, or None if
+ coverage is not being used.
"""
super(TestRunner, self).__init__(device, tool, build_type, push_deps,
cleanup_test_files)
@@ -86,6 +89,7 @@ class TestRunner(base_test_runner.BaseTestRunner):
self.disable_assertions = disable_assertions
self.test_pkg = test_pkg
self.ports_to_forward = ports_to_forward
+ self.coverage_dir = coverage_dir
#override
def InstallTestPackage(self):
@@ -115,11 +119,11 @@ class TestRunner(base_test_runner.BaseTestRunner):
dst_src = dest_host_pair.split(':',1)
dst_layer = dst_src[0]
host_src = dst_src[1]
- host_test_files_path = constants.DIR_SOURCE_ROOT + '/' + host_src
+ host_test_files_path = '%s/%s' % (constants.DIR_SOURCE_ROOT, host_src)
if os.path.exists(host_test_files_path):
- self.adb.PushIfNeeded(host_test_files_path,
- self.adb.GetExternalStorage() + '/' +
- TestRunner._DEVICE_DATA_DIR + '/' + dst_layer)
+ self.adb.PushIfNeeded(host_test_files_path, '%s/%s/%s' % (
+ self.adb.GetExternalStorage(), TestRunner._DEVICE_DATA_DIR,
+ dst_layer))
self.tool.CopyFiles()
TestRunner._DEVICE_HAS_TEST_FILES[self.device] = True
@@ -127,11 +131,15 @@ class TestRunner(base_test_runner.BaseTestRunner):
ret = {}
if self.wait_for_debugger:
ret['debug'] = 'true'
+ if self.coverage_dir:
+ ret['coverage'] = 'true'
+ ret['coverageFile'] = self.coverage_device_file
+
return ret
def _TakeScreenshot(self, test):
"""Takes a screenshot from the device."""
- screenshot_name = os.path.join(constants.SCREENSHOTS_DIR, test + '.png')
+ screenshot_name = os.path.join(constants.SCREENSHOTS_DIR, '%s.png' % test)
logging.info('Taking screenshot named %s', screenshot_name)
self.adb.TakeScreenshot(screenshot_name)
@@ -171,6 +179,14 @@ class TestRunner(base_test_runner.BaseTestRunner):
# Make sure the forwarder is still running.
self.RestartHttpServerForwarderIfNecessary()
+ if self.coverage_dir:
+ coverage_basename = '%s.ec' % test
+ self.coverage_device_file = '%s/%s/%s' % (self.adb.GetExternalStorage(),
+ TestRunner._DEVICE_COVERAGE_DIR,
+ coverage_basename)
+ self.coverage_host_file = os.path.join(
+ self.coverage_dir, coverage_basename)
+
def _IsPerfTest(self, test):
"""Determines whether a test is a performance test.
@@ -213,6 +229,10 @@ class TestRunner(base_test_runner.BaseTestRunner):
self.TearDownPerfMonitoring(test)
+ if self.coverage_dir:
+ self.adb.Adb().Pull(self.coverage_device_file, self.coverage_host_file)
+ self.adb.RunShellCommand('rm %s' % self.coverage_device_file)
frankf 2013/08/01 19:57:41 rm -f
gkanwar1 2013/08/07 19:24:56 Done.
+
def TearDownPerfMonitoring(self, test):
"""Cleans up performance monitoring if the specified test required it.

Powered by Google App Engine
This is Rietveld 408576698