2 # Copyright (C) 2010 Google Inc. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
14 # * Neither the Google name nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 """This is a test implementation of the Port interface that generates the
31 correct output for every test. It can be used for perf testing, because
32 it is pretty much a lower limit on how fast a port can possibly run.
34 This implementation acts as a wrapper around a real port (the real port
35 is held as a delegate object). To specify which port, use the port name
36 'dryrun-XXX' (e.g., 'dryrun-chromium-cg-mac-leopard'). If you use just
37 'dryrun', it uses the default port.
39 Note that because this is really acting as a wrapper around the underlying
40 port, you must be able to run the underlying port as well
41 (check_build() and check_sys_deps() must pass and auxiliary binaries
42 like layout_test_helper and httpd must work).
44 This implementation also modifies the test expectations so that all
45 tests are either SKIPPED or expected to PASS."""
47 from __future__ import with_statement
53 from webkitpy.layout_tests.port import Driver, DriverOutput, factory
56 # FIXME: Why not inherit from Port?
57 class DryRunPort(object):
58 """DryRun implementation of the Port interface."""
60 def __init__(self, **kwargs):
62 if 'port_name' in kwargs:
63 if kwargs['port_name'].startswith(pfx):
64 kwargs['port_name'] = kwargs['port_name'][len(pfx):]
66 kwargs['port_name'] = None
67 self.__delegate = factory.get(**kwargs)
69 def __getattr__(self, name):
70 return getattr(self.__delegate, name)
72 def acquire_http_lock(self):
75 def release_http_lock(self):
78 def check_build(self, needs_http):
81 def check_sys_deps(self, needs_http):
84 def start_helper(self):
87 def start_http_server(self):
90 def start_websocket_server(self):
93 def stop_helper(self):
96 def stop_http_server(self):
99 def stop_websocket_server(self):
102 def create_driver(self, worker_number):
103 return DryrunDriver(self, worker_number)
106 class DryrunDriver(Driver):
107 """Dryrun implementation of the DumpRenderTree / Driver interface."""
115 def run_test(self, driver_input):
116 start_time = time.time()
117 fs = self._port._filesystem
118 if (fs.exists(self._port.reftest_expected_filename(driver_input.test_name)) or
119 fs.exists(self._port.reftest_expected_mismatch_filename(driver_input.test_name)) or
120 driver_input.test_name.endswith('-expected.html')):
123 checksum = 'test-checksum'
125 elif driver_input.test_name.endswith('-expected-mismatch.html'):
126 text = 'test-text-mismatch'
127 image = 'test-image-mismatch'
128 checksum = 'test-checksum-mismatch'
131 text = self._port.expected_text(driver_input.test_name)
132 image = self._port.expected_image(driver_input.test_name)
133 checksum = self._port.expected_checksum(driver_input.test_name)
134 audio = self._port.expected_audio(driver_input.test_name)
135 return DriverOutput(text, image, checksum, audio, crash=False, test_time=time.time() - start_time, timeout=False, error='')