blob: df2c024adf255cb2d3502a0e0868dc56876008db [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 Google name 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
29import base64
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +010030import copy
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000031import sys
32import time
33
34from webkitpy.layout_tests.port import Port, Driver, DriverOutput
35from webkitpy.layout_tests.port.base import VirtualTestSuite
36from webkitpy.layout_tests.models.test_configuration import TestConfiguration
37from webkitpy.common.system.filesystem_mock import MockFileSystem
38from webkitpy.common.system.crashlogs import CrashLogs
39
40
41# This sets basic expectations for a test. Each individual expectation
42# can be overridden by a keyword argument in TestList.add().
43class TestInstance(object):
44 def __init__(self, name):
45 self.name = name
46 self.base = name[(name.rfind("/") + 1):name.rfind(".")]
47 self.crash = False
48 self.web_process_crash = False
49 self.exception = False
50 self.hang = False
51 self.keyboard = False
52 self.error = ''
53 self.timeout = False
54 self.is_reftest = False
55
56 # The values of each field are treated as raw byte strings. They
57 # will be converted to unicode strings where appropriate using
58 # FileSystem.read_text_file().
59 self.actual_text = self.base + '-txt'
60 self.actual_checksum = self.base + '-checksum'
61
62 # We add the '\x8a' for the image file to prevent the value from
63 # being treated as UTF-8 (the character is invalid)
64 self.actual_image = self.base + '\x8a' + '-png' + 'tEXtchecksum\x00' + self.actual_checksum
65
66 self.expected_text = self.actual_text
67 self.expected_image = self.actual_image
68
69 self.actual_audio = None
70 self.expected_audio = None
71
72
73# This is an in-memory list of tests, what we want them to produce, and
74# what we want to claim are the expected results.
75class TestList(object):
76 def __init__(self):
77 self.tests = {}
78
79 def add(self, name, **kwargs):
80 test = TestInstance(name)
81 for key, value in kwargs.items():
82 test.__dict__[key] = value
83 self.tests[name] = test
84
85 def add_reftest(self, name, reference_name, same_image):
86 self.add(name, actual_checksum='xxx', actual_image='XXX', is_reftest=True)
87 if same_image:
88 self.add(reference_name, actual_checksum='xxx', actual_image='XXX', is_reftest=True)
89 else:
90 self.add(reference_name, actual_checksum='yyy', actual_image='YYY', is_reftest=True)
91
92 def keys(self):
93 return self.tests.keys()
94
95 def __contains__(self, item):
96 return item in self.tests
97
98 def __getitem__(self, item):
99 return self.tests[item]
100
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000101#
102# These numbers may need to be updated whenever we add or delete tests.
103#
Ben Murdoche69819b2013-07-17 14:56:49 +0100104TOTAL_TESTS = 106
105TOTAL_SKIPS = 27
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000106TOTAL_RETRIES = 14
107
108UNEXPECTED_PASSES = 6
109UNEXPECTED_FAILURES = 17
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000110
111def unit_test_list():
112 tests = TestList()
113 tests.add('failures/expected/crash.html', crash=True)
114 tests.add('failures/expected/exception.html', exception=True)
115 tests.add('failures/expected/timeout.html', timeout=True)
116 tests.add('failures/expected/hang.html', hang=True)
117 tests.add('failures/expected/missing_text.html', expected_text=None)
Ben Murdoch591b9582013-07-10 11:41:44 +0100118 tests.add('failures/expected/needsrebaseline.html', actual_text='needsrebaseline text')
Ben Murdoche69819b2013-07-17 14:56:49 +0100119 tests.add('failures/expected/needsmanualrebaseline.html', actual_text='needsmanualrebaseline text')
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000120 tests.add('failures/expected/image.html',
121 actual_image='image_fail-pngtEXtchecksum\x00checksum_fail',
122 expected_image='image-pngtEXtchecksum\x00checksum-png')
123 tests.add('failures/expected/image_checksum.html',
124 actual_checksum='image_checksum_fail-checksum',
125 actual_image='image_checksum_fail-png')
126 tests.add('failures/expected/audio.html',
127 actual_audio=base64.b64encode('audio_fail-wav'), expected_audio='audio-wav',
128 actual_text=None, expected_text=None,
129 actual_image=None, expected_image=None,
130 actual_checksum=None)
131 tests.add('failures/expected/keyboard.html', keyboard=True)
132 tests.add('failures/expected/missing_check.html',
133 expected_image='missing_check-png')
134 tests.add('failures/expected/missing_image.html', expected_image=None)
135 tests.add('failures/expected/missing_audio.html', expected_audio=None,
136 actual_text=None, expected_text=None,
137 actual_image=None, expected_image=None,
138 actual_checksum=None)
139 tests.add('failures/expected/missing_text.html', expected_text=None)
140 tests.add('failures/expected/newlines_leading.html',
141 expected_text="\nfoo\n", actual_text="foo\n")
142 tests.add('failures/expected/newlines_trailing.html',
143 expected_text="foo\n\n", actual_text="foo\n")
144 tests.add('failures/expected/newlines_with_excess_CR.html',
145 expected_text="foo\r\r\r\n", actual_text="foo\n")
146 tests.add('failures/expected/text.html', actual_text='text_fail-png')
147 tests.add('failures/expected/skip_text.html', actual_text='text diff')
148 tests.add('failures/flaky/text.html')
149 tests.add('failures/unexpected/missing_text.html', expected_text=None)
150 tests.add('failures/unexpected/missing_check.html', expected_image='missing-check-png')
151 tests.add('failures/unexpected/missing_image.html', expected_image=None)
152 tests.add('failures/unexpected/missing_render_tree_dump.html', actual_text="""layer at (0,0) size 800x600
153 RenderView at (0,0) size 800x600
154layer at (0,0) size 800x34
155 RenderBlock {HTML} at (0,0) size 800x34
156 RenderBody {BODY} at (8,8) size 784x18
157 RenderText {#text} at (0,0) size 133x18
158 text run at (0,0) width 133: "This is an image test!"
159""", expected_text=None)
160 tests.add('failures/unexpected/crash.html', crash=True)
161 tests.add('failures/unexpected/crash-with-stderr.html', crash=True,
162 error="mock-std-error-output")
163 tests.add('failures/unexpected/web-process-crash-with-stderr.html', web_process_crash=True,
164 error="mock-std-error-output")
165 tests.add('failures/unexpected/pass.html')
166 tests.add('failures/unexpected/text-checksum.html',
167 actual_text='text-checksum_fail-txt',
168 actual_checksum='text-checksum_fail-checksum')
169 tests.add('failures/unexpected/text-image-checksum.html',
170 actual_text='text-image-checksum_fail-txt',
171 actual_image='text-image-checksum_fail-pngtEXtchecksum\x00checksum_fail',
172 actual_checksum='text-image-checksum_fail-checksum')
173 tests.add('failures/unexpected/checksum-with-matching-image.html',
174 actual_checksum='text-image-checksum_fail-checksum')
175 tests.add('failures/unexpected/skip_pass.html')
176 tests.add('failures/unexpected/text.html', actual_text='text_fail-txt')
177 tests.add('failures/unexpected/timeout.html', timeout=True)
178 tests.add('http/tests/passes/text.html')
179 tests.add('http/tests/passes/image.html')
180 tests.add('http/tests/ssl/text.html')
181 tests.add('passes/args.html')
182 tests.add('passes/error.html', error='stuff going to stderr')
183 tests.add('passes/image.html')
184 tests.add('passes/audio.html',
185 actual_audio=base64.b64encode('audio-wav'), expected_audio='audio-wav',
186 actual_text=None, expected_text=None,
187 actual_image=None, expected_image=None,
188 actual_checksum=None)
189 tests.add('passes/platform_image.html')
190 tests.add('passes/checksum_in_image.html',
191 expected_image='tEXtchecksum\x00checksum_in_image-checksum')
192 tests.add('passes/skipped/skip.html')
193
194 # Note that here the checksums don't match but the images do, so this test passes "unexpectedly".
195 # See https://bugs.webkit.org/show_bug.cgi?id=69444 .
196 tests.add('failures/unexpected/checksum.html', actual_checksum='checksum_fail-checksum')
197
198 # Text output files contain "\r\n" on Windows. This may be
199 # helpfully filtered to "\r\r\n" by our Python/Cygwin tooling.
200 tests.add('passes/text.html',
201 expected_text='\nfoo\n\n', actual_text='\nfoo\r\n\r\r\n')
202
203 # For reftests.
204 tests.add_reftest('passes/reftest.html', 'passes/reftest-expected.html', same_image=True)
205 tests.add_reftest('passes/mismatch.html', 'passes/mismatch-expected-mismatch.html', same_image=False)
206 tests.add_reftest('passes/svgreftest.svg', 'passes/svgreftest-expected.svg', same_image=True)
207 tests.add_reftest('passes/xhtreftest.xht', 'passes/xhtreftest-expected.html', same_image=True)
208 tests.add_reftest('passes/phpreftest.php', 'passes/phpreftest-expected-mismatch.svg', same_image=False)
209 tests.add_reftest('failures/expected/reftest.html', 'failures/expected/reftest-expected.html', same_image=False)
210 tests.add_reftest('failures/expected/mismatch.html', 'failures/expected/mismatch-expected-mismatch.html', same_image=True)
211 tests.add_reftest('failures/unexpected/reftest.html', 'failures/unexpected/reftest-expected.html', same_image=False)
212 tests.add_reftest('failures/unexpected/mismatch.html', 'failures/unexpected/mismatch-expected-mismatch.html', same_image=True)
213 tests.add('failures/unexpected/reftest-nopixel.html', actual_checksum=None, actual_image=None, is_reftest=True)
214 tests.add('failures/unexpected/reftest-nopixel-expected.html', actual_checksum=None, actual_image=None, is_reftest=True)
215 # FIXME: Add a reftest which crashes.
216 tests.add('reftests/foo/test.html')
217 tests.add('reftests/foo/test-ref.html')
218
219 tests.add('reftests/foo/multiple-match-success.html', actual_checksum='abc', actual_image='abc')
220 tests.add('reftests/foo/multiple-match-failure.html', actual_checksum='abc', actual_image='abc')
221 tests.add('reftests/foo/multiple-mismatch-success.html', actual_checksum='abc', actual_image='abc')
222 tests.add('reftests/foo/multiple-mismatch-failure.html', actual_checksum='abc', actual_image='abc')
223 tests.add('reftests/foo/multiple-both-success.html', actual_checksum='abc', actual_image='abc')
224 tests.add('reftests/foo/multiple-both-failure.html', actual_checksum='abc', actual_image='abc')
225
226 tests.add('reftests/foo/matching-ref.html', actual_checksum='abc', actual_image='abc')
227 tests.add('reftests/foo/mismatching-ref.html', actual_checksum='def', actual_image='def')
228 tests.add('reftests/foo/second-mismatching-ref.html', actual_checksum='ghi', actual_image='ghi')
229
230 # The following files shouldn't be treated as reftests
231 tests.add_reftest('reftests/foo/unlistedtest.html', 'reftests/foo/unlistedtest-expected.html', same_image=True)
232 tests.add('reftests/foo/reference/bar/common.html')
233 tests.add('reftests/foo/reftest/bar/shared.html')
234
235 tests.add('websocket/tests/passes/text.html')
236
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100237 # For testing that we don't run tests under platform/. Note that these don't contribute to TOTAL_TESTS.
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000238 tests.add('platform/test-mac-leopard/http/test.html')
239 tests.add('platform/test-win-win7/http/test.html')
240
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000241 # For testing if perf tests are running in a locked shard.
242 tests.add('perf/foo/test.html')
243 tests.add('perf/foo/test-ref.html')
244
245 # For testing --pixel-test-directories.
246 tests.add('failures/unexpected/pixeldir/image_in_pixeldir.html',
247 actual_image='image_in_pixeldir-pngtEXtchecksum\x00checksum_fail',
248 expected_image='image_in_pixeldir-pngtEXtchecksum\x00checksum-png')
249 tests.add('failures/unexpected/image_not_in_pixeldir.html',
250 actual_image='image_not_in_pixeldir-pngtEXtchecksum\x00checksum_fail',
251 expected_image='image_not_in_pixeldir-pngtEXtchecksum\x00checksum-png')
252
253 # For testing that virtual test suites don't expand names containing themselves
254 # See webkit.org/b/97925 and base_unittest.PortTest.test_tests().
255 tests.add('passes/test-virtual-passes.html')
256 tests.add('passes/passes/test-virtual-passes.html')
257
258 return tests
259
260
261# Here we use a non-standard location for the layout tests, to ensure that
262# this works. The path contains a '.' in the name because we've seen bugs
263# related to this before.
264
265LAYOUT_TEST_DIR = '/test.checkout/LayoutTests'
266PERF_TEST_DIR = '/test.checkout/PerformanceTests'
267
268
269# Here we synthesize an in-memory filesystem from the test list
270# in order to fully control the test output and to demonstrate that
271# we don't need a real filesystem to run the tests.
272def add_unit_tests_to_mock_filesystem(filesystem):
273 # Add the test_expectations file.
274 filesystem.maybe_make_directory(LAYOUT_TEST_DIR + '/platform/test')
275 if not filesystem.exists(LAYOUT_TEST_DIR + '/platform/test/TestExpectations'):
276 filesystem.write_text_file(LAYOUT_TEST_DIR + '/platform/test/TestExpectations', """
277Bug(test) failures/expected/crash.html [ Crash ]
278Bug(test) failures/expected/image.html [ ImageOnlyFailure ]
Ben Murdoch591b9582013-07-10 11:41:44 +0100279Bug(test) failures/expected/needsrebaseline.html [ NeedsRebaseline ]
Ben Murdoche69819b2013-07-17 14:56:49 +0100280Bug(test) failures/expected/needsmanualrebaseline.html [ NeedsManualRebaseline ]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000281Bug(test) failures/expected/audio.html [ Failure ]
282Bug(test) failures/expected/image_checksum.html [ ImageOnlyFailure ]
283Bug(test) failures/expected/mismatch.html [ ImageOnlyFailure ]
284Bug(test) failures/expected/missing_check.html [ Missing Pass ]
285Bug(test) failures/expected/missing_image.html [ Missing Pass ]
286Bug(test) failures/expected/missing_audio.html [ Missing Pass ]
287Bug(test) failures/expected/missing_text.html [ Missing Pass ]
288Bug(test) failures/expected/newlines_leading.html [ Failure ]
289Bug(test) failures/expected/newlines_trailing.html [ Failure ]
290Bug(test) failures/expected/newlines_with_excess_CR.html [ Failure ]
291Bug(test) failures/expected/reftest.html [ ImageOnlyFailure ]
292Bug(test) failures/expected/text.html [ Failure ]
293Bug(test) failures/expected/timeout.html [ Timeout ]
294Bug(test) failures/expected/hang.html [ WontFix ]
295Bug(test) failures/expected/keyboard.html [ WontFix ]
296Bug(test) failures/expected/exception.html [ WontFix ]
297Bug(test) failures/unexpected/pass.html [ Failure ]
298Bug(test) passes/skipped/skip.html [ Skip ]
Torne (Richard Coles)81a51572013-05-13 16:52:28 +0100299Bug(test) passes/text.html [ Pass ]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000300""")
301
302 filesystem.maybe_make_directory(LAYOUT_TEST_DIR + '/reftests/foo')
303 filesystem.write_text_file(LAYOUT_TEST_DIR + '/reftests/foo/reftest.list', """
304== test.html test-ref.html
305
306== multiple-match-success.html mismatching-ref.html
307== multiple-match-success.html matching-ref.html
308== multiple-match-failure.html mismatching-ref.html
309== multiple-match-failure.html second-mismatching-ref.html
310!= multiple-mismatch-success.html mismatching-ref.html
311!= multiple-mismatch-success.html second-mismatching-ref.html
312!= multiple-mismatch-failure.html mismatching-ref.html
313!= multiple-mismatch-failure.html matching-ref.html
314== multiple-both-success.html matching-ref.html
315== multiple-both-success.html mismatching-ref.html
316!= multiple-both-success.html second-mismatching-ref.html
317== multiple-both-failure.html matching-ref.html
318!= multiple-both-failure.html second-mismatching-ref.html
319!= multiple-both-failure.html matching-ref.html
320""")
321
322 # FIXME: This test was only being ignored because of missing a leading '/'.
323 # Fixing the typo causes several tests to assert, so disabling the test entirely.
324 # Add in a file should be ignored by port.find_test_files().
325 #files[LAYOUT_TEST_DIR + '/userscripts/resources/iframe.html'] = 'iframe'
326
327 def add_file(test, suffix, contents):
328 dirname = filesystem.join(LAYOUT_TEST_DIR, test.name[0:test.name.rfind('/')])
329 base = test.base
330 filesystem.maybe_make_directory(dirname)
331 filesystem.write_binary_file(filesystem.join(dirname, base + suffix), contents)
332
333 # Add each test and the expected output, if any.
334 test_list = unit_test_list()
335 for test in test_list.tests.values():
336 add_file(test, test.name[test.name.rfind('.'):], '')
337 if test.is_reftest:
338 continue
339 if test.actual_audio:
340 add_file(test, '-expected.wav', test.expected_audio)
341 continue
342 add_file(test, '-expected.txt', test.expected_text)
343 add_file(test, '-expected.png', test.expected_image)
344
345 filesystem.write_text_file(filesystem.join(LAYOUT_TEST_DIR, 'virtual', 'passes', 'args-expected.txt'), 'args-txt --virtual-arg')
346 # Clear the list of written files so that we can watch what happens during testing.
347 filesystem.clear_written_files()
348
349
350class TestPort(Port):
351 port_name = 'test'
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000352 default_port_name = 'test-mac-leopard'
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000353
354 """Test implementation of the Port interface."""
355 ALL_BASELINE_VARIANTS = (
356 'test-linux-x86_64',
357 'test-mac-snowleopard', 'test-mac-leopard',
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100358 'test-win-win7', 'test-win-xp',
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000359 )
360
361 @classmethod
362 def determine_full_port_name(cls, host, options, port_name):
363 if port_name == 'test':
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000364 return TestPort.default_port_name
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000365 return port_name
366
367 def __init__(self, host, port_name=None, **kwargs):
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000368 Port.__init__(self, host, port_name or TestPort.default_port_name, **kwargs)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000369 self._tests = unit_test_list()
370 self._flakes = set()
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100371 self._generic_expectations_path = LAYOUT_TEST_DIR + '/TestExpectations'
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000372 self._results_directory = None
373
374 self._operating_system = 'mac'
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000375 if self._name.startswith('test-win'):
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000376 self._operating_system = 'win'
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000377 elif self._name.startswith('test-linux'):
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000378 self._operating_system = 'linux'
379
380 version_map = {
381 'test-win-xp': 'xp',
382 'test-win-win7': 'win7',
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000383 'test-mac-leopard': 'leopard',
384 'test-mac-snowleopard': 'snowleopard',
385 'test-linux-x86_64': 'lucid',
386 }
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000387 self._version = version_map[self._name]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000388
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100389 def buildbot_archives_baselines(self):
390 return self._name != 'test-win-xp'
391
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000392 def default_pixel_tests(self):
393 return True
394
395 def _path_to_driver(self):
396 # This routine shouldn't normally be called, but it is called by
397 # the mock_drt Driver. We return something, but make sure it's useless.
398 return 'MOCK _path_to_driver'
399
400 def baseline_search_path(self):
401 search_paths = {
402 'test-mac-snowleopard': ['test-mac-snowleopard'],
403 'test-mac-leopard': ['test-mac-leopard', 'test-mac-snowleopard'],
404 'test-win-win7': ['test-win-win7'],
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100405 'test-win-xp': ['test-win-xp', 'test-win-win7'],
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100406 'test-linux-x86_64': ['test-linux-x86_64', 'test-win-win7'],
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000407 }
408 return [self._webkit_baseline_path(d) for d in search_paths[self.name()]]
409
410 def default_child_processes(self):
411 return 1
412
413 def worker_startup_delay_secs(self):
414 return 0
415
416 def check_build(self, needs_http):
417 return True
418
419 def check_sys_deps(self, needs_http):
420 return True
421
422 def default_configuration(self):
423 return 'Release'
424
Ben Murdoch591b9582013-07-10 11:41:44 +0100425 def diff_image(self, expected_contents, actual_contents):
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000426 diffed = actual_contents != expected_contents
427 if not actual_contents and not expected_contents:
Ben Murdoch591b9582013-07-10 11:41:44 +0100428 return (None, None)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000429 if not actual_contents or not expected_contents:
Ben Murdoch591b9582013-07-10 11:41:44 +0100430 return (True, None)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000431 if diffed:
Ben Murdoch591b9582013-07-10 11:41:44 +0100432 return ("< %s\n---\n> %s\n" % (expected_contents, actual_contents), None)
433 return (None, None)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000434
435 def layout_tests_dir(self):
436 return LAYOUT_TEST_DIR
437
438 def perf_tests_dir(self):
439 return PERF_TEST_DIR
440
441 def webkit_base(self):
442 return '/test.checkout'
443
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000444 def _skipped_tests_for_unsupported_features(self, test_list):
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000445 return set(['failures/expected/skip_text.html',
446 'failures/unexpected/skip_pass.html',
447 'virtual/skipped'])
448
449 def name(self):
450 return self._name
451
452 def operating_system(self):
453 return self._operating_system
454
455 def _path_to_wdiff(self):
456 return None
457
458 def default_results_directory(self):
459 return '/tmp/layout-test-results'
460
461 def setup_test_run(self):
462 pass
463
464 def _driver_class(self):
465 return TestDriver
466
467 def start_http_server(self, additional_dirs=None, number_of_servers=None):
468 pass
469
470 def start_websocket_server(self):
471 pass
472
473 def acquire_http_lock(self):
474 pass
475
476 def stop_http_server(self):
477 pass
478
479 def stop_websocket_server(self):
480 pass
481
482 def release_http_lock(self):
483 pass
484
485 def _path_to_lighttpd(self):
486 return "/usr/sbin/lighttpd"
487
488 def _path_to_lighttpd_modules(self):
489 return "/usr/lib/lighttpd"
490
491 def _path_to_lighttpd_php(self):
492 return "/usr/bin/php-cgi"
493
494 def _path_to_apache(self):
495 return "/usr/sbin/httpd"
496
497 def _path_to_apache_config_file(self):
498 return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf', 'httpd.conf')
499
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100500 def path_to_generic_test_expectations_file(self):
501 return self._generic_expectations_path
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000502
503 def all_test_configurations(self):
504 """Returns a sequence of the TestConfigurations the port supports."""
505 # By default, we assume we want to test every graphics type in
506 # every configuration on every system.
507 test_configurations = []
508 for version, architecture in self._all_systems():
509 for build_type in self._all_build_types():
510 test_configurations.append(TestConfiguration(
511 version=version,
512 architecture=architecture,
513 build_type=build_type))
514 return test_configurations
515
516 def _all_systems(self):
517 return (('leopard', 'x86'),
518 ('snowleopard', 'x86'),
519 ('xp', 'x86'),
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000520 ('win7', 'x86'),
521 ('lucid', 'x86'),
522 ('lucid', 'x86_64'))
523
524 def _all_build_types(self):
525 return ('debug', 'release')
526
527 def configuration_specifier_macros(self):
528 """To avoid surprises when introducing new macros, these are intentionally fixed in time."""
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100529 return {'mac': ['leopard', 'snowleopard'], 'win': ['xp', 'win7'], 'linux': ['lucid']}
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000530
531 def all_baseline_variants(self):
532 return self.ALL_BASELINE_VARIANTS
533
534 def virtual_test_suites(self):
535 return [
536 VirtualTestSuite('virtual/passes', 'passes', ['--virtual-arg']),
537 VirtualTestSuite('virtual/skipped', 'failures/expected', ['--virtual-arg2']),
538 ]
539
540
541class TestDriver(Driver):
Ben Murdoch591b9582013-07-10 11:41:44 +0100542 """Test/Dummy implementation of the driver interface."""
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000543 next_pid = 1
544
545 def __init__(self, *args, **kwargs):
546 super(TestDriver, self).__init__(*args, **kwargs)
547 self.started = False
548 self.pid = 0
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000549
550 def cmd_line(self, pixel_tests, per_test_args):
551 pixel_tests_flag = '-p' if pixel_tests else ''
552 return [self._port._path_to_driver()] + [pixel_tests_flag] + self._port.get_option('additional_drt_flag', []) + per_test_args
553
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100554 def run_test(self, driver_input, stop_when_done):
555 base = self._port.lookup_virtual_test_base(driver_input.test_name)
556 if base:
557 virtual_driver_input = copy.copy(driver_input)
558 virtual_driver_input.test_name = base
559 virtual_driver_input.args = self._port.lookup_virtual_test_args(driver_input.test_name)
560 return self.run_test(virtual_driver_input, stop_when_done)
561
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000562 if not self.started:
563 self.started = True
564 self.pid = TestDriver.next_pid
565 TestDriver.next_pid += 1
566
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000567 start_time = time.time()
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100568 test_name = driver_input.test_name
569 test_args = driver_input.args or []
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000570 test = self._port._tests[test_name]
571 if test.keyboard:
572 raise KeyboardInterrupt
573 if test.exception:
574 raise ValueError('exception from ' + test_name)
575 if test.hang:
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100576 time.sleep((float(driver_input.timeout) * 4) / 1000.0 + 1.0) # The 1.0 comes from thread_padding_sec in layout_test_runnery.
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000577
578 audio = None
579 actual_text = test.actual_text
580
581 if 'flaky' in test_name and not test_name in self._port._flakes:
582 self._port._flakes.add(test_name)
583 actual_text = 'flaky text failure'
584
585 if actual_text and test_args and test_name == 'passes/args.html':
586 actual_text = actual_text + ' ' + ' '.join(test_args)
587
588 if test.actual_audio:
589 audio = base64.b64decode(test.actual_audio)
590 crashed_process_name = None
591 crashed_pid = None
592 if test.crash:
593 crashed_process_name = self._port.driver_name()
594 crashed_pid = 1
595 elif test.web_process_crash:
596 crashed_process_name = 'WebProcess'
597 crashed_pid = 2
598
599 crash_log = ''
600 if crashed_process_name:
601 crash_logs = CrashLogs(self._port.host)
602 crash_log = crash_logs.find_newest_log(crashed_process_name, None) or ''
603
604 if stop_when_done:
605 self.stop()
606
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100607 if test.actual_checksum == driver_input.image_hash:
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000608 image = None
609 else:
610 image = test.actual_image
611 return DriverOutput(actual_text, image, test.actual_checksum, audio,
612 crash=test.crash or test.web_process_crash, crashed_process_name=crashed_process_name,
613 crashed_pid=crashed_pid, crash_log=crash_log,
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000614 test_time=time.time() - start_time, timeout=test.timeout, error=test.error, pid=self.pid)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000615
616 def stop(self):
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000617 self.started = False