|
Line 0
a/Tools/Scripts/webkitpy/w3c/conformance_checker.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 |
| 29 |
- generating expected.txt files (using run-webkit-tests) |
| 30 |
- computing whether a js 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 |
import webkitpy.w3c.test_importer as test_importer |
| 43 |
from webkitpy.w3c.test_results_manager import TestResultsManager |
| 44 |
from webkitpy.w3c.test_downloader import TestDownloader |
| 45 |
|
| 46 |
_log = logging.getLogger(__name__) |
| 47 |
|
| 48 |
|
| 49 |
def create_argument_parser(): |
| 50 |
parser = argparse.ArgumentParser() |
| 51 |
|
| 52 |
for opt in platform_options(use_globs=False): |
| 53 |
parser.add_argument(opt.get_opt_string(), action=opt.action, dest=opt.dest, const=getattr(opt, 'const'), help=getattr(opt, 'help')) |
| 54 |
parser.add_argument('--webkit-test-runner', '-2', action='store_true', default=False, |
| 55 |
help='Set WebKit architecture WebKit1 or WebKit2 (default WK1).') |
| 56 |
|
| 57 |
parser.add_argument('-q', dest='quiet', action='store_true', default=False, |
| 58 |
help='Print minimal log.') |
| 59 |
parser.add_argument('-v', dest='verbose', action='store_true', default=False, |
| 60 |
help='Print maximal log.') |
| 61 |
parser.add_argument('-t', '--test-path', action='append', dest='test_paths', default=[], |
| 62 |
help='Import and run only tests in the supplied subdirectory of the w3c_test_directory. Can be supplied multiple times to give multiple paths') |
| 63 |
parser.add_argument('-s', '--skip-refresh', action='store_false', default=True, dest='refresh', |
| 64 |
help='Disable refresh of tests (git checkout + import). By default, tests are refreshed.') |
| 65 |
parser.add_argument('--no-fetch', action='store_false', dest='fetch', default=True, |
| 66 |
help='Do not fetch the CSS/WPT repositories. By default, repositories are fetched if a W3c test directory is not provided') |
| 67 |
|
| 68 |
return parser |
| 69 |
|
| 70 |
|
| 71 |
class ConformanceChecker(object): |
| 72 |
|
| 73 |
def __init__(self, port, options): |
| 74 |
self._port = port |
| 75 |
self._filesystem = port.host.filesystem |
| 76 |
self._options = options |
| 77 |
self._results_manager = None |
| 78 |
self._tests = None |
| 79 |
self._conformance_results = None |
| 80 |
|
| 81 |
self.layout_w3c_directory = self._filesystem.join('imported', 'w3c') |
| 82 |
self.results_directory = self._port.w3c_conformance_results_directory() |
| 83 |
self.layout_tests_result_directory = self._filesystem.join(self.results_directory, 'layout-test-results') |
| 84 |
self.imported_tests_directory = self._filesystem.join(self.results_directory, 'imported-tests') |
| 85 |
self.runned_tests_directory = self._filesystem.join(self.results_directory, 'runned-tests') |
| 86 |
|
| 87 |
self.init_test_importer() |
| 88 |
|
| 89 |
def _print_rwt_output_line(self, line): |
| 90 |
if not self._options.verbose: |
| 91 |
if line.startswith('['): |
| 92 |
tokens = line.split(' ') |
| 93 |
sys.stdout.write('\r' + tokens[0] + ' ' + tokens[1].replace(self.runned_tests_directory, '')[1:] + ' ') |
| 94 |
sys.stdout.flush() |
| 95 |
elif line == '': |
| 96 |
sys.stdout.write('\n') |
| 97 |
else: |
| 98 |
sys.stdout.write(line) |
| 99 |
|
| 100 |
def run_tests(self, tests): |
| 101 |
run_webkit_args = [self._port.path_to_script('run-webkit-tests'), '--no-retry-failures', '--no-show-results', '--full-results-html'] |
| 102 |
|
| 103 |
test_list_filename = self._filesystem.join(self.runned_tests_directory, 'test_list.txt') |
| 104 |
self._filesystem.write_text_file(test_list_filename, '\n'.join(tests)) |
| 105 |
run_webkit_args.append('--test-list=' + test_list_filename) |
| 106 |
|
| 107 |
if self._filesystem.exists(self.layout_tests_result_directory): |
| 108 |
self._filesystem.rmtree(self.layout_tests_result_directory) |
| 109 |
run_webkit_args.append('--results-directory=' + self.layout_tests_result_directory) |
| 110 |
|
| 111 |
run_webkit_args.append('--wptserver-doc-root=' + self._filesystem.join(self.runned_tests_directory, TestDownloader.WPT_NAME)) |
| 112 |
|
| 113 |
if self._options.platform: |
| 114 |
run_webkit_args.append('--' + self._options.platform) |
| 115 |
if self._options.webkit_test_runner is True: |
| 116 |
run_webkit_args.append('-2') |
| 117 |
|
| 118 |
if not self._options.verbose: |
| 119 |
run_webkit_args.append('-q') |
| 120 |
|
| 121 |
process = Executive().popen(run_webkit_args, stdout=Executive.PIPE, stderr=Executive.STDOUT) |
| 122 |
while True: |
| 123 |
line = process.stdout.readline() |
| 124 |
self._print_rwt_output_line(line) |
| 125 |
if line == '': |
| 126 |
break |
| 127 |
process.wait() |
| 128 |
|
| 129 |
def results_manager(self): |
| 130 |
return self._results_manager |
| 131 |
|
| 132 |
def init_test_importer(self): |
| 133 |
args = ['-d', self.imported_tests_directory, '--ignore-expectations'] |
| 134 |
|
| 135 |
for test_path in self._options.test_paths: |
| 136 |
args.append('-t') |
| 137 |
args.append(test_path) |
| 138 |
|
| 139 |
if not self._options.fetch: |
| 140 |
args.append('--no-fetch') |
| 141 |
|
| 142 |
if self._options.verbose: |
| 143 |
args.append('-v') |
| 144 |
elif self._options.quiet: |
| 145 |
logging.getLogger('webkitpy.w3c.test_importer').setLevel(logging.WARN) |
| 146 |
logging.getLogger('webkitpy.w3c.test_converter').setLevel(logging.WARN) |
| 147 |
logging.getLogger('webkitpy.w3c.test_downloader').setLevel(logging.WARN) |
| 148 |
|
| 149 |
options, args = test_importer.parse_args(args) |
| 150 |
self.test_importer = test_importer.TestImporter(self._port.host, None, options) |
| 151 |
|
| 152 |
def test_suites(self): |
| 153 |
return self._options.test_paths if self._options.test_paths else self.test_importer.test_downloader().all_test_paths() |
| 154 |
|
| 155 |
def tests(self): |
| 156 |
test_suites = self.test_suites() |
| 157 |
if self._tests is None: |
| 158 |
test_suite_paths = [self._filesystem.join(self.runned_tests_directory, test_suite) for test_suite in test_suites] |
| 159 |
self._tests = self._port.tests(test_suite_paths) |
| 160 |
return self._tests |
| 161 |
|
| 162 |
def conformance_result(self, test): |
| 163 |
if self._conformance_results is None: |
| 164 |
self._conformance_results = self.results_manager().conformance_results() |
| 165 |
return self._conformance_results[self.results_manager().w3c_test_name(test)] |
| 166 |
|
| 167 |
def check_conformance(self): |
| 168 |
if self._options.refresh is True: |
| 169 |
_log.info('Importing tests...') |
| 170 |
self.test_importer.do_import() |
| 171 |
else: |
| 172 |
_log.info('Skipping test import...') |
| 173 |
|
| 174 |
# Regenerate runned_test_directory to start in a clean state (no -expected.txt files in particular). |
| 175 |
self._filesystem.rmtree(self.runned_tests_directory) |
| 176 |
self._filesystem.copytree(self.imported_tests_directory, self.runned_tests_directory) |
| 177 |
|
| 178 |
_log.info('Running tests...') |
| 179 |
self.run_tests(self.tests()) |
| 180 |
|
| 181 |
_log.info('Parsing test results...') |
| 182 |
self._results_manager = TestResultsManager(self._port, self.runned_tests_directory, self.layout_tests_result_directory, self.tests()) |
| 183 |
self._results_manager.process_test_results() |
| 184 |
|
| 185 |
_log.info('Generating conformance results...') |
| 186 |
self._filesystem.maybe_make_directory(self.results_directory) |
| 187 |
self.write_conformance_results() |
| 188 |
|
| 189 |
_log.info('Generating expectation updates...') |
| 190 |
self.write_test_expectation_updates(self.results_directory) |
| 191 |
self.write_import_expectation_updates(self.results_directory) |
| 192 |
|
| 193 |
return True |
| 194 |
|
| 195 |
def print_results_to_console(self): |
| 196 |
summary = self.results_manager().summary() |
| 197 |
_log.info('Run ' + str(summary['total']) + ' tests') |
| 198 |
_log.info('Pass: ' + str(summary['num_pass'])) |
| 199 |
_log.info('Partial: ' + str(summary['num_partial'])) |
| 200 |
_log.info('Fail: ' + str(summary['num_fail'])) |
| 201 |
_log.info('Error: ' + str(summary['num_error'])) |
| 202 |
|
| 203 |
def write_import_expectation_updates(self, directory_path): |
| 204 |
import_expectations = [] |
| 205 |
for test_suite in self.test_suites(): |
| 206 |
import_expectations.append('# %s [ Pass ]' % self._filesystem.join(self.layout_w3c_directory, test_suite)) |
| 207 |
|
| 208 |
import_expectations.append('') |
| 209 |
|
| 210 |
for test in self.tests(): |
| 211 |
if not self.conformance_result(test) == 'PASS': |
| 212 |
import_expectations.append('%s [ Skip ]' % self._filesystem.join(self.layout_w3c_directory, self.results_manager().w3c_test_name(test))) |
| 213 |
|
| 214 |
self._filesystem.write_text_file(self._filesystem.join(directory_path, 'ImportExpectations'), '\n'.join(import_expectations)) |
| 215 |
|
| 216 |
def write_test_expectation_updates(self, directory_path): |
| 217 |
test_expectations = ['# W3C test infrastructure folders'] |
| 218 |
for path in self.test_importer.test_downloader().infrastructure_paths: |
| 219 |
file_path = self._filesystem.join(self.runned_tests_directory, path) |
| 220 |
if (self._filesystem.isdir(file_path)): |
| 221 |
test_expectations.append('%s [ Skip ]' % self._filesystem.join(self.layout_w3c_directory, path)) |
| 222 |
self._filesystem.write_text_file(self._filesystem.join(directory_path, 'TestExpectations'), '\n'.join(test_expectations)) |
| 223 |
|
| 224 |
def write_conformance_results(self): |
| 225 |
test_run_info = {} |
| 226 |
test_run_info['port_name'] = self._port.port_name |
| 227 |
test_run_info['web_platform_tests_version'] = self.test_importer.test_downloader().tests_version('WPT') |
| 228 |
test_run_info['csswg_tests_version'] = self.test_importer.test_downloader().tests_version('CSS') |
| 229 |
test_run_info['results_directory'] = self._filesystem.relpath(self.layout_tests_result_directory, self.results_directory) |
| 230 |
test_run_info['tests_directory'] = self._filesystem.relpath(self.runned_tests_directory, self.results_directory) |
| 231 |
self.results_manager().write_conformance_results(self.results_directory, test_run_info) |
| 232 |
|
| 233 |
|
| 234 |
def configure_logging(): |
| 235 |
class LogHandler(logging.StreamHandler): |
| 236 |
def format(self, record): |
| 237 |
if record.levelno > logging.INFO: |
| 238 |
return "%s: %s" % (record.levelname, record.getMessage()) |
| 239 |
return record.getMessage() |
| 240 |
|
| 241 |
logger = logging.getLogger() |
| 242 |
logger.setLevel(logging.INFO) |
| 243 |
handler = LogHandler() |
| 244 |
handler.setLevel(logging.INFO) |
| 245 |
logger.addHandler(handler) |
| 246 |
return handler |
| 247 |
|
| 248 |
|
| 249 |
def main(argv, stdout, stderr): |
| 250 |
configure_logging() |
| 251 |
host = Host() |
| 252 |
parser = create_argument_parser() |
| 253 |
options, args = parser.parse_known_args(argv) |
| 254 |
port = host.port_factory.get(options.platform, optparse.Values({'webkit_test_runner': options.webkit_test_runner})) |
| 255 |
|
| 256 |
runner = ConformanceChecker(port, options) |
| 257 |
if runner.check_conformance(): |
| 258 |
runner.print_results_to_console() |
| 259 |
_log.info("Results exported in '" + runner.results_directory + "'") |
| 260 |
|
| 261 |
if '__main__' == __name__: |
| 262 |
sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr)) |