1#!/usr/bin/python 2# Copyright (C) 2010 Google Inc. All rights reserved. 3# Copyright (C) 2010 Gabor Rapcsanyi (rgabor@inf.u-szeged.hu), University of Szeged 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: 8# 9# * Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# * Redistributions in binary form must reproduce the above 12# copyright notice, this list of conditions and the following disclaimer 13# in the documentation and/or other materials provided with the 14# distribution. 15# * Neither the name of Google Inc. nor the names of its 16# contributors may be used to endorse or promote products derived from 17# this software without specific prior written permission. 18# 19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31"""Unit tests for TestRunner().""" 32 33import unittest 34 35from webkitpy.common.system import filesystem_mock 36from webkitpy.thirdparty.mock import Mock 37 38import test_runner 39 40 41class TestRunnerWrapper(test_runner.TestRunner): 42 def _get_test_input_for_file(self, test_file): 43 return test_file 44 45 46class TestRunnerTest(unittest.TestCase): 47 def test_shard_tests(self): 48 # Test that _shard_tests in test_runner.TestRunner really 49 # put the http tests first in the queue. 50 port = Mock() 51 port._filesystem = filesystem_mock.MockFileSystem() 52 runner = TestRunnerWrapper(port=port, options=Mock(), 53 printer=Mock()) 54 55 test_list = [ 56 "LayoutTests/websocket/tests/unicode.htm", 57 "LayoutTests/animations/keyframes.html", 58 "LayoutTests/http/tests/security/view-source-no-refresh.html", 59 "LayoutTests/websocket/tests/websocket-protocol-ignored.html", 60 "LayoutTests/fast/css/display-none-inline-style-change-crash.html", 61 "LayoutTests/http/tests/xmlhttprequest/supported-xml-content-types.html", 62 "LayoutTests/dom/html/level2/html/HTMLAnchorElement03.html", 63 "LayoutTests/ietestcenter/Javascript/11.1.5_4-4-c-1.html", 64 "LayoutTests/dom/html/level2/html/HTMLAnchorElement06.html", 65 ] 66 67 expected_tests_to_http_lock = set([ 68 'LayoutTests/websocket/tests/unicode.htm', 69 'LayoutTests/http/tests/security/view-source-no-refresh.html', 70 'LayoutTests/websocket/tests/websocket-protocol-ignored.html', 71 'LayoutTests/http/tests/xmlhttprequest/supported-xml-content-types.html', 72 ]) 73 74 # FIXME: Ideally the HTTP tests don't have to all be in one shard. 75 single_thread_results = runner._shard_tests(test_list, False) 76 multi_thread_results = runner._shard_tests(test_list, True) 77 78 self.assertEqual("tests_to_http_lock", single_thread_results[0][0]) 79 self.assertEqual(expected_tests_to_http_lock, set(single_thread_results[0][1])) 80 self.assertEqual("tests_to_http_lock", multi_thread_results[0][0]) 81 self.assertEqual(expected_tests_to_http_lock, set(multi_thread_results[0][1])) 82 83 84if __name__ == '__main__': 85 unittest.main() 86