initial import
[vuplus_webkit] / Tools / Scripts / webkitpy / tool / commands / rebaselineserver.py
1 # Copyright (c) 2010 Google 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 are
5 # met:
6 #
7 #     * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #     * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #     * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 """Starts a local HTTP server which displays layout test failures (given a test
30 results directory), provides comparisons of expected and actual results (both
31 images and text) and allows one-click rebaselining of tests."""
32
33 import os
34 import os.path
35
36 from webkitpy.common import system
37 from webkitpy.common.net.resultsjsonparser import for_each_test, JSONTestResult
38 from webkitpy.layout_tests.layout_package import json_results_generator
39 from webkitpy.layout_tests.port import factory
40 from webkitpy.tool.commands.abstractlocalservercommand import AbstractLocalServerCommand
41 from webkitpy.tool.servers.rebaselineserver import get_test_baselines, RebaselineHTTPServer, STATE_NEEDS_REBASELINE
42
43
44 class TestConfig(object):
45     def __init__(self, test_port, layout_tests_directory, results_directory, platforms, filesystem, scm):
46         self.test_port = test_port
47         self.layout_tests_directory = layout_tests_directory
48         self.results_directory = results_directory
49         self.platforms = platforms
50         self.filesystem = filesystem
51         self.scm = scm
52
53
54 class RebaselineServer(AbstractLocalServerCommand):
55     name = "rebaseline-server"
56     help_text = __doc__
57     argument_names = "/path/to/results/directory"
58
59     server = RebaselineHTTPServer
60
61     def _gather_baselines(self, results_json):
62         # Rebaseline server and it's associated JavaScript expected the tests subtree to
63         # be key-value pairs instead of hierarchical.
64         # FIXME: make the rebaseline server use the hierarchical tree.
65         new_tests_subtree = {}
66
67         def gather_baselines_for_test(test_name, result_dict):
68             result = JSONTestResult(test_name, result_dict)
69             if result.did_pass_or_run_as_expected():
70                 return
71             result_dict['state'] = STATE_NEEDS_REBASELINE
72             result_dict['baselines'] = get_test_baselines(test_name, self._test_config)
73             new_tests_subtree[test_name] = result_dict
74
75         for_each_test(results_json['tests'], gather_baselines_for_test)
76         results_json['tests'] = new_tests_subtree
77
78     def _prepare_config(self, options, args, tool):
79         results_directory = args[0]
80         filesystem = system.filesystem.FileSystem()
81         scm = self._tool.scm()
82
83         print 'Parsing full_results.json...'
84         results_json_path = filesystem.join(results_directory, 'full_results.json')
85         results_json = json_results_generator.load_json(filesystem, results_json_path)
86
87         port = factory.get()
88         layout_tests_directory = port.layout_tests_dir()
89         platforms = filesystem.listdir(filesystem.join(layout_tests_directory, 'platform'))
90         self._test_config = TestConfig(port, layout_tests_directory, results_directory, platforms, filesystem, scm)
91
92         print 'Gathering current baselines...'
93         self._gather_baselines(results_json)
94
95         return {
96             'test_config': self._test_config,
97             "results_json": results_json,
98             "platforms_json": {
99                 'platforms': platforms,
100                 'defaultPlatform': port.name(),
101             },
102         }