Bug 1416008 - Support packaging code coverage files and running grcov on Windows. r=jmaher
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Fri, 10 Nov 2017 15:39:32 +0100
changeset 696791 a04bb99cdd474fa37ace46ecc67df9264dbefcb0
parent 696790 257e004c31f2d53ce760ba149c541a85bdf59d30
child 696800 fa1adc80866df83946da2991273861af06ebf98b
push id88784
push usercholler@mozilla.com
push dateSat, 11 Nov 2017 10:21:53 +0000
reviewersjmaher
bugs1416008
milestone58.0a1
Bug 1416008 - Support packaging code coverage files and running grcov on Windows. r=jmaher
testing/mozharness/mozharness/mozilla/testing/codecoverage.py
--- a/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
+++ b/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
@@ -48,17 +48,17 @@ class CodeCoverageMixin(object):
 
     @property
     def code_coverage_enabled(self):
         try:
             if self.config.get('code_coverage'):
                 return True
 
             # XXX workaround because bug 1110465 is hard
-            return self.buildbot_config['properties']['stage_platform'] in ('linux64-ccov',)
+            return 'ccov' in self.buildbot_config['properties']['stage_platform']
         except (AttributeError, KeyError, TypeError):
             return False
 
     @property
     def ccov_upload_disabled(self):
         try:
             if self.config.get('disable_ccov_upload'):
                 return True
@@ -68,17 +68,17 @@ class CodeCoverageMixin(object):
 
     @property
     def jsd_code_coverage_enabled(self):
         try:
             if self.config.get('jsd_code_coverage'):
                 return True
 
             # XXX workaround because bug 1110465 is hard
-            return self.buildbot_config['properties']['stage_platform'] in ('linux64-jsdcov',)
+            return 'jsdcov' in self.buildbot_config['properties']['stage_platform']
         except (AttributeError, KeyError, TypeError):
             return False
 
     @PreScriptAction('run-tests')
     def _set_gcov_prefix(self, action):
         if not self.code_coverage_enabled:
             return
         # Set the GCOV directory.
@@ -133,69 +133,79 @@ class CodeCoverageMixin(object):
                 if filename.startswith("jscov") and filename.endswith(".json"):
                     os.remove(os.path.join(jsdcov_dir, filename))
 
             self.info("Completed compression of JSDCov artifacts!")
             self.info("Path to JSDCov compressed artifacts: " + zipFile)
 
         if not self.code_coverage_enabled:
             return
+
         del os.environ['GCOV_PREFIX']
         del os.environ['JS_CODE_COVERAGE_OUTPUT_DIR']
 
         if not self.ccov_upload_disabled:
             # TODO This is fragile, find rel_topsrcdir properly somehow
             # We need to find the path relative to the gecko topsrcdir. Use
             # some known gecko directories as a test.
             canary_dirs = ['browser', 'docshell', 'dom', 'js', 'layout', 'toolkit', 'xpcom', 'xpfe']
             rel_topsrcdir = None
             for root, dirs, files in os.walk(self.gcov_dir):
                 # need to use 'any' in case no gcda data was generated in that subdir.
                 if any(d in dirs for d in canary_dirs):
                     rel_topsrcdir = root
                     break
-            else:
+
+            if rel_topsrcdir is None:
                 # Unable to upload code coverage files. Since this is the whole
                 # point of code coverage, making this fatal.
-                self.fatal("Could not find relative topsrcdir in code coverage "
-                           "data!")
+                self.fatal("Could not find relative topsrcdir in code coverage data!")
+
+            dirs = self.query_abs_dirs()
 
             # Package GCOV coverage data.
-            dirs = self.query_abs_dirs()
-            file_path_gcda = os.path.join(
-                dirs['abs_blob_upload_dir'], 'code-coverage-gcda.zip')
-            command = ['zip', '-r', file_path_gcda, '.']
-            self.run_command(command, cwd=rel_topsrcdir)
+            file_path_gcda = os.path.join(dirs['abs_blob_upload_dir'], 'code-coverage-gcda.zip')
+            self.run_command(['zip', '-r', file_path_gcda, '.'], cwd=rel_topsrcdir)
 
             # Package JSVM coverage data.
-            dirs = self.query_abs_dirs()
-            file_path_jsvm = os.path.join(
-                dirs['abs_blob_upload_dir'], 'code-coverage-jsvm.zip')
-            command = ['zip', '-r', file_path_jsvm, '.']
-            self.run_command(command, cwd=self.jsvm_dir)
+            file_path_jsvm = os.path.join(dirs['abs_blob_upload_dir'], 'code-coverage-jsvm.zip')
+            self.run_command(['zip', '-r', file_path_jsvm, '.'], cwd=self.jsvm_dir)
 
             # GRCOV post-processing
             # Download the gcno fom the build machine.
             self.download_file(self.url_to_gcno, file_name=None, parent_dir=self.grcov_dir)
 
+            if mozinfo.os == 'linux':
+                prefix = '/builds/worker/workspace/build/src/'
+            elif mozinfo.os == 'win':
+                prefix = 'z:/build/build/src/'
+
             # Run grcov on the zipped .gcno and .gcda files.
             grcov_command = [
                 os.path.join(self.grcov_dir, 'grcov'),
                 '-t', 'lcov',
-                '-p', '/builds/worker/workspace/build/src/',
+                '-p', prefix,
                 '--ignore-dir', 'gcc',
                 os.path.join(self.grcov_dir, 'target.code-coverage-gcno.zip'), file_path_gcda
             ]
 
             # 'grcov_output' will be a tuple, the first variable is the path to the lcov output,
             # the other is the path to the standard error output.
-            grcov_output = self.get_output_from_command(grcov_command, cwd=self.grcov_dir, \
-                silent=True, tmpfile_base_path=os.path.join(self.grcov_dir, 'grcov_lcov_output'), \
-                save_tmpfiles=True, return_type='files')
+            grcov_output = self.get_output_from_command(
+                grcov_command,
+                cwd=self.grcov_dir,
+                silent=True,
+                tmpfile_base_path=os.path.join(self.grcov_dir, 'grcov_lcov_output'),
+                save_tmpfiles=True,
+                return_type='files'
+            )
             new_output_name = grcov_output[0] + '.info'
             os.rename(grcov_output[0], new_output_name)
 
             # Zip the grcov output and upload it.
-            command = ['zip', os.path.join(dirs['abs_blob_upload_dir'], 'code-coverage-grcov.zip'), new_output_name]
-            self.run_command(command, cwd=self.grcov_dir)
+            self.run_command(
+                ['zip', os.path.join(dirs['abs_blob_upload_dir'], 'code-coverage-grcov.zip'), new_output_name],
+                cwd=self.grcov_dir
+            )
+
         shutil.rmtree(self.gcov_dir)
         shutil.rmtree(self.jsvm_dir)
         shutil.rmtree(self.grcov_dir)