|
Line 0
a/Tools/Scripts/webkitpy/w3c/run_w3c_conformance_tests.py_sec1
|
|
|
1 |
# Copyright (c) 2014, Canon Inc. All rights reserved. |
| 2 |
# |
| 3 |
# Redistribution and use in source and binary forms, with or without |
| 4 |
# modification, are permitted provided that the following conditions |
| 5 |
# are met: |
| 6 |
# 1. Redistributions of source code must retain the above copyright |
| 7 |
# notice, this list of conditions and the following disclaimer. |
| 8 |
# 2. Redistributions in binary form must reproduce the above copyright |
| 9 |
# notice, this list of conditions and the following disclaimer in the |
| 10 |
# documentation and/or other materials provided with the distribution. |
| 11 |
# 3. Neither the name of Canon Inc. nor the names of |
| 12 |
# its contributors may be used to endorse or promote products derived |
| 13 |
# from this software without specific prior written permission. |
| 14 |
# |
| 15 |
# THIS SOFTWARE IS PROVIDED BY CANON INC. AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 16 |
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 |
# DISCLAIMED. IN NO EVENT SHALL CANON INC. AND ITS CONTRIBUTORS BE LIABLE FOR |
| 19 |
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 20 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 21 |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 22 |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 23 |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 |
|
| 26 |
""" |
| 27 |
This script evaluates W3C tests conformance by: |
| 28 |
- importing W3C tests as WebKit tests (using web_platform_test_importer) |
| 29 |
- generating expected.txt files (using run-webkit-tests) |
| 30 |
- computing whether a test is passing or not by checking PASS/FAIL assertions outputted within the expected.txt files |
| 31 |
""" |
| 32 |
|
| 33 |
import argparse |
| 34 |
import logging |
| 35 |
import optparse |
| 36 |
import sys |
| 37 |
|
| 38 |
from webkitpy.common.host import Host |
| 39 |
from webkitpy.common.system.executive import Executive |
| 40 |
from webkitpy.layout_tests.models.test_expectations import TestExpectations |
| 41 |
from webkitpy.port import platform_options |
| 42 |
from webkitpy.w3c.factory import w3c_create_argument_parser |
| 43 |
from webkitpy.w3c.test_results_manager import TestResultsManager |
| 44 |
from webkitpy.w3c.web_platform_test_setup import WebPlatformTestSetup |
| 45 |
from webkitpy.w3c.web_platform_test_importer import WebPlatformTestImporter |
| 46 |
|
| 47 |
_log = logging.getLogger(__name__) |
| 48 |
|
| 49 |
|
| 50 |
class W3CConformanceRunner(object): |
| 51 |
|
| 52 |
def __init__(self, port, options): |
| 53 |
self._port = port |
| 54 |
self._filesystem = port.host.filesystem |
| 55 |
self._options = options |
| 56 |
self._results_manager = None |
| 57 |
self._tests = None |
| 58 |
self._conformance_results = None |
| 59 |
|
| 60 |
self.web_platform_test_importer = WebPlatformTestImporter(port, options) |
| 61 |
self.imported_tests_directory = self.web_platform_test_importer.imported_tests_directory |
| 62 |
self.runned_tests_directory = self._filesystem.join(port.w3c_conformance_results_directory(), "runned-tests") |
| 63 |
|
| 64 |
def conformance_results_directory(self): |
| 65 |
return self._port.w3c_conformance_results_directory() |
| 66 |
|
| 67 |
def layout_tests_result_directory(self): |
| 68 |
return self._filesystem.join(self.conformance_results_directory(), "layout-test-results") |
| 69 |
|
| 70 |
def test_suites(self): |
| 71 |
return self.web_platform_test_importer.test_suites() |
| 72 |
|
| 73 |
def run_webkit_tests(self, parameters): |
| 74 |
tmp_args = [self._port.path_to_script('run-webkit-tests')] + parameters |
| 75 |
if self._options.platform: |
| 76 |
tmp_args.append('--' + self._options.platform) |
| 77 |
if self._options.webkit_test_runner is True: |
| 78 |
tmp_args.append('-2') |
| 79 |
Executive().run_command(tmp_args, error_handler=Executive.ignore_error, return_stderr=(self._options.__dict__['w3c_quiet']), decode_output=False) |
| 80 |
|
| 81 |
def run_test_list(self, tests): |
| 82 |
test_list_filename = self._filesystem.join(self.runned_tests_directory, 'test_list.txt') |
| 83 |
with open(test_list_filename, 'w+') as out: |
| 84 |
for test in tests: |
| 85 |
out.write(test + '\n') |
| 86 |
out.close() |
| 87 |
|
| 88 |
run_webkit_args = ['-q', '--no-retry-failures', '--no-show-results', '--full-results-html', '--results-directory=' + self.layout_tests_result_directory(), '--wptserver-doc-root=' + self.runned_tests_directory, '--test-list=' + test_list_filename] |
| 89 |
|
| 90 |
self.run_webkit_tests(run_webkit_args) |
| 91 |
self._results_manager = TestResultsManager(self._port, self.runned_tests_directory, self.layout_tests_result_directory(), self.tests()) |
| 92 |
return self._results_manager.process_test_results() |
| 93 |
|
| 94 |
def results_manager(self): |
| 95 |
return self._results_manager |
| 96 |
|
| 97 |
def tests(self): |
| 98 |
if self._tests is None: |
| 99 |
test_suite_paths = [self._filesystem.join(self.runned_tests_directory, test_suite) for test_suite in self.test_suites()] |
| 100 |
self._tests = self._port.tests(test_suite_paths) |
| 101 |
return self._tests |
| 102 |
|
| 103 |
def conformance_result(self, test): |
| 104 |
if self._conformance_results is None: |
| 105 |
self._conformance_results = self.results_manager().compute_conformance_results() |
| 106 |
return self._conformance_results[self.results_manager().w3c_test_name(test)] |
| 107 |
|
| 108 |
def run_tests(self): |
| 109 |
if self._options.__dict__['w3c_list'] is True: |
| 110 |
return False |
| 111 |
|
| 112 |
if self._options.__dict__['w3c_refresh'] is True: |
| 113 |
_log.info('Importing tests...') |
| 114 |
self.web_platform_test_importer.import_tests() |
| 115 |
else: |
| 116 |
_log.info('Skipping test import...') |
| 117 |
|
| 118 |
_log.info('Setting up configuration files...') |
| 119 |
wpt_setup = WebPlatformTestSetup(self._port.host, self.imported_tests_directory) |
| 120 |
wpt_setup.copy_webkit_testharnessreport() |
| 121 |
wpt_setup.copy_wpt_json_config() |
| 122 |
|
| 123 |
_log.info('Copying imported_tests_directory as runned_test_directory') |
| 124 |
# A different directory, runned_test_directory, is used to run tests so that imported_tests_directory remains clean. |
| 125 |
# runned_test_directory is also recreated each time to start in a clean state. |
| 126 |
self._filesystem.rmtree(self.runned_tests_directory) |
| 127 |
self._filesystem.copytree(self.imported_tests_directory, self.runned_tests_directory) |
| 128 |
|
| 129 |
_log.info('Running tests...') |
| 130 |
self.run_test_list(self.tests()) |
| 131 |
|
| 132 |
_log.info('Generating conformance results...') |
| 133 |
self._filesystem.maybe_make_directory(self.conformance_results_directory()) |
| 134 |
self.write_conformance_results() |
| 135 |
|
| 136 |
return True |
| 137 |
|
| 138 |
def print_results_to_console(self): |
| 139 |
summary = self.results_manager().summary() |
| 140 |
_log.info('Run ' + str(summary['total']) + ' tests') |
| 141 |
_log.info('Pass: ' + str(summary['num_pass'])) |
| 142 |
_log.info('Partial: ' + str(summary['num_partial'])) |
| 143 |
_log.info('Fail: ' + str(summary['num_fail'])) |
| 144 |
_log.info('Error: ' + str(summary['num_error'])) |
| 145 |
|
| 146 |
def print_potential_test_expectations_update(self): |
| 147 |
test_expectations = TestExpectations(self._port).model() |
| 148 |
conformance = self.results_manager().compute_conformance_results() |
| 149 |
for test in self.tests(): |
| 150 |
w3c_test_name = self.results_manager().w3c_test_name(test) |
| 151 |
wk_test_name = self._filesystem.join('imported', 'w3c', 'wpt', w3c_test_name) |
| 152 |
if not test_expectations.has_test(wk_test_name): |
| 153 |
if not conformance[w3c_test_name] == 'PASS': |
| 154 |
_log.info('test ' + wk_test_name + ' is not passing') |
| 155 |
elif conformance[w3c_test_name] == 'PASS': |
| 156 |
_log.info('test ' + wk_test_name + ' is passing') |
| 157 |
|
| 158 |
def write_conformance_results(self): |
| 159 |
test_run_info = {} |
| 160 |
test_run_info['port_name'] = self._port.port_name |
| 161 |
test_run_info['tests_version'] = self.web_platform_test_importer.wptsha() |
| 162 |
test_run_info['results_directory'] = self._filesystem.relpath(self.layout_tests_result_directory(), self.conformance_results_directory()) |
| 163 |
test_run_info['tests_directory'] = self._filesystem.relpath(self.runned_tests_directory, self.conformance_results_directory()) |
| 164 |
self.results_manager().write_conformance_results(self.conformance_results_directory(), test_run_info) |
| 165 |
|
| 166 |
|
| 167 |
def configure_logging(): |
| 168 |
class LogHandler(logging.StreamHandler): |
| 169 |
def format(self, record): |
| 170 |
if record.levelno > logging.INFO: |
| 171 |
return "%s: %s" % (record.levelname, record.getMessage()) |
| 172 |
return record.getMessage() |
| 173 |
|
| 174 |
logger = logging.getLogger() |
| 175 |
logger.setLevel(logging.INFO) |
| 176 |
handler = LogHandler() |
| 177 |
handler.setLevel(logging.INFO) |
| 178 |
logger.addHandler(handler) |
| 179 |
return handler |
| 180 |
|
| 181 |
|
| 182 |
def main(argv, stdout, stderr): |
| 183 |
configure_logging() |
| 184 |
host = Host() |
| 185 |
parser = w3c_create_argument_parser(host, host.filesystem.basename(__file__)) |
| 186 |
options, args = parser.parse_known_args(argv) |
| 187 |
port = host.port_factory.get(options.platform, optparse.Values({'webkit_test_runner': options.webkit_test_runner})) |
| 188 |
|
| 189 |
runner = W3CConformanceRunner(port, options) |
| 190 |
if runner.run_tests(): |
| 191 |
runner.print_results_to_console() |
| 192 |
runner.print_potential_test_expectations_update() |
| 193 |
_log.info("Results exported in '" + runner.conformance_results_directory() + "'") |
| 194 |
|
| 195 |
if '__main__' == __name__: |
| 196 |
sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr)) |