Bug 1393788 - Compress all JSDcov artifacts (.json files) into zip files after all tests are completed. r?jmaher, r?gmierz. draft
authoralex <ateoh.dev@gmail.com>
Thu, 26 Oct 2017 17:01:12 -0400
changeset 690126 70e658104dc129f382d54d41674c61f131d0232b
parent 687040 7290c8fce8a1f5c4bce930d951eaf1d6326bd788
child 738500 b6b70b39e6c9b1a941a1af99a9517e0218c577fb
push id87223
push userbmo:ateoh.dev@gmail.com
push dateWed, 01 Nov 2017 17:47:52 +0000
reviewersjmaher, gmierz
bugs1393788
milestone58.0a1
Bug 1393788 - Compress all JSDcov artifacts (.json files) into zip files after all tests are completed. r?jmaher, r?gmierz. Building with "Linux x64 JSDCov", each suite of tests will produce a list of JSDCov artifacts (.json). This patch compresses all JSDCov artifacts into 1 zip file for each suite upon tests completion. MozReview-Commit-ID: DaNLOQuW2lc
taskcluster/taskgraph/transforms/tests.py
testing/mozharness/mozharness/mozilla/testing/codecoverage.py
--- a/taskcluster/taskgraph/transforms/tests.py
+++ b/taskcluster/taskgraph/transforms/tests.py
@@ -675,16 +675,17 @@ def enable_code_coverage(config, tests):
                 test['mozharness']['extra-options'].append('--add-option')
                 test['mozharness']['extra-options'].append('--tppagecycles,1')
                 test['mozharness']['extra-options'].append('--add-option')
                 test['mozharness']['extra-options'].append('--no-upload-results')
                 test['mozharness']['extra-options'].append('--add-option')
                 test['mozharness']['extra-options'].append('--tptimeout,15000')
         elif test['build-platform'] == 'linux64-jsdcov/opt':
             test['run-on-projects'] = ['mozilla-central']
+            test['mozharness'].setdefault('extra-options', []).append('--jsd-code-coverage')
         yield test
 
 
 @transforms.add
 def handle_run_on_projects(config, tests):
     """Handle translating `built-projects` appropriately"""
     for test in tests:
         if test['run-on-projects'] == 'built-projects':
--- a/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
+++ b/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
@@ -21,16 +21,22 @@ code_coverage_config_options = [
       "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."
       }],
+    [["--jsd-code-coverage"],
+     {"action": "store_true",
+      "dest": "jsd_code_coverage",
+      "default": False,
+      "help": "Whether JSDebugger code coverage should be run."
+      }],
 ]
 
 
 class CodeCoverageMixin(object):
     """
     Mixin for setting GCOV_PREFIX during test execution, packaging up
     the resulting .gcda files and uploading them to blobber.
     """
@@ -52,16 +58,27 @@ class CodeCoverageMixin(object):
     def ccov_upload_disabled(self):
         try:
             if self.config.get('disable_ccov_upload'):
                 return True
             return False
         except (AttributeError, KeyError, TypeError):
             return False
 
+    @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',)
+        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.
         self.gcov_dir = tempfile.mkdtemp()
         os.environ['GCOV_PREFIX'] = self.gcov_dir
 
@@ -84,16 +101,34 @@ class CodeCoverageMixin(object):
         cmd = [tooltool_path, '--url', 'https://tooltool.mozilla-releng.net/', 'fetch', \
             '-m', manifest, '-o', '-c', '/builds/worker/tooltool-cache']
         self.run_command(cmd, cwd=self.grcov_dir)
         self.run_command(['tar', '-jxvf', os.path.join(self.grcov_dir, 'grcov-linux-standalone-x86_64.tar.bz2'), \
             '-C', self.grcov_dir], cwd=self.grcov_dir)
 
     @PostScriptAction('run-tests')
     def _package_coverage_data(self, action, success=None):
+        if self.jsd_code_coverage_enabled:
+            # Setup the command for compression
+            dirs = self.query_abs_dirs()
+            jsdcov_dir = dirs['abs_blob_upload_dir']
+            zipFile = os.path.join(jsdcov_dir, "jsdcov_artifacts.zip")
+            command = ["zip", "-r", zipFile, ".", "-i", "jscov*.json"]
+
+            self.info("Beginning compression of JSDCov artifacts...")
+            self.run_command(command, cwd=jsdcov_dir)
+
+            # Delete already compressed JSCov artifacts.
+            for filename in os.listdir(jsdcov_dir):
+                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