|
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 os |
| 37 |
import sys |
| 38 |
|
| 39 |
from webkitpy.common.host import Host |
| 40 |
from webkitpy.common.system.executive import Executive |
| 41 |
from webkitpy.layout_tests.models.test_expectations import TestExpectations |
| 42 |
from webkitpy.port import platform_options |
| 43 |
from webkitpy.w3c.factory import w3c_create_argument_parser |
| 44 |
from webkitpy.w3c.test_results_manager import TestResultsManager |
| 45 |
from webkitpy.w3c.web_platform_test_setup import WebPlatformTestSetup |
| 46 |
from webkitpy.w3c.web_platform_test_importer import WebPlatformTestImporter |
| 47 |
|
| 48 |
_log = logging.getLogger(__name__) |
| 49 |
|
| 50 |
|
| 51 |
class W3CConformanceRunner(object): |
| 52 |
|
| 53 |
def __init__(self, port, options): |
| 54 |
self.port = port |
| 55 |
self.filesystem = port.host.filesystem |
| 56 |
self.options = options |
| 57 |
self.web_platform_test_importer = WebPlatformTestImporter(port, options) |
| 58 |
self.tests = None |
| 59 |
self._results_manager = None |
| 60 |
|
| 61 |
def get_conformance_results_directory(self): |
| 62 |
return self.filesystem.join(self.port.results_directory(), "..", "w3c-conformance-results") |
| 63 |
|
| 64 |
def layout_tests_result_directory(self): |
| 65 |
return self.filesystem.join(self.get_conformance_results_directory(), "layout-test-results") |
| 66 |
|
| 67 |
def test_suites(self): |
| 68 |
return self.web_platform_test_importer.test_suites() |
| 69 |
|
| 70 |
def run_test_suites(self, parameters): |
| 71 |
#TODO: clean this to have a better path computation |
| 72 |
up = os.path.dirname |
| 73 |
script_dir = up(up(up(os.path.abspath(__file__)))) |
| 74 |
tmp_args = [self.filesystem.join(script_dir, 'run-webkit-tests')] + parameters + ['--results-directory=' + self.layout_tests_result_directory()] |
| 75 |
tmp_args.append('--' + self.options.platform) |
| 76 |
if self.options.webkit_test_runner is True: |
| 77 |
tmp_args.append('-2') |
| 78 |
|
| 79 |
#compute list of tests to run |
| 80 |
for test_suite in self.test_suites(): |
| 81 |
path = self.filesystem.join('LayoutTests', self.options.__dict__['importdir'], test_suite) |
| 82 |
tmp_args.append(path) |
| 83 |
Executive().run_command(tmp_args, error_handler=Executive.ignore_error, return_stderr=(not self.options.__dict__['w3c_verbose']), decode_output=False) |
| 84 |
self._results_manager = TestResultsManager(self.port, self.options.platform, self.options.__dict__['importdir'], self.layout_tests_result_directory(), self.tests) |
| 85 |
|
| 86 |
def run_tests_to_generate_test_baseline(self): |
| 87 |
self.run_test_suites(['-q', '--no-retry-failures', '--no-show-results', '--skipped=ignore']) |
| 88 |
|
| 89 |
def remove_test_expected_files(self): |
| 90 |
for test in self.tests: |
| 91 |
filename = self.port.expected_filename(test, '.txt', False) |
| 92 |
if not(filename is None): |
| 93 |
file_path = self.filesystem.join(self.port.layout_tests_dir(), filename) |
| 94 |
self.filesystem.remove(file_path) |
| 95 |
|
| 96 |
def results_manager(self): |
| 97 |
return self._results_manager |
| 98 |
|
| 99 |
def run_tests(self): |
| 100 |
if self.options.__dict__['w3c_list'] is True: |
| 101 |
return False |
| 102 |
|
| 103 |
# import tests |
| 104 |
_log.info('Importing tests...') |
| 105 |
self.web_platform_test_importer.import_tests() |
| 106 |
self.tests = self.web_platform_test_importer.tests() |
| 107 |
|
| 108 |
# setup the necessary configuration files |
| 109 |
wpt_setup = WebPlatformTestSetup(self.port.host, self.options) |
| 110 |
wpt_setup.copy_webkit_testharnessreport() |
| 111 |
wpt_setup.copy_wpt_json_config() |
| 112 |
|
| 113 |
self.remove_test_expected_files() |
| 114 |
|
| 115 |
_log.info('Running tests...') |
| 116 |
self.run_tests_to_generate_test_baseline() |
| 117 |
|
| 118 |
# generate conformance results |
| 119 |
self.filesystem.maybe_make_directory(self.get_conformance_results_directory()) |
| 120 |
self.results_manager().write_conformance_results(self.get_conformance_results_directory()) |
| 121 |
|
| 122 |
return True |
| 123 |
|
| 124 |
def print_results_to_console(self): |
| 125 |
summary = self.results_manager().summary() |
| 126 |
_log.info('Run ' + str(summary['total']) + ' tests') |
| 127 |
_log.info('Pass: ' + str(summary['num_pass'])) |
| 128 |
_log.info('Partial: ' + str(summary['num_partial'])) |
| 129 |
_log.info('Fail: ' + str(summary['num_fail'])) |
| 130 |
_log.info('Error: ' + str(summary['num_error'])) |
| 131 |
|
| 132 |
def print_potential_test_expectations_update(self): |
| 133 |
test_expectations = TestExpectations(self.port).model() |
| 134 |
conformance = self.results_manager().conformance_results() |
| 135 |
# TODO: Finalize this check to get meaningful information |
| 136 |
for test in self.tests: |
| 137 |
if not test_expectations.has_test(test): |
| 138 |
if not conformance[test] == 'PASS': |
| 139 |
_log.info('test ' + test + ' is not passing') |
| 140 |
elif conformance[test] == 'PASS': |
| 141 |
_log.info('test ' + test + ' is now passing') |
| 142 |
|
| 143 |
|
| 144 |
def configure_logging(): |
| 145 |
class LogHandler(logging.StreamHandler): |
| 146 |
def format(self, record): |
| 147 |
if record.levelno > logging.INFO: |
| 148 |
return "%s: %s" % (record.levelname, record.getMessage()) |
| 149 |
return record.getMessage() |
| 150 |
|
| 151 |
logger = logging.getLogger() |
| 152 |
logger.setLevel(logging.INFO) |
| 153 |
handler = LogHandler() |
| 154 |
handler.setLevel(logging.INFO) |
| 155 |
logger.addHandler(handler) |
| 156 |
return handler |
| 157 |
|
| 158 |
|
| 159 |
def main(argv, stdout, stderr): |
| 160 |
configure_logging() |
| 161 |
host = Host() |
| 162 |
parser = w3c_create_argument_parser(host, host.filesystem.basename(__file__)) |
| 163 |
options, args = parser.parse_known_args(argv) |
| 164 |
port = host.port_factory.get(options.platform, optparse.Values({'webkit_test_runner': options.webkit_test_runner})) |
| 165 |
|
| 166 |
runner = W3CConformanceRunner(port, options) |
| 167 |
if runner.run_tests(): |
| 168 |
runner.print_results_to_console() |
| 169 |
runner.print_potential_test_expectations_update() |
| 170 |
runner.remove_test_expected_files() |
| 171 |
_log.info("Results exported in '" + runner.get_conformance_results_directory() + "'") |
| 172 |
|
| 173 |
if '__main__' == __name__: |
| 174 |
sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr)) |