Bug 1480120 - Cleanup reftest, jsreftest and wpt file paths in per-test coverage data. r=marco,gbrown draft
authorTudor-Gabriel Vîjială <tvijiala@mozilla.com>
Thu, 02 Aug 2018 17:39:21 +0100
changeset 827555 859de657e9036473798996f1d38dbb85d230f379
parent 827540 17116905bc072c37d74226ccc46c93f0bd45d516
push id118550
push userbmo:tvijiala@mozilla.com
push dateWed, 08 Aug 2018 15:15:01 +0000
reviewersmarco, gbrown
bugs1480120
milestone63.0a1
Bug 1480120 - Cleanup reftest, jsreftest and wpt file paths in per-test coverage data. r=marco,gbrown MozReview-Commit-ID: KJtYSk18L2W
testing/mozharness/mozharness/mozilla/testing/codecoverage.py
testing/mozharness/mozharness/mozilla/testing/per_test_base.py
--- a/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
+++ b/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
@@ -1,15 +1,16 @@
 #!/usr/bin/env python
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import json
 import os
+import posixpath
 import shutil
 import sys
 import tarfile
 import tempfile
 import zipfile
 import uuid
 
 import mozinfo
@@ -353,16 +354,24 @@ class CodeCoverageMixin(SingleTestMixin)
         grcov_file = self.parse_coverage_artifacts(
             gcov_dir, self.jsvm_dir, merge=True, output_format='coveralls',
             filter_covered=True,
         )
 
         report_file = str(uuid.uuid4()) + '.json'
         shutil.move(grcov_file, report_file)
 
+        # Get the test path relative to topsrcdir.
+        # This mapping is constructed by self.find_modified_tests().
+        test = self.test_src_path.get(test.replace(os.sep, posixpath.sep), test)
+
+        # Log a warning if the test path is still an absolute path.
+        if os.path.isabs(test):
+            self.warn("Found absolute path for test: {}".format(test))
+
         if suite not in self.per_test_reports:
             self.per_test_reports[suite] = {}
         assert test not in self.per_test_reports[suite]
         self.per_test_reports[suite][test] = report_file
 
         if 'GCOV_RESULTS_DIR' in env:
             # In this case, parse_coverage_artifacts has removed GCOV_RESULTS_DIR
             # so we need to remove GCOV_PREFIX.
--- a/testing/mozharness/mozharness/mozilla/testing/per_test_base.py
+++ b/testing/mozharness/mozharness/mozilla/testing/per_test_base.py
@@ -17,16 +17,24 @@ from manifestparser import TestManifest
 class SingleTestMixin(object):
     """Utility functions for per-test testing like test verification and per-test coverage."""
 
     def __init__(self):
         self.suites = {}
         self.tests_downloaded = False
         self.reftest_test_dir = None
         self.jsreftest_test_dir = None
+        # Map from full test path on the test machine to a relative path in the source checkout.
+        # Use self._map_test_path_to_source(test_machine_path, source_path) to add a mapping.
+        self.test_src_path = {}
+
+    def _map_test_path_to_source(self, test_machine_path, source_path):
+        test_machine_path = test_machine_path.replace(os.sep, posixpath.sep)
+        source_path = source_path.replace(os.sep, posixpath.sep)
+        self.test_src_path[test_machine_path] = source_path
 
     def _is_gpu_suite(self, suite):
         if suite and (suite == 'gpu' or suite.startswith('webgl')):
             return True
         return False
 
     def _find_misc_tests(self, dirs, changed_files, gpu=False):
         manifests = [
@@ -61,36 +69,39 @@ class SingleTestMixin(object):
         ]
         sys.path.append(dirs['abs_reftest_dir'])
         import manifest
         self.reftest_test_dir = os.path.join(dirs['abs_reftest_dir'], 'tests')
         for (path, suite, subsuite) in ref_manifests:
             if os.path.exists(path):
                 man = manifest.ReftestManifest()
                 man.load(path)
-                tests_by_path.update({
-                    os.path.relpath(t, self.reftest_test_dir): (suite, subsuite) for t in man.files
-                })
+                for t in man.files:
+                    relpath = os.path.relpath(t, self.reftest_test_dir)
+                    tests_by_path[relpath] = (suite, subsuite)
+                    self._map_test_path_to_source(t, relpath)
                 self.info("Per-test run updated with manifest %s" % path)
 
         suite = 'jsreftest'
         self.jsreftest_test_dir = os.path.join(dirs['abs_test_install_dir'], 'jsreftest', 'tests')
         path = os.path.join(self.jsreftest_test_dir, 'jstests.list')
         if os.path.exists(path):
             man = manifest.ReftestManifest()
             man.load(path)
             for t in man.files:
                 # expect manifest test to look like:
                 #    ".../tests/jsreftest/tests/jsreftest.html?test=test262/.../some_test.js"
                 # while the test is in mercurial at:
                 #    js/src/tests/test262/.../some_test.js
                 epos = t.find('=')
                 if epos > 0:
                     relpath = t[epos+1:]
+                    test_path = os.path.join(self.jsreftest_test_dir, relpath)
                     relpath = os.path.join('js', 'src', 'tests', relpath)
+                    self._map_test_path_to_source(test_path, relpath)
                     tests_by_path.update({relpath: (suite, None)})
                 else:
                     self.warning("unexpected jsreftest test format: %s" % str(t))
             self.info("Per-test run updated with manifest %s" % path)
 
         # for each changed file, determine if it is a test file, and what suite it is in
         for file in changed_files:
             # manifest paths use os.sep (like backslash on Windows) but
@@ -158,19 +169,20 @@ class SingleTestMixin(object):
             # manifest paths use os.sep (like backslash on Windows) but
             # automation-relevance uses posixpath.sep
             repo_path = repo_path.replace(os.sep, posixpath.sep)
             if repo_path in changed_files:
                 self.info("found web-platform test file '%s', type %s" % (path, type))
                 suite_files = self.suites.get(type)
                 if not suite_files:
                     suite_files = []
-                path = os.path.join(tests_path, path)
-                suite_files.append(path)
+                test_path = os.path.join(tests_path, path)
+                suite_files.append(test_path)
                 self.suites[type] = suite_files
+                self._map_test_path_to_source(test_path, repo_path)
 
     def find_modified_tests(self):
         """
            For each file modified on this push, determine if the modified file
            is a test, by searching test manifests. Populate self.suites
            with test files, organized by suite.
 
            This depends on test manifests, so can only run after test zips have