Changeset 245287 in webkit


Ignore:
Timestamp:
May 14, 2019 10:03:18 AM (5 years ago)
Author:
youenn@apple.com
Message:

Add support for webkit-test-runner options to WPT importer
https://bugs.webkit.org/show_bug.cgi?id=197826

Reviewed by Alex Christensen.

In case of overwriting an existing test, check if the existing test
contains a <!-- webkit-test-runner --> comment and insert it back if
needed in the new test.

For exporter, forbid creating a WPT PR if there are changes containing
the webkit-test-runner string.

  • Scripts/webkitpy/w3c/test_converter.py:

(convert_for_webkit):
(_W3CTestConverter.init):
(_W3CTestConverter.add_webkit_test_runner_options_if_needed):
(_W3CTestConverter.handle_starttag):
(_W3CTestConverter.handle_comment):
(_W3CTestConverter.handle_decl):
(_W3CTestConverter.handle_pi):

  • Scripts/webkitpy/w3c/test_exporter.py:

(WebPlatformTestExporter.write_git_patch_file):
(WebPlatformTestExporter.make_pull_request):

  • Scripts/webkitpy/w3c/test_importer.py:

(TestImporter.webkit_test_runner_options):
(TestImporter):
(TestImporter.add_webkit_test_runner_options_to_content):
(TestImporter.copy_html_file):
(TestImporter.write_html_template):
(TestImporter.write_html_files_for_templated_js_tests):
(TestImporter.import_tests):

  • Scripts/webkitpy/w3c/test_importer_unittest.py:

(test_manual_slow_test):
(test_webkit_test_runner_options):

Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r245282 r245287  
     12019-05-14  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support for webkit-test-runner options to WPT importer
     4        https://bugs.webkit.org/show_bug.cgi?id=197826
     5
     6        Reviewed by Alex Christensen.
     7
     8        In case of overwriting an existing test, check if the existing test
     9        contains a <!-- webkit-test-runner --> comment and insert it back if
     10        needed in the new test.
     11
     12        For exporter, forbid creating a WPT PR if there are changes containing
     13        the webkit-test-runner string.
     14
     15        * Scripts/webkitpy/w3c/test_converter.py:
     16        (convert_for_webkit):
     17        (_W3CTestConverter.__init__):
     18        (_W3CTestConverter.add_webkit_test_runner_options_if_needed):
     19        (_W3CTestConverter.handle_starttag):
     20        (_W3CTestConverter.handle_comment):
     21        (_W3CTestConverter.handle_decl):
     22        (_W3CTestConverter.handle_pi):
     23        * Scripts/webkitpy/w3c/test_exporter.py:
     24        (WebPlatformTestExporter.write_git_patch_file):
     25        (WebPlatformTestExporter.make_pull_request):
     26        * Scripts/webkitpy/w3c/test_importer.py:
     27        (TestImporter.webkit_test_runner_options):
     28        (TestImporter):
     29        (TestImporter.add_webkit_test_runner_options_to_content):
     30        (TestImporter.copy_html_file):
     31        (TestImporter.write_html_template):
     32        (TestImporter.write_html_files_for_templated_js_tests):
     33        (TestImporter.import_tests):
     34        * Scripts/webkitpy/w3c/test_importer_unittest.py:
     35        (test_manual_slow_test):
     36        (test_webkit_test_runner_options):
     37
    1382019-05-14  Aakash Jain  <aakash_jain@apple.com>
    239
  • trunk/Tools/Scripts/webkitpy/w3c/test_converter.py

    r209012 r245287  
    3939
    4040
    41 def convert_for_webkit(new_path, filename, reference_support_info, host=Host(), convert_test_harness_links=True):
     41def convert_for_webkit(new_path, filename, reference_support_info, host=Host(), convert_test_harness_links=True, webkit_test_runner_options=''):
    4242    """ Converts a file's |contents| so it will function correctly in its |new_path| in Webkit.
    4343
    4444    Returns the list of modified properties and the modified text if the file was modifed, None otherwise."""
    4545    contents = host.filesystem.read_binary_file(filename)
    46     converter = _W3CTestConverter(new_path, filename, reference_support_info, host, convert_test_harness_links)
     46    converter = _W3CTestConverter(new_path, filename, reference_support_info, host, convert_test_harness_links, webkit_test_runner_options)
    4747    if filename.endswith('.css'):
    4848        return converter.add_webkit_prefix_to_unprefixed_properties_and_values(contents)
     
    5454
    5555class _W3CTestConverter(HTMLParser):
    56     def __init__(self, new_path, filename, reference_support_info, host=Host(), convert_test_harness_links=True):
     56    def __init__(self, new_path, filename, reference_support_info, host=Host(), convert_test_harness_links=True, webkit_test_runner_options=''):
    5757        HTMLParser.__init__(self)
    5858
     
    6868        self.filename = filename
    6969        self.reference_support_info = reference_support_info
     70        self.webkit_test_runner_options = webkit_test_runner_options
     71        self.has_started = False
    7072
    7173        resources_path = self.path_from_webkit_root('LayoutTests', 'resources')
     
    216218        self.converted_data.append(converted)
    217219
     220    def add_webkit_test_runner_options_if_needed(self):
     221        if self.has_started:
     222            return
     223        self.has_started = True
     224        if self.webkit_test_runner_options:
     225            self.converted_data[-1] = self.converted_data[-1] + self.webkit_test_runner_options
     226
    218227    def handle_starttag(self, tag, attrs):
    219228        if tag == 'style':
    220229            self.in_style_tag = True
    221230        self.convert_attributes_if_needed(tag, attrs)
     231        self.add_webkit_test_runner_options_if_needed()
    222232
    223233    def handle_endtag(self, tag):
     
    245255    def handle_comment(self, data):
    246256        self.converted_data.extend(['<!-- ', data, ' -->'])
     257        self.add_webkit_test_runner_options_if_needed()
    247258
    248259    def handle_decl(self, decl):
    249260        self.converted_data.extend(['<!', decl, '>'])
     261        self.add_webkit_test_runner_options_if_needed()
    250262
    251263    def handle_pi(self, data):
    252264        self.converted_data.extend(['<?', data, '>'])
     265        self.add_webkit_test_runner_options_if_needed()
  • trunk/Tools/Scripts/webkitpy/w3c/test_exporter.py

    r240438 r245287  
    183183        # FIXME: We can probably try to use --relative git parameter to not do that replacement.
    184184        patch_data = patch_data.replace(WEBKIT_WPT_DIR + '/', '')
     185
     186        # FIXME: Support stripping of <!-- webkit-test-runner --> comments.
     187        self.has_webkit_test_runner_specific_changes = 'webkit-test-runner' in patch_data
     188        if self.has_webkit_test_runner_specific_changes:
     189            _log.warning("Patch contains webkit-test-runner specific changes, please remove them before creating a PR")
     190            return ''
     191
    185192        self._filesystem.write_text_file(patch_file, patch_data)
    186193        return patch_file
     
    307314
    308315    def make_pull_request(self):
     316        if self.has_webkit_test_runner_specific_changes:
     317            _log.error('Cannot create a WPT PR since it contains webkit test runner specific changes')
     318            return
     319
    309320        if not self._github:
    310321            _log.info('Skipping pull request because OAuth token was not provided. You can open the pull request manually using the branch ' + self._wpt_fork_branch_github_url)
  • trunk/Tools/Scripts/webkitpy/w3c/test_importer.py

    r233624 r245287  
    361361        return self.options.convert_test_harness_links
    362362
     363    def _webkit_test_runner_options(self, path):
     364        if not(self.filesystem.isfile(path)):
     365            return ''
     366
     367        options_prefix = '<!-- webkit-test-runner'
     368        contents = self.filesystem.read_text_file(path).split('\n')
     369        if not len(contents):
     370            return ''
     371        first_line = contents[0]
     372
     373        return first_line[first_line.index(options_prefix):] if options_prefix in first_line else ''
     374
     375    def _add_webkit_test_runner_options_to_content(self, content, webkit_test_runner_options):
     376        lines = content.split('\n')
     377        if not len(lines):
     378            return ''
     379        lines[0] = lines[0] + webkit_test_runner_options
     380        return '\n'.join(lines)
     381
     382    def _copy_html_file(self, source_filepath, new_filepath):
     383        webkit_test_runner_options = self._webkit_test_runner_options(new_filepath)
     384        if not webkit_test_runner_options:
     385            self.filesystem.copyfile(source_filepath, new_filepath)
     386            return
     387
     388        source_content = self.filesystem.read_text_file(source_filepath)
     389        self.filesystem.write_text_file(new_filepath, self._add_webkit_test_runner_options_to_content(source_content, webkit_test_runner_options))
     390
     391    def _write_html_template(self, new_filepath):
     392        webkit_test_runner_options = self._webkit_test_runner_options(new_filepath)
     393        content = '<!-- This file is required for WebKit test infrastructure to run the templated test -->'
     394        self.filesystem.write_text_file(new_filepath, content + webkit_test_runner_options)
     395
    363396    def write_html_files_for_templated_js_tests(self, orig_filepath, new_filepath):
    364         content = '<!-- This file is required for WebKit test infrastructure to run the templated test -->'
    365397        if (orig_filepath.endswith('.window.js')):
    366             self.filesystem.write_text_file(new_filepath.replace('.window.js', '.window.html'), content)
     398            self._write_html_template(new_filepath.replace('.window.js', '.window.html'))
    367399            return
    368400        if (orig_filepath.endswith('.worker.js')):
    369             self.filesystem.write_text_file(new_filepath.replace('.worker.js', '.worker.html'), content)
     401            self._write_html_template(new_filepath.replace('.worker.js', '.worker.html'))
    370402            return
    371403        if (orig_filepath.endswith('.any.js')):
    372             self.filesystem.write_text_file(new_filepath.replace('.any.js', '.any.html'), content)
    373             self.filesystem.write_text_file(new_filepath.replace('.any.js', '.any.worker.html'), content)
     404            self._write_html_template(new_filepath.replace('.any.js', '.any.html'))
     405            self._write_html_template(new_filepath.replace('.any.js', '.any.worker.html'))
    374406            return
    375407
     
    450482                if should_rewrite_files and ('html' in str(mimetype[0]) or 'xml' in str(mimetype[0])  or 'css' in str(mimetype[0])):
    451483                    try:
    452                         converted_file = convert_for_webkit(new_path, filename=orig_filepath, reference_support_info=reference_support_info, host=self.host, convert_test_harness_links=self.should_convert_test_harness_links(subpath))
     484                        converted_file = convert_for_webkit(new_path, filename=orig_filepath, reference_support_info=reference_support_info, host=self.host, convert_test_harness_links=self.should_convert_test_harness_links(subpath), webkit_test_runner_options=self._webkit_test_runner_options(new_filepath))
    453485                    except:
    454486                        _log.warn('Failed converting %s', orig_filepath)
     
    475507                    # Some bots dislike empty __init__.py.
    476508                    self.write_init_py(new_filepath)
     509                elif 'html' in str(mimetype[0]):
     510                    self._copy_html_file(orig_filepath, new_filepath)
    477511                else:
    478512                    self.filesystem.copyfile(orig_filepath, new_filepath)
  • trunk/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py

    r223281 r245287  
    305305        self.assertFalse(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/new-manual.html'))
    306306        self.assertEquals(tests_options, fs.read_text_file('/mock-checkout/LayoutTests/tests-options.json'))
     307
     308    def test_webkit_test_runner_options(self):
     309        FAKE_FILES = {
     310            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/t/test.html': '<!doctype html><script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>',
     311            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/css/test.html': '<!doctype html>\n<script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>',
     312            '/mock-checkout/LayoutTests/w3c/web-platform-tests/css/test.html': '<!-- doctype html --><!-- webkit-test-runner [ dummy ] -->',
     313            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/test.html': '<!doctype html><script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>',
     314            '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.html': '<!-- doctype html --><!-- webkit-test-runner [ dummy ] -->',
     315            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/test.any.js': 'test(() => {}, "empty")',
     316            '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.any.html': '<!-- This file is required for WebKit test infrastructure to run the templated test --><!-- webkit-test-runner [ dummy ] -->',
     317            '/mock-checkout/Source/WebCore/css/CSSProperties.json': '',
     318            '/mock-checkout/Source/WebCore/css/CSSValueKeywords.in': '',
     319        }
     320        FAKE_FILES.update(FAKE_REPOSITORY)
     321
     322        fs = self.import_downloaded_tests(['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES)
     323
     324        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/test.html'))
     325        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.html'))
     326        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.any.html'))
     327        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.any.worker.html'))
     328        self.assertTrue('<!-- webkit-test-runner [ dummy ] -->' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/web-platform-tests/css/test.html').split('\n')[0])
     329        self.assertTrue('<!-- webkit-test-runner [ dummy ] -->' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.html').split('\n')[0])
     330        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])
     331        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])
Note: See TracChangeset for help on using the changeset viewer.