Bug 1475256 - Refactor CodeCoverageMixin to pass --java-coverage-output-dir instead of a file path. r=gbrown,marco

Differential Revision: https://phabricator.services.mozilla.com/D4142

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tudor-Gabriel Vîjială 2018-09-06 16:59:57 +00:00
Родитель 0f87b879ff
Коммит 48c6ba440f
3 изменённых файлов: 28 добавлений и 21 удалений

Просмотреть файл

@ -52,10 +52,14 @@ class JUnitTestRunner(MochitestDesktop):
update_mozinfo()
self.remote_profile = posixpath.join(self.device.test_root, 'junit-profile')
if self.options.coverage and not self.options.coverage_output_path:
raise Exception("--coverage-output-path is required when using --enable-coverage")
self.remote_coverage_output_path = posixpath.join(self.device.test_root,
if self.options.coverage and not self.options.coverage_output_dir:
raise Exception("--coverage-output-dir is required when using --enable-coverage")
if self.options.coverage:
self.remote_coverage_output_file = posixpath.join(self.device.test_root,
'junit-coverage.ec')
self.coverage_output_file = os.path.join(self.options.coverage_output_dir,
'junit-coverage.ec')
self.server_init()
self.cleanup()
@ -153,7 +157,7 @@ class JUnitTestRunner(MochitestDesktop):
# enable code coverage reports
if self.options.coverage:
cmd = cmd + " -e coverage true"
cmd = cmd + " -e coverageFile %s" % self.remote_coverage_output_path
cmd = cmd + " -e coverageFile %s" % self.remote_coverage_output_file
# environment
env = {}
env["MOZ_CRASHREPORTER"] = "1"
@ -273,12 +277,12 @@ class JUnitTestRunner(MochitestDesktop):
if self.options.coverage:
try:
self.device.pull(self.remote_coverage_output_path,
self.options.coverage_output_path)
self.device.pull(self.remote_coverage_output_file,
self.coverage_output_file)
except ADBError:
# Avoid a task retry in case the code coverage file is not found.
self.log.error("No code coverage file (%s) found on remote device" %
self.remote_coverage_output_path)
self.remote_coverage_output_file)
return -1
return 1 if self.fail_count else 0
@ -388,12 +392,12 @@ class JunitArgumentParser(argparse.ArgumentParser):
dest="coverage",
default=False,
help="Enable code coverage collection.")
self.add_argument("--coverage-output-path",
self.add_argument("--coverage-output-dir",
action="store",
type=str,
dest="coverage_output_path",
dest="coverage_output_dir",
default=None,
help="If collecting code coverage, save the report file to this path.")
help="If collecting code coverage, save the report file in this dir.")
# Additional options for server.
self.add_argument("--certificate-path",
action="store",

Просмотреть файл

@ -140,8 +140,7 @@ class CodeCoverageMixin(SingleTestMixin):
os.remove(classfiles_zip_path)
# Create the directory where the emulator coverage file will be placed.
self.java_coverage_output_path = os.path.join(tempfile.mkdtemp(),
'junit-coverage.ec')
self.java_coverage_output_dir = tempfile.mkdtemp()
@PostScriptAction('download-and-extract')
def setup_coverage_tools(self, action, success=None):
@ -503,16 +502,20 @@ class CodeCoverageMixin(SingleTestMixin):
return
# If the emulator became unresponsive, the task has failed and we don't
# have the coverage report file, so stop running this function and
# have any coverage report file, so stop running this function and
# allow the task to be retried automatically.
if not success and not os.path.exists(self.java_coverage_output_path):
if not success and not os.listdir(self.java_coverage_output_dir):
return
report_files = [os.path.join(self.java_coverage_output_dir, f)
for f in os.listdir(self.java_coverage_output_dir)]
assert len(report_files) > 0, "JaCoCo coverage data files were not found."
dirs = self.query_abs_dirs()
xml_path = tempfile.mkdtemp()
jacoco_command = ['java', '-jar', self.jacoco_jar, 'report',
self.java_coverage_output_path,
'--classfiles', self.classfiles_dir,
jacoco_command = ['java', '-jar', self.jacoco_jar, 'report'] + \
report_files + \
['--classfiles', self.classfiles_dir,
'--name', 'geckoview-junit',
'--xml', os.path.join(xml_path, 'geckoview-junit.xml')]
self.run_command(jacoco_command, halt_on_failure=True)

Просмотреть файл

@ -493,7 +493,7 @@ class AndroidEmulatorTest(TestingMixin, BaseScript, MozbaseMixin, CodeCoverageMi
if self.java_code_coverage_enabled:
cmd.extend(['--enable-coverage',
'--coverage-output-path', self.java_coverage_output_path])
'--coverage-output-dir', self.java_coverage_output_dir])
return cmd