Bug 1368088 - Add flag to disable code coverage artifact uploading for linux64-ccov. r?jmaher draft
authorGreg Mierzwinski <gmierz2@outlook.com>
Thu, 25 May 2017 15:43:53 -0400
changeset 585204 0d32dfe458f608960cab6718aaa41a0536a064ca
parent 583913 cb321835e07108b6aa4c91b7fd5a1fee5ee0b68f
child 630669 09e4e3456690f2d70c8ef196be4763c6da62420a
push id61051
push userbmo:gmierz2@outlook.com
push dateFri, 26 May 2017 17:12:03 +0000
reviewersjmaher
bugs1368088
milestone55.0a1
Bug 1368088 - Add flag to disable code coverage artifact uploading for linux64-ccov. r?jmaher This flag can be used to allow gcov for c++ code coverage to run with '--code-coverage' but it prevents 'gcda' artifacts from being uploaded after the tests are done. The 'gcno' upload is allowed with another flag in the code-coverage config called 'MOZ_CODE_COVERAGE'. Removing it's definition will prevent the 'gcno' file from being uploaded. MozReview-Commit-ID: 1XkH0P4Bh5A
testing/mozharness/mozharness/mozilla/testing/codecoverage.py
--- a/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
+++ b/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
@@ -12,16 +12,22 @@ from mozharness.base.script import (
     PostScriptAction,
 )
 
 code_coverage_config_options = [
     [["--code-coverage"],
      {"action": "store_true",
       "dest": "code_coverage",
       "default": False,
+      "help": "Whether gcov c++ code coverage should be run."
+      }],
+    [["--disable-ccov-upload"],
+     {"action": "store_true",
+      "dest": "disable_ccov_upload",
+      "default": False,
       "help": "Whether test run should package and upload code coverage data."
       }],
 ]
 
 
 class CodeCoverageMixin(object):
     """
     Mixin for setting GCOV_PREFIX during test execution, packaging up
@@ -35,44 +41,53 @@ class CodeCoverageMixin(object):
             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',)
         except (AttributeError, KeyError, TypeError):
             return False
 
+    @property
+    def ccov_upload_disabled(self):
+        try:
+            if self.config.get('disable_ccov_upload'):
+                return True
+            return False
+        except (AttributeError, KeyError, TypeError):
+            return False
 
     @PreScriptAction('run-tests')
     def _set_gcov_prefix(self, action):
         if not self.code_coverage_enabled:
             return
         self.gcov_dir = tempfile.mkdtemp()
         os.environ['GCOV_PREFIX'] = self.gcov_dir
 
     @PostScriptAction('run-tests')
     def _package_coverage_data(self, action, success=None):
         if not self.code_coverage_enabled:
             return
         del os.environ['GCOV_PREFIX']
 
-        # 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:
-            # 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!")
+        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:
+                # 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!")
 
-        dirs = self.query_abs_dirs()
-        file_path = os.path.join(
-            dirs['abs_blob_upload_dir'], 'code-coverage-gcda.zip')
-        command = ['zip', '-r', file_path, '.']
-        self.run_command(command, cwd=rel_topsrcdir)
+            dirs = self.query_abs_dirs()
+            file_path = os.path.join(
+                dirs['abs_blob_upload_dir'], 'code-coverage-gcda.zip')
+            command = ['zip', '-r', file_path, '.']
+            self.run_command(command, cwd=rel_topsrcdir)
         shutil.rmtree(self.gcov_dir)