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 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 30import copy 31import sys 32import time 33 34from webkitpy.layout_tests.port import DeviceFailure, Driver, DriverOutput, Port 35from webkitpy.layout_tests.port.base import VirtualTestSuite 36from webkitpy.layout_tests.models.test_configuration import TestConfiguration 37from webkitpy.layout_tests.models import test_run_results 38from webkitpy.common.system.filesystem_mock import MockFileSystem 39from webkitpy.common.system.crashlogs import CrashLogs 40 41 42# This sets basic expectations for a test. Each individual expectation 43# can be overridden by a keyword argument in TestList.add(). 44class TestInstance(object): 45 def __init__(self, name): 46 self.name = name 47 self.base = name[(name.rfind("/") + 1):name.rfind(".")] 48 self.crash = False 49 self.web_process_crash = False 50 self.exception = False 51 self.keyboard = False 52 self.error = '' 53 self.timeout = False 54 self.is_reftest = False 55 self.device_failure = False 56 57 # The values of each field are treated as raw byte strings. They 58 # will be converted to unicode strings where appropriate using 59 # FileSystem.read_text_file(). 60 self.actual_text = self.base + '-txt' 61 self.actual_checksum = self.base + '-checksum' 62 63 # We add the '\x8a' for the image file to prevent the value from 64 # being treated as UTF-8 (the character is invalid) 65 self.actual_image = self.base + '\x8a' + '-png' + 'tEXtchecksum\x00' + self.actual_checksum 66 67 self.expected_text = self.actual_text 68 self.expected_image = self.actual_image 69 70 self.actual_audio = None 71 self.expected_audio = None 72 73 74# This is an in-memory list of tests, what we want them to produce, and 75# what we want to claim are the expected results. 76class TestList(object): 77 def __init__(self): 78 self.tests = {} 79 80 def add(self, name, **kwargs): 81 test = TestInstance(name) 82 for key, value in kwargs.items(): 83 test.__dict__[key] = value 84 self.tests[name] = test 85 86 def add_reftest(self, name, reference_name, same_image, crash=False): 87 self.add(name, actual_checksum='xxx', actual_image='XXX', is_reftest=True, crash=crash) 88 if same_image: 89 self.add(reference_name, actual_checksum='xxx', actual_image='XXX', is_reftest=True) 90 else: 91 self.add(reference_name, actual_checksum='yyy', actual_image='YYY', is_reftest=True) 92 93 def keys(self): 94 return self.tests.keys() 95 96 def __contains__(self, item): 97 return item in self.tests 98 99 def __getitem__(self, item): 100 return self.tests[item] 101 102# 103# These numbers may need to be updated whenever we add or delete tests. This includes virtual tests. 104# 105TOTAL_TESTS = 110 106TOTAL_SKIPS = 28 107 108UNEXPECTED_PASSES = 1 109UNEXPECTED_FAILURES = 25 110 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/device_failure.html', device_failure=True) 116 tests.add('failures/expected/timeout.html', timeout=True) 117 tests.add('failures/expected/missing_text.html', expected_text=None) 118 tests.add('failures/expected/needsrebaseline.html', actual_text='needsrebaseline text') 119 tests.add('failures/expected/needsmanualrebaseline.html', actual_text='needsmanualrebaseline text') 120 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/crash_then_text.html') 148 tests.add('failures/expected/skip_text.html', actual_text='text diff') 149 tests.add('failures/flaky/text.html') 150 tests.add('failures/unexpected/missing_text.html', expected_text=None) 151 tests.add('failures/unexpected/missing_check.html', expected_image='missing-check-png') 152 tests.add('failures/unexpected/missing_image.html', expected_image=None) 153 tests.add('failures/unexpected/missing_render_tree_dump.html', actual_text="""layer at (0,0) size 800x600 154 RenderView at (0,0) size 800x600 155layer at (0,0) size 800x34 156 RenderBlock {HTML} at (0,0) size 800x34 157 RenderBody {BODY} at (8,8) size 784x18 158 RenderText {#text} at (0,0) size 133x18 159 text run at (0,0) width 133: "This is an image test!" 160""", expected_text=None) 161 tests.add('failures/unexpected/crash.html', crash=True) 162 tests.add('failures/unexpected/crash-with-stderr.html', crash=True, 163 error="mock-std-error-output") 164 tests.add('failures/unexpected/web-process-crash-with-stderr.html', web_process_crash=True, 165 error="mock-std-error-output") 166 tests.add('failures/unexpected/pass.html') 167 tests.add('failures/unexpected/text-checksum.html', 168 actual_text='text-checksum_fail-txt', 169 actual_checksum='text-checksum_fail-checksum') 170 tests.add('failures/unexpected/text-image-checksum.html', 171 actual_text='text-image-checksum_fail-txt', 172 actual_image='text-image-checksum_fail-pngtEXtchecksum\x00checksum_fail', 173 actual_checksum='text-image-checksum_fail-checksum') 174 tests.add('failures/unexpected/checksum-with-matching-image.html', 175 actual_checksum='text-image-checksum_fail-checksum') 176 tests.add('failures/unexpected/skip_pass.html') 177 tests.add('failures/unexpected/text.html', actual_text='text_fail-txt') 178 tests.add('failures/unexpected/text_then_crash.html') 179 tests.add('failures/unexpected/timeout.html', timeout=True) 180 tests.add('http/tests/passes/text.html') 181 tests.add('http/tests/passes/image.html') 182 tests.add('http/tests/ssl/text.html') 183 tests.add('passes/args.html') 184 tests.add('passes/error.html', error='stuff going to stderr') 185 tests.add('passes/image.html') 186 tests.add('passes/audio.html', 187 actual_audio=base64.b64encode('audio-wav'), expected_audio='audio-wav', 188 actual_text=None, expected_text=None, 189 actual_image=None, expected_image=None, 190 actual_checksum=None) 191 tests.add('passes/platform_image.html') 192 tests.add('passes/checksum_in_image.html', 193 expected_image='tEXtchecksum\x00checksum_in_image-checksum') 194 tests.add('passes/skipped/skip.html') 195 196 # Note that here the checksums don't match but the images do, so this test passes "unexpectedly". 197 # See https://bugs.webkit.org/show_bug.cgi?id=69444 . 198 tests.add('failures/unexpected/checksum.html', actual_checksum='checksum_fail-checksum') 199 200 # Text output files contain "\r\n" on Windows. This may be 201 # helpfully filtered to "\r\r\n" by our Python/Cygwin tooling. 202 tests.add('passes/text.html', 203 expected_text='\nfoo\n\n', actual_text='\nfoo\r\n\r\r\n') 204 205 # For reftests. 206 tests.add_reftest('passes/reftest.html', 'passes/reftest-expected.html', same_image=True) 207 208 # This adds a different virtual reference to ensure that that also works. 209 tests.add('virtual/passes/reftest-expected.html', actual_checksum='xxx', actual_image='XXX', is_reftest=True) 210 211 tests.add_reftest('passes/mismatch.html', 'passes/mismatch-expected-mismatch.html', same_image=False) 212 tests.add_reftest('passes/svgreftest.svg', 'passes/svgreftest-expected.svg', same_image=True) 213 tests.add_reftest('passes/xhtreftest.xht', 'passes/xhtreftest-expected.html', same_image=True) 214 tests.add_reftest('passes/phpreftest.php', 'passes/phpreftest-expected-mismatch.svg', same_image=False) 215 tests.add_reftest('failures/expected/reftest.html', 'failures/expected/reftest-expected.html', same_image=False) 216 tests.add_reftest('failures/expected/mismatch.html', 'failures/expected/mismatch-expected-mismatch.html', same_image=True) 217 tests.add_reftest('failures/unexpected/crash-reftest.html', 'failures/unexpected/crash-reftest-expected.html', same_image=True, crash=True) 218 tests.add_reftest('failures/unexpected/reftest.html', 'failures/unexpected/reftest-expected.html', same_image=False) 219 tests.add_reftest('failures/unexpected/mismatch.html', 'failures/unexpected/mismatch-expected-mismatch.html', same_image=True) 220 tests.add('failures/unexpected/reftest-nopixel.html', actual_checksum=None, actual_image=None, is_reftest=True) 221 tests.add('failures/unexpected/reftest-nopixel-expected.html', actual_checksum=None, actual_image=None, is_reftest=True) 222 tests.add('reftests/foo/test.html') 223 tests.add('reftests/foo/test-ref.html') 224 225 tests.add('reftests/foo/multiple-match-success.html', actual_checksum='abc', actual_image='abc') 226 tests.add('reftests/foo/multiple-match-failure.html', actual_checksum='abc', actual_image='abc') 227 tests.add('reftests/foo/multiple-mismatch-success.html', actual_checksum='abc', actual_image='abc') 228 tests.add('reftests/foo/multiple-mismatch-failure.html', actual_checksum='abc', actual_image='abc') 229 tests.add('reftests/foo/multiple-both-success.html', actual_checksum='abc', actual_image='abc') 230 tests.add('reftests/foo/multiple-both-failure.html', actual_checksum='abc', actual_image='abc') 231 232 tests.add('reftests/foo/matching-ref.html', actual_checksum='abc', actual_image='abc') 233 tests.add('reftests/foo/mismatching-ref.html', actual_checksum='def', actual_image='def') 234 tests.add('reftests/foo/second-mismatching-ref.html', actual_checksum='ghi', actual_image='ghi') 235 236 # The following files shouldn't be treated as reftests 237 tests.add_reftest('reftests/foo/unlistedtest.html', 'reftests/foo/unlistedtest-expected.html', same_image=True) 238 tests.add('reftests/foo/reference/bar/common.html') 239 tests.add('reftests/foo/reftest/bar/shared.html') 240 241 tests.add('websocket/tests/passes/text.html') 242 243 # For testing that we don't run tests under platform/. Note that these don't contribute to TOTAL_TESTS. 244 tests.add('platform/test-mac-leopard/http/test.html') 245 tests.add('platform/test-win-win7/http/test.html') 246 247 # For testing if perf tests are running in a locked shard. 248 tests.add('perf/foo/test.html') 249 tests.add('perf/foo/test-ref.html') 250 251 # For testing --pixel-test-directories. 252 tests.add('failures/unexpected/pixeldir/image_in_pixeldir.html', 253 actual_image='image_in_pixeldir-pngtEXtchecksum\x00checksum_fail', 254 expected_image='image_in_pixeldir-pngtEXtchecksum\x00checksum-png') 255 tests.add('failures/unexpected/image_not_in_pixeldir.html', 256 actual_image='image_not_in_pixeldir-pngtEXtchecksum\x00checksum_fail', 257 expected_image='image_not_in_pixeldir-pngtEXtchecksum\x00checksum-png') 258 259 # For testing that virtual test suites don't expand names containing themselves 260 # See webkit.org/b/97925 and base_unittest.PortTest.test_tests(). 261 tests.add('passes/test-virtual-passes.html') 262 tests.add('passes/passes/test-virtual-passes.html') 263 264 return tests 265 266 267# Here we use a non-standard location for the layout tests, to ensure that 268# this works. The path contains a '.' in the name because we've seen bugs 269# related to this before. 270 271LAYOUT_TEST_DIR = '/test.checkout/LayoutTests' 272PERF_TEST_DIR = '/test.checkout/PerformanceTests' 273 274 275# Here we synthesize an in-memory filesystem from the test list 276# in order to fully control the test output and to demonstrate that 277# we don't need a real filesystem to run the tests. 278def add_unit_tests_to_mock_filesystem(filesystem): 279 # Add the test_expectations file. 280 filesystem.maybe_make_directory('/mock-checkout/LayoutTests') 281 if not filesystem.exists('/mock-checkout/LayoutTests/TestExpectations'): 282 filesystem.write_text_file('/mock-checkout/LayoutTests/TestExpectations', """ 283Bug(test) failures/expected/crash.html [ Crash ] 284Bug(test) failures/expected/crash_then_text.html [ Failure ] 285Bug(test) failures/expected/image.html [ ImageOnlyFailure ] 286Bug(test) failures/expected/needsrebaseline.html [ NeedsRebaseline ] 287Bug(test) failures/expected/needsmanualrebaseline.html [ NeedsManualRebaseline ] 288Bug(test) failures/expected/audio.html [ Failure ] 289Bug(test) failures/expected/image_checksum.html [ ImageOnlyFailure ] 290Bug(test) failures/expected/mismatch.html [ ImageOnlyFailure ] 291Bug(test) failures/expected/missing_check.html [ Missing Pass ] 292Bug(test) failures/expected/missing_image.html [ Missing Pass ] 293Bug(test) failures/expected/missing_audio.html [ Missing Pass ] 294Bug(test) failures/expected/missing_text.html [ Missing Pass ] 295Bug(test) failures/expected/newlines_leading.html [ Failure ] 296Bug(test) failures/expected/newlines_trailing.html [ Failure ] 297Bug(test) failures/expected/newlines_with_excess_CR.html [ Failure ] 298Bug(test) failures/expected/reftest.html [ ImageOnlyFailure ] 299Bug(test) failures/expected/text.html [ Failure ] 300Bug(test) failures/expected/timeout.html [ Timeout ] 301Bug(test) failures/expected/keyboard.html [ WontFix ] 302Bug(test) failures/expected/exception.html [ WontFix ] 303Bug(test) failures/expected/device_failure.html [ WontFix ] 304Bug(test) failures/unexpected/pass.html [ Failure ] 305Bug(test) passes/skipped/skip.html [ Skip ] 306Bug(test) passes/text.html [ Pass ] 307""") 308 309 filesystem.maybe_make_directory(LAYOUT_TEST_DIR + '/reftests/foo') 310 filesystem.write_text_file(LAYOUT_TEST_DIR + '/reftests/foo/reftest.list', """ 311== test.html test-ref.html 312 313== multiple-match-success.html mismatching-ref.html 314== multiple-match-success.html matching-ref.html 315== multiple-match-failure.html mismatching-ref.html 316== multiple-match-failure.html second-mismatching-ref.html 317!= multiple-mismatch-success.html mismatching-ref.html 318!= multiple-mismatch-success.html second-mismatching-ref.html 319!= multiple-mismatch-failure.html mismatching-ref.html 320!= multiple-mismatch-failure.html matching-ref.html 321== multiple-both-success.html matching-ref.html 322== multiple-both-success.html mismatching-ref.html 323!= multiple-both-success.html second-mismatching-ref.html 324== multiple-both-failure.html matching-ref.html 325!= multiple-both-failure.html second-mismatching-ref.html 326!= multiple-both-failure.html matching-ref.html 327""") 328 329 # FIXME: This test was only being ignored because of missing a leading '/'. 330 # Fixing the typo causes several tests to assert, so disabling the test entirely. 331 # Add in a file should be ignored by port.find_test_files(). 332 #files[LAYOUT_TEST_DIR + '/userscripts/resources/iframe.html'] = 'iframe' 333 334 def add_file(test, suffix, contents): 335 dirname = filesystem.join(LAYOUT_TEST_DIR, test.name[0:test.name.rfind('/')]) 336 base = test.base 337 filesystem.maybe_make_directory(dirname) 338 filesystem.write_binary_file(filesystem.join(dirname, base + suffix), contents) 339 340 # Add each test and the expected output, if any. 341 test_list = unit_test_list() 342 for test in test_list.tests.values(): 343 add_file(test, test.name[test.name.rfind('.'):], '') 344 if test.is_reftest: 345 continue 346 if test.actual_audio: 347 add_file(test, '-expected.wav', test.expected_audio) 348 continue 349 add_file(test, '-expected.txt', test.expected_text) 350 add_file(test, '-expected.png', test.expected_image) 351 352 filesystem.write_text_file(filesystem.join(LAYOUT_TEST_DIR, 'virtual', 'passes', 'args-expected.txt'), 'args-txt --virtual-arg') 353 # Clear the list of written files so that we can watch what happens during testing. 354 filesystem.clear_written_files() 355 356 357class TestPort(Port): 358 port_name = 'test' 359 default_port_name = 'test-mac-leopard' 360 361 """Test implementation of the Port interface.""" 362 ALL_BASELINE_VARIANTS = ( 363 'test-linux-x86_64', 364 'test-mac-snowleopard', 'test-mac-leopard', 365 'test-win-win7', 'test-win-xp', 366 ) 367 368 FALLBACK_PATHS = { 369 'xp': ['test-win-win7', 'test-win-xp'], 370 'win7': ['test-win-win7'], 371 'leopard': ['test-mac-leopard', 'test-mac-snowleopard'], 372 'snowleopard': ['test-mac-snowleopard'], 373 'lucid': ['test-linux-x86_64', 'test-win-win7'], 374 } 375 376 @classmethod 377 def determine_full_port_name(cls, host, options, port_name): 378 if port_name == 'test': 379 return TestPort.default_port_name 380 return port_name 381 382 def __init__(self, host, port_name=None, **kwargs): 383 Port.__init__(self, host, port_name or TestPort.default_port_name, **kwargs) 384 self._tests = unit_test_list() 385 self._flakes = set() 386 387 # FIXME: crbug.com/279494. This needs to be in the "real layout tests 388 # dir" in a mock filesystem, rather than outside of the checkout, so 389 # that tests that want to write to a TestExpectations file can share 390 # this between "test" ports and "real" ports. This is the result of 391 # rebaseline_unittest.py having tests that refer to "real" port names 392 # and real builders instead of fake builders that point back to the 393 # test ports. rebaseline_unittest.py needs to not mix both "real" ports 394 # and "test" ports 395 396 self._generic_expectations_path = '/mock-checkout/LayoutTests/TestExpectations' 397 self._results_directory = None 398 399 self._operating_system = 'mac' 400 if self._name.startswith('test-win'): 401 self._operating_system = 'win' 402 elif self._name.startswith('test-linux'): 403 self._operating_system = 'linux' 404 405 version_map = { 406 'test-win-xp': 'xp', 407 'test-win-win7': 'win7', 408 'test-mac-leopard': 'leopard', 409 'test-mac-snowleopard': 'snowleopard', 410 'test-linux-x86_64': 'lucid', 411 } 412 self._version = version_map[self._name] 413 414 def repository_paths(self): 415 """Returns a list of (repository_name, repository_path) tuples of its depending code base.""" 416 # FIXME: We override this just to keep the perf tests happy. 417 return [('blink', self.layout_tests_dir())] 418 419 def buildbot_archives_baselines(self): 420 return self._name != 'test-win-xp' 421 422 def default_pixel_tests(self): 423 return True 424 425 def _path_to_driver(self): 426 # This routine shouldn't normally be called, but it is called by 427 # the mock_drt Driver. We return something, but make sure it's useless. 428 return 'MOCK _path_to_driver' 429 430 def default_child_processes(self): 431 return 1 432 433 def check_build(self, needs_http, printer): 434 return test_run_results.OK_EXIT_STATUS 435 436 def check_sys_deps(self, needs_http): 437 return test_run_results.OK_EXIT_STATUS 438 439 def default_configuration(self): 440 return 'Release' 441 442 def diff_image(self, expected_contents, actual_contents): 443 diffed = actual_contents != expected_contents 444 if not actual_contents and not expected_contents: 445 return (None, None) 446 if not actual_contents or not expected_contents: 447 return (True, None) 448 if diffed: 449 return ("< %s\n---\n> %s\n" % (expected_contents, actual_contents), None) 450 return (None, None) 451 452 def layout_tests_dir(self): 453 return LAYOUT_TEST_DIR 454 455 def perf_tests_dir(self): 456 return PERF_TEST_DIR 457 458 def webkit_base(self): 459 return '/test.checkout' 460 461 def _skipped_tests_for_unsupported_features(self, test_list): 462 return set(['failures/expected/skip_text.html', 463 'failures/unexpected/skip_pass.html', 464 'virtual/skipped']) 465 466 def name(self): 467 return self._name 468 469 def operating_system(self): 470 return self._operating_system 471 472 def _path_to_wdiff(self): 473 return None 474 475 def default_results_directory(self): 476 return '/tmp/layout-test-results' 477 478 def setup_test_run(self): 479 pass 480 481 def _driver_class(self): 482 return TestDriver 483 484 def start_http_server(self, additional_dirs=None, number_of_servers=None): 485 pass 486 487 def start_websocket_server(self): 488 pass 489 490 def acquire_http_lock(self): 491 pass 492 493 def stop_http_server(self): 494 pass 495 496 def stop_websocket_server(self): 497 pass 498 499 def release_http_lock(self): 500 pass 501 502 def _path_to_lighttpd(self): 503 return "/usr/sbin/lighttpd" 504 505 def _path_to_lighttpd_modules(self): 506 return "/usr/lib/lighttpd" 507 508 def _path_to_lighttpd_php(self): 509 return "/usr/bin/php-cgi" 510 511 def _path_to_apache(self): 512 return "/usr/sbin/httpd" 513 514 def _path_to_apache_config_file(self): 515 return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf', 'httpd.conf') 516 517 def path_to_generic_test_expectations_file(self): 518 return self._generic_expectations_path 519 520 def _port_specific_expectations_files(self): 521 return [self._filesystem.join(self._webkit_baseline_path(d), 'TestExpectations') for d in ['test', 'test-win-xp']] 522 523 def all_test_configurations(self): 524 """Returns a sequence of the TestConfigurations the port supports.""" 525 # By default, we assume we want to test every graphics type in 526 # every configuration on every system. 527 test_configurations = [] 528 for version, architecture in self._all_systems(): 529 for build_type in self._all_build_types(): 530 test_configurations.append(TestConfiguration( 531 version=version, 532 architecture=architecture, 533 build_type=build_type)) 534 return test_configurations 535 536 def _all_systems(self): 537 return (('leopard', 'x86'), 538 ('snowleopard', 'x86'), 539 ('xp', 'x86'), 540 ('win7', 'x86'), 541 ('lucid', 'x86'), 542 ('lucid', 'x86_64')) 543 544 def _all_build_types(self): 545 return ('debug', 'release') 546 547 def configuration_specifier_macros(self): 548 """To avoid surprises when introducing new macros, these are intentionally fixed in time.""" 549 return {'mac': ['leopard', 'snowleopard'], 'win': ['xp', 'win7'], 'linux': ['lucid']} 550 551 def all_baseline_variants(self): 552 return self.ALL_BASELINE_VARIANTS 553 554 def virtual_test_suites(self): 555 return [ 556 VirtualTestSuite('passes', 'passes', ['--virtual-arg'], use_legacy_naming=True), 557 VirtualTestSuite('skipped', 'failures/expected', ['--virtual-arg2'], use_legacy_naming=True), 558 ] 559 560 561class TestDriver(Driver): 562 """Test/Dummy implementation of the driver interface.""" 563 next_pid = 1 564 565 def __init__(self, *args, **kwargs): 566 super(TestDriver, self).__init__(*args, **kwargs) 567 self.started = False 568 self.pid = 0 569 570 def cmd_line(self, pixel_tests, per_test_args): 571 pixel_tests_flag = '-p' if pixel_tests else '' 572 return [self._port._path_to_driver()] + [pixel_tests_flag] + self._port.get_option('additional_drt_flag', []) + per_test_args 573 574 def run_test(self, driver_input, stop_when_done): 575 if not self.started: 576 self.started = True 577 self.pid = TestDriver.next_pid 578 TestDriver.next_pid += 1 579 580 start_time = time.time() 581 test_name = driver_input.test_name 582 test_args = driver_input.args or [] 583 test = self._port._tests[test_name] 584 if test.keyboard: 585 raise KeyboardInterrupt 586 if test.exception: 587 raise ValueError('exception from ' + test_name) 588 if test.device_failure: 589 raise DeviceFailure('device failure in ' + test_name) 590 591 audio = None 592 actual_text = test.actual_text 593 crash = test.crash 594 web_process_crash = test.web_process_crash 595 596 if 'flaky/text.html' in test_name and not test_name in self._port._flakes: 597 self._port._flakes.add(test_name) 598 actual_text = 'flaky text failure' 599 600 if 'crash_then_text.html' in test_name: 601 if test_name in self._port._flakes: 602 actual_text = 'text failure' 603 else: 604 self._port._flakes.add(test_name) 605 crashed_process_name = self._port.driver_name() 606 crashed_pid = 1 607 crash = True 608 609 if 'text_then_crash.html' in test_name: 610 if test_name in self._port._flakes: 611 crashed_process_name = self._port.driver_name() 612 crashed_pid = 1 613 crash = True 614 else: 615 self._port._flakes.add(test_name) 616 actual_text = 'text failure' 617 618 if actual_text and test_args and test_name == 'passes/args.html': 619 actual_text = actual_text + ' ' + ' '.join(test_args) 620 621 if test.actual_audio: 622 audio = base64.b64decode(test.actual_audio) 623 crashed_process_name = None 624 crashed_pid = None 625 if crash: 626 crashed_process_name = self._port.driver_name() 627 crashed_pid = 1 628 elif web_process_crash: 629 crashed_process_name = 'WebProcess' 630 crashed_pid = 2 631 632 crash_log = '' 633 if crashed_process_name: 634 crash_logs = CrashLogs(self._port.host) 635 crash_log = crash_logs.find_newest_log(crashed_process_name, None) or '' 636 637 if stop_when_done: 638 self.stop() 639 640 if test.actual_checksum == driver_input.image_hash: 641 image = None 642 else: 643 image = test.actual_image 644 return DriverOutput(actual_text, image, test.actual_checksum, audio, 645 crash=(crash or web_process_crash), crashed_process_name=crashed_process_name, 646 crashed_pid=crashed_pid, crash_log=crash_log, 647 test_time=time.time() - start_time, timeout=test.timeout, error=test.error, pid=self.pid) 648 649 def stop(self): 650 self.started = False 651