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

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: Removes unnecessary option, cleans up some string formatting 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 dcf3d20613d6e5b867688d5c83d0c492da6f8554..7aa8d76539f2c47b5f7680c1bd775b1f764ecf1e 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, install_apk, 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:
@@ -74,6 +75,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)
@@ -88,6 +91,7 @@ class TestRunner(base_test_runner.BaseTestRunner):
self.test_pkg = test_pkg
self.ports_to_forward = ports_to_forward
self.install_apk = install_apk
+ self.coverage_dir = coverage_dir
#override
def InstallTestPackage(self):
@@ -118,11 +122,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
@@ -130,11 +134,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)
@@ -174,6 +182,14 @@ class TestRunner(base_test_runner.BaseTestRunner):
# Make sure the forwarder is still running.
self.RestartHttpServerForwarderIfNecessary()
+ if self.coverage_dir:
+ self.coverage_basename = '%s.ec' % (test)
frankf 2013/07/25 20:28:19 No need for ()
frankf 2013/07/25 20:28:19 This var is local now
gkanwar1 2013/08/01 02:14:35 Done.
gkanwar1 2013/08/01 02:14:35 Done.
+ self.coverage_device_file = '%s/%s/%s' % (self.adb.GetExternalStorage(),
+ TestRunner._DEVICE_COVERAGE_DIR,
+ self.coverage_basename)
+ self.coverage_host_file = os.path.join(
+ self.coverage_dir, self.coverage_basename)
+
def _IsPerfTest(self, test):
"""Determines whether a test is a performance test.
@@ -216,6 +232,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)
+
def TearDownPerfMonitoring(self, test):
"""Cleans up performance monitoring if the specified test required it.
@@ -308,7 +328,7 @@ class TestRunner(base_test_runner.BaseTestRunner):
try:
return self.adb.RunInstrumentationTest(
test, self.test_pkg.GetPackageName(),
- self._GetInstrumentationArgs(), timeout)
+ self._GetInstrumentationArgs(test), timeout)
except android_commands.errors.WaitForResponseTimedOutError:
logging.info('Ran the test with timeout of %ds.' % timeout)
raise

Powered by Google App Engine
This is Rietveld 408576698