blob: b0f4a6b7235db7aacfcc04e3a14fd19a0a88e650 [file] [log] [blame]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001# 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
Ben Murdoch7757ec22013-07-23 11:17:36 +010029import webkitpy.thirdparty.unittest2 as unittest
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000030
31from webkitpy.common.system.systemhost_mock import MockSystemHost
32
33from webkitpy.layout_tests.port import Port, Driver, DriverOutput
34from webkitpy.layout_tests.port.server_process_mock import MockServerProcess
35
36# FIXME: remove the dependency on TestWebKitPort
37from webkitpy.layout_tests.port.port_testcase import TestWebKitPort
38
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000039from webkitpy.tool.mocktool import MockOptions
40
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000041
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000042class DriverTest(unittest.TestCase):
43 def make_port(self):
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000044 port = Port(MockSystemHost(), 'test', MockOptions(configuration='Release'))
45 port._config.build_directory = lambda configuration: '/mock-build'
46 return port
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000047
48 def _assert_wrapper(self, wrapper_string, expected_wrapper):
49 wrapper = Driver(self.make_port(), None, pixel_tests=False)._command_wrapper(wrapper_string)
50 self.assertEqual(wrapper, expected_wrapper)
51
52 def test_command_wrapper(self):
53 self._assert_wrapper(None, [])
54 self._assert_wrapper("valgrind", ["valgrind"])
55
56 # Validate that shlex works as expected.
57 command_with_spaces = "valgrind --smc-check=\"check with spaces!\" --foo"
58 expected_parse = ["valgrind", "--smc-check=check with spaces!", "--foo"]
59 self._assert_wrapper(command_with_spaces, expected_parse)
60
61 def test_test_to_uri(self):
62 port = self.make_port()
63 driver = Driver(port, None, pixel_tests=False)
64 self.assertEqual(driver.test_to_uri('foo/bar.html'), 'file://%s/foo/bar.html' % port.layout_tests_dir())
65 self.assertEqual(driver.test_to_uri('http/tests/foo.html'), 'http://127.0.0.1:8000/foo.html')
66 self.assertEqual(driver.test_to_uri('http/tests/ssl/bar.html'), 'https://127.0.0.1:8443/ssl/bar.html')
67
68 def test_uri_to_test(self):
69 port = self.make_port()
70 driver = Driver(port, None, pixel_tests=False)
71 self.assertEqual(driver.uri_to_test('file://%s/foo/bar.html' % port.layout_tests_dir()), 'foo/bar.html')
72 self.assertEqual(driver.uri_to_test('http://127.0.0.1:8000/foo.html'), 'http/tests/foo.html')
73 self.assertEqual(driver.uri_to_test('https://127.0.0.1:8443/ssl/bar.html'), 'http/tests/ssl/bar.html')
74
75 def test_read_block(self):
76 port = TestWebKitPort()
77 driver = Driver(port, 0, pixel_tests=False)
78 driver._server_process = MockServerProcess(lines=[
79 'ActualHash: foobar',
80 'Content-Type: my_type',
81 'Content-Transfer-Encoding: none',
82 "#EOF",
83 ])
84 content_block = driver._read_block(0)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000085 self.assertEqual(content_block.content_type, 'my_type')
86 self.assertEqual(content_block.encoding, 'none')
87 self.assertEqual(content_block.content_hash, 'foobar')
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000088 driver._server_process = None
89
90 def test_read_binary_block(self):
91 port = TestWebKitPort()
92 driver = Driver(port, 0, pixel_tests=True)
93 driver._server_process = MockServerProcess(lines=[
94 'ActualHash: actual',
95 'ExpectedHash: expected',
96 'Content-Type: image/png',
97 'Content-Length: 9',
98 "12345678",
99 "#EOF",
100 ])
101 content_block = driver._read_block(0)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000102 self.assertEqual(content_block.content_type, 'image/png')
103 self.assertEqual(content_block.content_hash, 'actual')
104 self.assertEqual(content_block.content, '12345678\n')
105 self.assertEqual(content_block.decoded_content, '12345678\n')
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000106 driver._server_process = None
107
108 def test_read_base64_block(self):
109 port = TestWebKitPort()
110 driver = Driver(port, 0, pixel_tests=True)
111 driver._server_process = MockServerProcess(lines=[
112 'ActualHash: actual',
113 'ExpectedHash: expected',
114 'Content-Type: image/png',
115 'Content-Transfer-Encoding: base64',
116 'Content-Length: 12',
117 'MTIzNDU2NzgK#EOF',
118 ])
119 content_block = driver._read_block(0)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000120 self.assertEqual(content_block.content_type, 'image/png')
121 self.assertEqual(content_block.content_hash, 'actual')
122 self.assertEqual(content_block.encoding, 'base64')
123 self.assertEqual(content_block.content, 'MTIzNDU2NzgK')
124 self.assertEqual(content_block.decoded_content, '12345678\n')
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000125
126 def test_no_timeout(self):
127 port = TestWebKitPort()
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000128 port._config.build_directory = lambda configuration: '/mock-build'
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000129 driver = Driver(port, 0, pixel_tests=True, no_timeout=True)
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100130 self.assertEqual(driver.cmd_line(True, []), ['/mock-build/content_shell', '--no-timeout', '--dump-render-tree', '-'])
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000131
132 def test_check_for_driver_crash(self):
133 port = TestWebKitPort()
134 driver = Driver(port, 0, pixel_tests=True)
135
136 class FakeServerProcess(object):
137 def __init__(self, crashed):
138 self.crashed = crashed
139
140 def pid(self):
141 return 1234
142
143 def name(self):
144 return 'FakeServerProcess'
145
146 def has_crashed(self):
147 return self.crashed
148
149 def stop(self, timeout):
150 pass
151
152 def assert_crash(driver, error_line, crashed, name, pid, unresponsive=False):
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000153 self.assertEqual(driver._check_for_driver_crash(error_line), crashed)
154 self.assertEqual(driver._crashed_process_name, name)
155 self.assertEqual(driver._crashed_pid, pid)
156 self.assertEqual(driver._subprocess_was_unresponsive, unresponsive)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000157 driver.stop()
158
159 driver._server_process = FakeServerProcess(False)
160 assert_crash(driver, '', False, None, None)
161
162 driver._crashed_process_name = None
163 driver._crashed_pid = None
164 driver._server_process = FakeServerProcess(False)
165 driver._subprocess_was_unresponsive = False
166 assert_crash(driver, '#CRASHED\n', True, 'FakeServerProcess', 1234)
167
168 driver._crashed_process_name = None
169 driver._crashed_pid = None
170 driver._server_process = FakeServerProcess(False)
171 driver._subprocess_was_unresponsive = False
172 assert_crash(driver, '#CRASHED - WebProcess\n', True, 'WebProcess', None)
173
174 driver._crashed_process_name = None
175 driver._crashed_pid = None
176 driver._server_process = FakeServerProcess(False)
177 driver._subprocess_was_unresponsive = False
178 assert_crash(driver, '#CRASHED - WebProcess (pid 8675)\n', True, 'WebProcess', 8675)
179
180 driver._crashed_process_name = None
181 driver._crashed_pid = None
182 driver._server_process = FakeServerProcess(False)
183 driver._subprocess_was_unresponsive = False
184 assert_crash(driver, '#PROCESS UNRESPONSIVE - WebProcess (pid 8675)\n', True, 'WebProcess', 8675, True)
185
186 driver._crashed_process_name = None
187 driver._crashed_pid = None
188 driver._server_process = FakeServerProcess(False)
189 driver._subprocess_was_unresponsive = False
190 assert_crash(driver, '#CRASHED - renderer (pid 8675)\n', True, 'renderer', 8675)
191
192 driver._crashed_process_name = None
193 driver._crashed_pid = None
194 driver._server_process = FakeServerProcess(True)
195 driver._subprocess_was_unresponsive = False
196 assert_crash(driver, '', True, 'FakeServerProcess', 1234)
197
198 def test_creating_a_port_does_not_write_to_the_filesystem(self):
199 port = TestWebKitPort()
200 driver = Driver(port, 0, pixel_tests=True)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000201 self.assertEqual(port._filesystem.written_files, {})
202 self.assertEqual(port._filesystem.last_tmpdir, None)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000203
204 def test_stop_cleans_up_properly(self):
205 port = TestWebKitPort()
206 port._server_process_constructor = MockServerProcess
207 driver = Driver(port, 0, pixel_tests=True)
208 driver.start(True, [])
209 last_tmpdir = port._filesystem.last_tmpdir
210 self.assertNotEquals(last_tmpdir, None)
211 driver.stop()
212 self.assertFalse(port._filesystem.isdir(last_tmpdir))
213
214 def test_two_starts_cleans_up_properly(self):
215 port = TestWebKitPort()
216 port._server_process_constructor = MockServerProcess
217 driver = Driver(port, 0, pixel_tests=True)
218 driver.start(True, [])
219 last_tmpdir = port._filesystem.last_tmpdir
220 driver._start(True, [])
221 self.assertFalse(port._filesystem.isdir(last_tmpdir))
222
223 def test_start_actually_starts(self):
224 port = TestWebKitPort()
225 port._server_process_constructor = MockServerProcess
226 driver = Driver(port, 0, pixel_tests=True)
227 driver.start(True, [])
228 self.assertTrue(driver._server_process.started)