• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2011 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
29import unittest
30
31from webkitpy.common.system import executive_mock
32from webkitpy.common.system import filesystem_mock
33
34from webkitpy.layout_tests.port import chromium_linux
35from webkitpy.layout_tests.port import port_testcase
36
37
38class ChromiumLinuxPortTest(port_testcase.PortTestCase):
39    def port_maker(self, platform):
40        if platform != 'linux':
41            return None
42        return chromium_linux.ChromiumLinuxPort
43
44    def assert_architecture(self, port_name=None, file_output=None,
45                            expected_architecture=None):
46        filesystem = filesystem_mock.MockFileSystem()
47        filesystem.exists = lambda x: 'DumpRenderTree' in x
48        executive = None
49        if file_output:
50            executive = executive_mock.MockExecutive2(file_output)
51
52        port = chromium_linux.ChromiumLinuxPort(port_name=port_name,
53            executive=executive, filesystem=filesystem)
54        self.assertEquals(port.architecture(), expected_architecture)
55        if expected_architecture == 'x86':
56            self.assertTrue(port.baseline_path().endswith('chromium-linux'))
57            self.assertTrue(port.baseline_search_path()[0].endswith('chromium-linux'))
58        else:
59            self.assertTrue(port.baseline_path().endswith('chromium-linux-x86_64'))
60            self.assertTrue(port.baseline_search_path()[0].endswith('chromium-linux-x86_64'))
61            self.assertTrue(port.baseline_search_path()[1].endswith('chromium-linux'))
62
63    def test_architectures(self):
64        self.assert_architecture(port_name='chromium-linux-x86',
65                                 expected_architecture='x86')
66        self.assert_architecture(port_name='chromium-linux-x86_64',
67                                 expected_architecture='x86_64')
68        self.assert_architecture(file_output='ELF 32-bit LSB executable',
69                                 expected_architecture='x86')
70        self.assert_architecture(file_output='ELF 64-bit LSB executable',
71                                 expected_architecture='x86_64')
72
73    def test_check_illegal_port_names(self):
74        # FIXME: Check that, for now, these are illegal port names.
75        # Eventually we should be able to do the right thing here.
76        self.assertRaises(AssertionError, chromium_linux.ChromiumLinuxPort,
77                          port_name='chromium-x86-linux')
78        self.assertRaises(AssertionError, chromium_linux.ChromiumLinuxPort,
79                          port_name='chromium-linux-x86-gpu')
80
81    def test_determine_architecture_fails(self):
82        # Test that we default to 'x86' if the driver doesn't exist.
83        filesystem = filesystem_mock.MockFileSystem()
84        port = chromium_linux.ChromiumLinuxPort(filesystem=filesystem)
85        self.assertEquals(port.architecture(), 'x86')
86
87        # Test that we default to 'x86' on an unknown architecture.
88        filesystem = filesystem_mock.MockFileSystem()
89        filesystem.exists = lambda x: True
90        executive = executive_mock.MockExecutive2('win32')
91        port = chromium_linux.ChromiumLinuxPort(filesystem=filesystem,
92                                                executive=executive)
93        self.assertEquals(port.architecture(), 'x86')
94
95        # Test that we raise errors if something weird happens.
96        filesystem = filesystem_mock.MockFileSystem()
97        filesystem.exists = lambda x: True
98        executive = executive_mock.MockExecutive2(exception=AssertionError)
99        self.assertRaises(AssertionError, chromium_linux.ChromiumLinuxPort,
100                          filesystem=filesystem, executive=executive)
101
102
103if __name__ == '__main__':
104    unittest.main()
105