Title: [249139] trunk/Tools
Revision
249139
Author
[email protected]
Date
2019-08-27 05:31:51 -0700 (Tue, 27 Aug 2019)

Log Message

W3C test importer should be able to handle expected references with an absolute path.
https://bugs.webkit.org/show_bug.cgi?id=200717

Reviewed by Youenn Fablet.

This patch implements the logic to resolve test references with absolute paths
when importing w3c tests (like web-platform-tests).
When an absolute path is found for a test reference, the parser now
tries to find the right file by looking for a relative path inside
the root directory of the source test repository.
It works when the tool is run in download-mode as well as when the
tool is run to import the tests from a local directory.

This fixes the import of test references for tests like
web-platform-tests/css/css-images/multiple-position-color-stop-linear-2.html

* Scripts/webkitpy/w3c/test_importer.py:
(TestImporter._source_root_directory_for_path):
(TestImporter.find_importable_tests):
* Scripts/webkitpy/w3c/test_importer_unittest.py:
(TestImporterTest.import_directory):
(test_webkit_test_runner_options):
(test_webkit_test_runner_import_reftests_with_absolute_paths_download):
(test_webkit_test_runner_import_reftests_with_absolute_paths_from_source_dir):
* Scripts/webkitpy/w3c/test_parser.py:
(TestParser.__init__):
(TestParser.analyze_test):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (249138 => 249139)


--- trunk/Tools/ChangeLog	2019-08-27 11:05:22 UTC (rev 249138)
+++ trunk/Tools/ChangeLog	2019-08-27 12:31:51 UTC (rev 249139)
@@ -1,3 +1,33 @@
+2019-08-27  Carlos Alberto Lopez Perez  <[email protected]>
+
+        W3C test importer should be able to handle expected references with an absolute path.
+        https://bugs.webkit.org/show_bug.cgi?id=200717
+
+        Reviewed by Youenn Fablet.
+
+        This patch implements the logic to resolve test references with absolute paths
+        when importing w3c tests (like web-platform-tests).
+        When an absolute path is found for a test reference, the parser now
+        tries to find the right file by looking for a relative path inside
+        the root directory of the source test repository.
+        It works when the tool is run in download-mode as well as when the
+        tool is run to import the tests from a local directory.
+
+        This fixes the import of test references for tests like
+        web-platform-tests/css/css-images/multiple-position-color-stop-linear-2.html
+
+        * Scripts/webkitpy/w3c/test_importer.py:
+        (TestImporter._source_root_directory_for_path):
+        (TestImporter.find_importable_tests):
+        * Scripts/webkitpy/w3c/test_importer_unittest.py:
+        (TestImporterTest.import_directory):
+        (test_webkit_test_runner_options):
+        (test_webkit_test_runner_import_reftests_with_absolute_paths_download):
+        (test_webkit_test_runner_import_reftests_with_absolute_paths_from_source_dir):
+        * Scripts/webkitpy/w3c/test_parser.py:
+        (TestParser.__init__):
+        (TestParser.analyze_test):
+
 2019-08-26  Wenson Hsieh  <[email protected]>
 
         Remove UIHelper.activateElementAtHumanSpeed

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_importer.py (249138 => 249139)


--- trunk/Tools/Scripts/webkitpy/w3c/test_importer.py	2019-08-27 11:05:22 UTC (rev 249138)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_importer.py	2019-08-27 12:31:51 UTC (rev 249139)
@@ -269,6 +269,14 @@
             if self.filesystem.glob(path.replace('-expected.txt', '*')) == [path]:
                 self.filesystem.remove(path)
 
+    def _source_root_directory_for_path(self, path):
+        if not self._importing_downloaded_tests:
+            return self.source_directory
+        for test_repository in self.test_downloader().load_test_repositories(self.filesystem):
+            source_directory = self.filesystem.join(self.source_directory, test_repository['name'])
+            if path.startswith(source_directory):
+                return source_directory
+
     def find_importable_tests(self, directory):
         def should_keep_subdir(filesystem, path):
             if self._importing_downloaded_tests:
@@ -278,6 +286,7 @@
             should_skip = filesystem.basename(subdir).startswith('.') or (subdir in DIRS_TO_SKIP)
             return not should_skip
 
+        source_root_directory = self._source_root_directory_for_path(directory)
         directories = self.filesystem.dirs_under(directory, should_keep_subdir)
         for root in directories:
             _log.info('Scanning ' + root + '...')
@@ -302,7 +311,7 @@
                     copy_list.append({'src': fullpath, 'dest': filename})
                     continue
 
-                test_parser = TestParser(vars(self.options), filename=fullpath, host=self.host)
+                test_parser = TestParser(vars(self.options), filename=fullpath, host=self.host, source_root_directory=source_root_directory)
                 test_info = test_parser.analyze_test()
                 if test_info is None:
                     # This is probably a resource file, but we should generate WPT manifest instead and get the list of resource files from it.

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py (249138 => 249139)


--- trunk/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py	2019-08-27 11:05:22 UTC (rev 249138)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py	2019-08-27 12:31:51 UTC (rev 249139)
@@ -126,6 +126,16 @@
         self.assertTrue(host.filesystem.exists("/mock-checkout/LayoutTests/w3c/test2/__init__.py"))
         self.assertTrue(host.filesystem.getsize("/mock-checkout/LayoutTests/w3c/test1/__init__.py") > 0)
 
+    def import_directory(self, args, files, test_paths):
+        host = MockHost()
+        host.executive = MockExecutive2()
+        host.filesystem = MockFileSystem(files=files)
+
+        options, args = parse_args(args)
+        importer = TestImporter(host, test_paths, options)
+        importer.do_import()
+        return host.filesystem
+
     def import_downloaded_tests(self, args, files):
         # files are passed as parameter as we cannot clone/fetch/checkout a repo in mock system.
 
@@ -346,3 +356,67 @@
         self.assertTrue('<!-- webkit-test-runner [ dummy ] -->' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.html').split('\n')[0])
         self.assertTrue('<!-- webkit-test-runner [ dummy ] -->' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.any.html').split('\n')[0])
         self.assertFalse('<!-- webkit-test-runner [ dummy ] -->' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.any.worker.html').split('\n')[0])
+
+    def test_webkit_test_runner_import_reftests_with_absolute_paths_download(self):
+        FAKE_FILES = {
+            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/t/test1.html': '<html><head><link rel=match href=""
+            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/t/test1-ref.html': '<html></html>',
+            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/t/test2.html': '<html><head><link rel=match href=""
+            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/some/directory/in/csswg-root/test2-ref.html': '<html></html>',
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/css/css-images/test3.html': '<html><head><link rel=match href=""
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/css/css-images/test3-ref.html': '<html></html>',
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/css/css-images/test4.html': '<html><head><link rel=match href=""
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/some/directory/in/wpt-root/test4-ref.html': '<html></html>',
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/css/css-images/test5.html': '<html><head><link rel=match href=""     /some/directory/in/wpt-root/test5-ref.html    "></head></html>',
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/some/directory/in/wpt-root/test5-ref.html': '<html></html>',
+        }
+        FAKE_FILES.update(FAKE_REPOSITORY)
+
+        fs = self.import_downloaded_tests(['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES)
+        # test1
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/csswg-tests/t/test1.html'))
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/csswg-tests/t/test1-ref.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test1.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test1-expected.html'))
+        # test2
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/csswg-tests/t/test2.html'))
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/csswg-tests/some/directory/in/csswg-root/test2-ref.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test2.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test2-expected.html'))
+        # test3
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/css/css-images/test3.html'))
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/css/css-images/test3-ref.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test3.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test3-expected.html'))
+        # test4
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/css/css-images/test4.html'))
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/some/directory/in/wpt-root/test4-ref.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test4.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test4-expected.html'))
+        # test5
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/css/css-images/test5.html'))
+        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/some/directory/in/wpt-root/test5-ref.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test5.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test5-expected.html'))
+
+    def test_webkit_test_runner_import_reftests_with_absolute_paths_from_source_dir(self):
+        FAKE_FILES = {
+            '/home/user/wpt/css/css-images/test1.html': '<html><head><link rel=match href=""
+            '/home/user/wpt/css/css-images/test1-ref.html': '<html></html>',
+            '/home/user/wpt/css/css-images/test2.html': '<html><head><link rel=match href=""
+            '/home/user/wpt/some/directory/in/wpt-root/test2-ref.html': '<html></html>',
+            '/home/user/wpt/css/css-images/test3.html': '<html><head><link rel=match href=""             /some/directory/in/wpt-root/test3-ref.html    "></head></html>',
+            '/home/user/wpt/some/directory/in/wpt-root/test3-ref.html': '<html></html>',
+        }
+        FAKE_FILES.update(FAKE_REPOSITORY)
+
+        fs = self.import_directory(['-s', '/home/user/wpt', '-d', '/mock-checkout/LayoutTests/w3c/web-platform-tests'], FAKE_FILES, 'css/css-images')
+        # test1
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test1.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test1-expected.html'))
+        # test2
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test2.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test2-expected.html'))
+        # test3
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test3.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test3-expected.html'))

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_parser.py (249138 => 249139)


--- trunk/Tools/Scripts/webkitpy/w3c/test_parser.py	2019-08-27 11:05:22 UTC (rev 249138)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_parser.py	2019-08-27 12:31:51 UTC (rev 249139)
@@ -39,11 +39,12 @@
 
 class TestParser(object):
 
-    def __init__(self, options, filename, host=Host()):
+    def __init__(self, options, filename, host=Host(), source_root_directory=None):
         self.options = options
         self.filename = filename
         self.host = host
         self.filesystem = self.host.filesystem
+        self.source_root_directory = source_root_directory
 
         self.test_doc = None
         self.ref_doc = None
@@ -89,7 +90,11 @@
                              self.filesystem.basename(self.filename))
 
             try:
-                ref_file = self.filesystem.join(self.filesystem.dirname(self.filename), matches[0]['href'])
+                href_match_file = matches[0]['href'].strip()
+                if href_match_file.startswith('/'):
+                    ref_file = self.filesystem.join(self.source_root_directory, href_match_file.lstrip('/'))
+                else:
+                    ref_file = self.filesystem.join(self.filesystem.dirname(self.filename), href_match_file)
             except KeyError as e:
                 # FIXME: Figure out what to do w/ invalid test files.
                 _log.error('%s has a reference link but is missing the "href"', self.filesystem)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to