Bug 1473313 - Part 2: Support running emulator junit tests with code coverage support. r=gbrown
MozReview-Commit-ID: MIZm9SEdlI
--- a/testing/mochitest/runjunit.py
+++ b/testing/mochitest/runjunit.py
@@ -46,16 +46,18 @@ class JUnitTestRunner(MochitestDesktop):
self.device = ADBAndroid(adb=options.adbPath or 'adb',
device=options.deviceSerial,
test_root=options.remoteTestRoot,
verbose=verbose)
self.options = options
self.log.debug("options=%s" % vars(options))
update_mozinfo()
self.remote_profile = posixpath.join(self.device.test_root, 'junit-profile')
+ self.coverage_output_path = posixpath.join(self.device.test_root,
+ 'geckoview-junit-coverage.ec')
self.server_init()
self.cleanup()
self.device.clear_logcat()
self.build_profile()
self.startServers(
self.options,
debuggerInfo=None,
@@ -140,16 +142,20 @@ class JUnitTestRunner(MochitestDesktop):
shard = self.options.thisChunk
if shards is not None and shard is not None:
shard -= 1 # shard index is 0 based
cmd = cmd + " -e numShards %d -e shardIndex %d" % (shards, shard)
# test filters: limit run to specific test(s)
for f in test_filters:
# filter can be class-name or 'class-name#method-name' (single test)
cmd = cmd + " -e class %s" % f
+ # enable code coverage reports
+ if self.options.coverage:
+ cmd = cmd + " -e coverage true"
+ cmd = cmd + " -e coverageFile %s" % self.coverage_output_path
# environment
env = {}
env["MOZ_CRASHREPORTER"] = "1"
env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"
env["MOZ_CRASHREPORTER_SHUTDOWN"] = "1"
env["XPCOM_DEBUG_BREAK"] = "stack"
env["DISABLE_UNSAFE_CPOW_WARNINGS"] = "1"
env["MOZ_DISABLE_NONLOCAL_CONNECTIONS"] = "1"
@@ -257,16 +263,19 @@ class JUnitTestRunner(MochitestDesktop):
self.log.info("Failed: %d" % self.fail_count)
self.log.info("Todo: %d" % self.todo_count)
finally:
self.log.suite_end()
if self.check_for_crashes():
self.fail_count = 1
+ if self.options.coverage:
+ self.device.pull(self.coverage_output_path, self.options.coverage_output_path)
+
return 1 if self.fail_count else 0
def check_for_crashes(self):
logcat = self.device.get_logcat()
if logcat:
if mozcrash.check_for_java_exception(logcat, self.current_full_name):
return True
symbols_path = self.options.symbolsPath
@@ -359,16 +368,27 @@ class JunitArgumentParser(argparse.Argum
default=None,
help="Total number of chunks to split tests into.")
self.add_argument("--this-chunk",
action="store",
type=int,
dest="thisChunk",
default=None,
help="If running tests by chunks, the chunk number to run.")
+ self.add_argument("--enable-coverage",
+ action="store_true",
+ dest="coverage",
+ default=False,
+ help="Enable code coverage collection.")
+ self.add_argument("--coverage-output-path",
+ action="store",
+ type=str,
+ dest="coverage_output_path",
+ default=None,
+ help="If collecting code coverage, save the report file to this path.")
# Additional options for server.
self.add_argument("--certificate-path",
action="store",
type=str,
dest="certPath",
default=None,
help="Path to directory containing certificate store."),
self.add_argument("--http-port",