Commit d470cee7 authored by Andrew Luo's avatar Andrew Luo Committed by Commit Bot

Add jococo coverage file generation support for junit tests

Change-Id: I86456f477cfb19a127f26e255c678729d4f7769f
Reviewed-on: https://chromium-review.googlesource.com/c/1299693
Commit-Queue: Andrew Luo <aluo@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609081}
parent fb4e35b5
......@@ -14,6 +14,7 @@ class JunitTestInstance(test_instance.TestInstance):
self._android_manifest_path = args.android_manifest_path
self._coverage_dir = args.coverage_dir
self._debug_socket = args.debug_socket
self._jacoco = args.jacoco
self._package_filter = args.package_filter
self._package_name = args.package_name
self._resource_zips = args.resource_zips
......@@ -42,6 +43,10 @@ class JunitTestInstance(test_instance.TestInstance):
def coverage_dir(self):
return self._coverage_dir
@property
def jacoco(self):
return self._jacoco
@property
def debug_socket(self):
return self._debug_socket
......
......@@ -12,6 +12,7 @@ from devil.utils import reraiser_thread
from pylib import constants
from pylib.base import base_test_result
from pylib.base import test_run
from pylib.constants import host_paths
from pylib.results import json_results
from py_utils import tempfile_ext
......@@ -97,9 +98,20 @@ class LocalMachineJunitTestRun(test_run.TestRun):
os.makedirs(self._test_instance.coverage_dir)
elif not os.path.isdir(self._test_instance.coverage_dir):
raise Exception('--coverage-dir takes a directory, not file path.')
jvm_args.append('-Demma.coverage.out.file=%s' % os.path.join(
self._test_instance.coverage_dir,
'%s.ec' % self._test_instance.suite))
if self._test_instance.jacoco:
jacoco_coverage_file = os.path.join(
self._test_instance.coverage_dir,
'%s.exec' % self._test_instance.suite)
jacoco_agent_path = os.path.join(host_paths.DIR_SOURCE_ROOT,
'third_party', 'jacoco',
'lib', 'jacocoagent.jar')
jacoco_args = '-javaagent:{}=destfile={},includes=org.chromium.*'
jvm_args.append(jacoco_args.format(jacoco_agent_path,
jacoco_coverage_file))
else:
jvm_args.append('-Demma.coverage.out.file=%s' % os.path.join(
self._test_instance.coverage_dir,
'%s.ec' % self._test_instance.suite))
if jvm_args:
command.extend(['--jvm-args', '"%s"' % ' '.join(jvm_args)])
......
......@@ -495,6 +495,9 @@ def AddJUnitTestOptions(parser):
parser = parser.add_argument_group('junit arguments')
parser.add_argument(
'--jacoco', action='store_true',
help='Generate jacoco report.')
parser.add_argument(
'--coverage-dir', type=os.path.realpath,
help='Directory to store coverage info.')
......@@ -1016,6 +1019,10 @@ def main():
parser.error('--replace-system-package and --enable-concurrent-adb cannot '
'be used together')
if (getattr(args, 'jacoco', False) and
not getattr(args, 'coverage_dir', '')):
parser.error('--jacoco requires --coverage-dir')
if (hasattr(args, 'debug_socket') or
(hasattr(args, 'wait_for_java_debugger') and
args.wait_for_java_debugger)):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment