initial import
[vuplus_webkit] / Tools / Scripts / webkitpy / layout_tests / port / dryrun.py
1 #!/usr/bin/env python
2 # Copyright (C) 2010 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
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
13 # distribution.
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.
17 #
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.
29
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.
33
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.
38
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).
43
44    This implementation also modifies the test expectations so that all
45    tests are either SKIPPED or expected to PASS."""
46
47 from __future__ import with_statement
48
49 import os
50 import sys
51 import time
52
53 from webkitpy.layout_tests.port import Driver, DriverOutput, factory
54
55
56 # FIXME: Why not inherit from Port?
57 class DryRunPort(object):
58     """DryRun implementation of the Port interface."""
59
60     def __init__(self, **kwargs):
61         pfx = 'dryrun-'
62         if 'port_name' in kwargs:
63             if kwargs['port_name'].startswith(pfx):
64                 kwargs['port_name'] = kwargs['port_name'][len(pfx):]
65             else:
66                 kwargs['port_name'] = None
67         self.__delegate = factory.get(**kwargs)
68
69     def __getattr__(self, name):
70         return getattr(self.__delegate, name)
71
72     def acquire_http_lock(self):
73         pass
74
75     def release_http_lock(self):
76         pass
77
78     def check_build(self, needs_http):
79         return True
80
81     def check_sys_deps(self, needs_http):
82         return True
83
84     def start_helper(self):
85         pass
86
87     def start_http_server(self):
88         pass
89
90     def start_websocket_server(self):
91         pass
92
93     def stop_helper(self):
94         pass
95
96     def stop_http_server(self):
97         pass
98
99     def stop_websocket_server(self):
100         pass
101
102     def create_driver(self, worker_number):
103         return DryrunDriver(self, worker_number)
104
105
106 class DryrunDriver(Driver):
107     """Dryrun implementation of the DumpRenderTree / Driver interface."""
108
109     def cmd_line(self):
110         return ['None']
111
112     def poll(self):
113         return None
114
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')):
121             text = 'test-text'
122             image = 'test-image'
123             checksum = 'test-checksum'
124             audio = None
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'
129             audio = None
130         else:
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='')
136
137     def start(self):
138         pass
139
140     def stop(self):
141         pass