Changeset 249139 in webkit


Ignore:
Timestamp:
Aug 27, 2019 5:31:51 AM (5 years ago)
Author:
clopez@igalia.com
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):

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r249125 r249139  
     12019-08-27  Carlos Alberto Lopez Perez  <clopez@igalia.com>
     2
     3        W3C test importer should be able to handle expected references with an absolute path.
     4        https://bugs.webkit.org/show_bug.cgi?id=200717
     5
     6        Reviewed by Youenn Fablet.
     7
     8        This patch implements the logic to resolve test references with absolute paths
     9        when importing w3c tests (like web-platform-tests).
     10        When an absolute path is found for a test reference, the parser now
     11        tries to find the right file by looking for a relative path inside
     12        the root directory of the source test repository.
     13        It works when the tool is run in download-mode as well as when the
     14        tool is run to import the tests from a local directory.
     15
     16        This fixes the import of test references for tests like
     17        web-platform-tests/css/css-images/multiple-position-color-stop-linear-2.html
     18
     19        * Scripts/webkitpy/w3c/test_importer.py:
     20        (TestImporter._source_root_directory_for_path):
     21        (TestImporter.find_importable_tests):
     22        * Scripts/webkitpy/w3c/test_importer_unittest.py:
     23        (TestImporterTest.import_directory):
     24        (test_webkit_test_runner_options):
     25        (test_webkit_test_runner_import_reftests_with_absolute_paths_download):
     26        (test_webkit_test_runner_import_reftests_with_absolute_paths_from_source_dir):
     27        * Scripts/webkitpy/w3c/test_parser.py:
     28        (TestParser.__init__):
     29        (TestParser.analyze_test):
     30
    1312019-08-26  Wenson Hsieh  <wenson_hsieh@apple.com>
    232
  • trunk/Tools/Scripts/webkitpy/w3c/test_importer.py

    r246469 r249139  
    270270                self.filesystem.remove(path)
    271271
     272    def _source_root_directory_for_path(self, path):
     273        if not self._importing_downloaded_tests:
     274            return self.source_directory
     275        for test_repository in self.test_downloader().load_test_repositories(self.filesystem):
     276            source_directory = self.filesystem.join(self.source_directory, test_repository['name'])
     277            if path.startswith(source_directory):
     278                return source_directory
     279
    272280    def find_importable_tests(self, directory):
    273281        def should_keep_subdir(filesystem, path):
     
    279287            return not should_skip
    280288
     289        source_root_directory = self._source_root_directory_for_path(directory)
    281290        directories = self.filesystem.dirs_under(directory, should_keep_subdir)
    282291        for root in directories:
     
    303312                    continue
    304313
    305                 test_parser = TestParser(vars(self.options), filename=fullpath, host=self.host)
     314                test_parser = TestParser(vars(self.options), filename=fullpath, host=self.host, source_root_directory=source_root_directory)
    306315                test_info = test_parser.analyze_test()
    307316                if test_info is None:
  • trunk/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py

    r246434 r249139  
    127127        self.assertTrue(host.filesystem.getsize("/mock-checkout/LayoutTests/w3c/test1/__init__.py") > 0)
    128128
     129    def import_directory(self, args, files, test_paths):
     130        host = MockHost()
     131        host.executive = MockExecutive2()
     132        host.filesystem = MockFileSystem(files=files)
     133
     134        options, args = parse_args(args)
     135        importer = TestImporter(host, test_paths, options)
     136        importer.do_import()
     137        return host.filesystem
     138
    129139    def import_downloaded_tests(self, args, files):
    130140        # files are passed as parameter as we cannot clone/fetch/checkout a repo in mock system.
     
    347357        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])
    348358        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])
     359
     360    def test_webkit_test_runner_import_reftests_with_absolute_paths_download(self):
     361        FAKE_FILES = {
     362            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/t/test1.html': '<html><head><link rel=match href=/t/test1-ref.html></head></html>',
     363            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/t/test1-ref.html': '<html></html>',
     364            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/t/test2.html': '<html><head><link rel=match href=/some/directory/in/csswg-root/test2-ref.html></head></html>',
     365            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/some/directory/in/csswg-root/test2-ref.html': '<html></html>',
     366            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/css/css-images/test3.html': '<html><head><link rel=match href=/css/css-images/test3-ref.html></head></html>',
     367            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/css/css-images/test3-ref.html': '<html></html>',
     368            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/css/css-images/test4.html': '<html><head><link rel=match href=/some/directory/in/wpt-root/test4-ref.html></head></html>',
     369            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/some/directory/in/wpt-root/test4-ref.html': '<html></html>',
     370            '/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>',
     371            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/some/directory/in/wpt-root/test5-ref.html': '<html></html>',
     372        }
     373        FAKE_FILES.update(FAKE_REPOSITORY)
     374
     375        fs = self.import_downloaded_tests(['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES)
     376        # test1
     377        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/csswg-tests/t/test1.html'))
     378        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/csswg-tests/t/test1-ref.html'))
     379        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test1.html'))
     380        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test1-expected.html'))
     381        # test2
     382        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/csswg-tests/t/test2.html'))
     383        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/csswg-tests/some/directory/in/csswg-root/test2-ref.html'))
     384        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test2.html'))
     385        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test2-expected.html'))
     386        # test3
     387        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/css/css-images/test3.html'))
     388        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/css/css-images/test3-ref.html'))
     389        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test3.html'))
     390        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test3-expected.html'))
     391        # test4
     392        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/css/css-images/test4.html'))
     393        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/some/directory/in/wpt-root/test4-ref.html'))
     394        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test4.html'))
     395        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test4-expected.html'))
     396        # test5
     397        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/css/css-images/test5.html'))
     398        self.assertTrue(fs.exists('/mock-checkout/WebKitBuild/w3c-tests/to-be-imported/web-platform-tests/some/directory/in/wpt-root/test5-ref.html'))
     399        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test5.html'))
     400        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test5-expected.html'))
     401
     402    def test_webkit_test_runner_import_reftests_with_absolute_paths_from_source_dir(self):
     403        FAKE_FILES = {
     404            '/home/user/wpt/css/css-images/test1.html': '<html><head><link rel=match href=/css/css-images/test1-ref.html></head></html>',
     405            '/home/user/wpt/css/css-images/test1-ref.html': '<html></html>',
     406            '/home/user/wpt/css/css-images/test2.html': '<html><head><link rel=match href=/some/directory/in/wpt-root/test2-ref.html></head></html>',
     407            '/home/user/wpt/some/directory/in/wpt-root/test2-ref.html': '<html></html>',
     408            '/home/user/wpt/css/css-images/test3.html': '<html><head><link rel=match href="             /some/directory/in/wpt-root/test3-ref.html    "></head></html>',
     409            '/home/user/wpt/some/directory/in/wpt-root/test3-ref.html': '<html></html>',
     410        }
     411        FAKE_FILES.update(FAKE_REPOSITORY)
     412
     413        fs = self.import_directory(['-s', '/home/user/wpt', '-d', '/mock-checkout/LayoutTests/w3c/web-platform-tests'], FAKE_FILES, 'css/css-images')
     414        # test1
     415        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test1.html'))
     416        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test1-expected.html'))
     417        # test2
     418        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test2.html'))
     419        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test2-expected.html'))
     420        # test3
     421        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test3.html'))
     422        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/css-images/test3-expected.html'))
  • trunk/Tools/Scripts/webkitpy/w3c/test_parser.py

    r232506 r249139  
    4040class TestParser(object):
    4141
    42     def __init__(self, options, filename, host=Host()):
     42    def __init__(self, options, filename, host=Host(), source_root_directory=None):
    4343        self.options = options
    4444        self.filename = filename
    4545        self.host = host
    4646        self.filesystem = self.host.filesystem
     47        self.source_root_directory = source_root_directory
    4748
    4849        self.test_doc = None
     
    9091
    9192            try:
    92                 ref_file = self.filesystem.join(self.filesystem.dirname(self.filename), matches[0]['href'])
     93                href_match_file = matches[0]['href'].strip()
     94                if href_match_file.startswith('/'):
     95                    ref_file = self.filesystem.join(self.source_root_directory, href_match_file.lstrip('/'))
     96                else:
     97                    ref_file = self.filesystem.join(self.filesystem.dirname(self.filename), href_match_file)
    9398            except KeyError as e:
    9499                # FIXME: Figure out what to do w/ invalid test files.
Note: See TracChangeset for help on using the changeset viewer.