Home | History | Annotate | Download | only in port
      1 #!/usr/bin/env python
      2 # Copyright (C) 2010 Google Inc. All rights reserved.
      3 #
      4 # Redistribution and use in source and binary forms, with or without
      5 # modification, are permitted provided that the following conditions are
      6 # met:
      7 #
      8 #     * Redistributions of source code must retain the above copyright
      9 # notice, this list of conditions and the following disclaimer.
     10 #     * Redistributions in binary form must reproduce the above
     11 # copyright notice, this list of conditions and the following disclaimer
     12 # in the documentation and/or other materials provided with the
     13 # distribution.
     14 #     * Neither the name of Google Inc. nor the names of its
     15 # contributors may be used to endorse or promote products derived from
     16 # this software without specific prior written permission.
     17 #
     18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 """Chromium Win implementation of the Port interface."""
     31 
     32 import logging
     33 import sys
     34 
     35 import chromium
     36 
     37 _log = logging.getLogger("webkitpy.layout_tests.port.chromium_win")
     38 
     39 
     40 def os_version(windows_version=None):
     41     if not windows_version:
     42         if hasattr(sys, 'getwindowsversion'):
     43             windows_version = tuple(sys.getwindowsversion()[:2])
     44         else:
     45             # Make up something for testing.
     46             windows_version = (5, 1)
     47 
     48     version_strings = {
     49         (6, 1): 'win7',
     50         (6, 0): 'vista',
     51         (5, 1): 'xp',
     52     }
     53     return version_strings[windows_version]
     54 
     55 
     56 class ChromiumWinPort(chromium.ChromiumPort):
     57     """Chromium Win implementation of the Port class."""
     58     # FIXME: Figure out how to unify this with base.TestConfiguration.all_systems()?
     59     SUPPORTED_VERSIONS = ('xp', 'vista', 'win7')
     60 
     61     # FIXME: Do we need mac-snowleopard here, like the base win port?
     62     FALLBACK_PATHS = {
     63         'xp': ['chromium-win-xp', 'chromium-win-vista', 'chromium-win', 'chromium', 'win', 'mac'],
     64         'vista': ['chromium-win-vista', 'chromium-win', 'chromium', 'win', 'mac'],
     65         'win7': ['chromium-win', 'chromium', 'win', 'mac'],
     66     }
     67 
     68     def __init__(self, port_name=None, windows_version=None, **kwargs):
     69         # We're a little generic here because this code is reused by the
     70         # 'google-chrome' port as well as the 'mock-' and 'dryrun-' ports.
     71         port_name = port_name or 'chromium-win'
     72         chromium.ChromiumPort.__init__(self, port_name=port_name, **kwargs)
     73         if port_name.endswith('-win'):
     74             self._version = os_version(windows_version)
     75             self._name = port_name + '-' + self._version
     76         else:
     77             self._version = port_name[port_name.index('-win-') + 5:]
     78             assert self._version in self.SUPPORTED_VERSIONS
     79 
     80         self._operating_system = 'win'
     81 
     82     def setup_environ_for_server(self):
     83         env = chromium.ChromiumPort.setup_environ_for_server(self)
     84         # Put the cygwin directory first in the path to find cygwin1.dll.
     85         env["PATH"] = "%s;%s" % (
     86             self.path_from_chromium_base("third_party", "cygwin", "bin"),
     87             env["PATH"])
     88         # Configure the cygwin directory so that pywebsocket finds proper
     89         # python executable to run cgi program.
     90         env["CYGWIN_PATH"] = self.path_from_chromium_base(
     91             "third_party", "cygwin", "bin")
     92         if (sys.platform in ("cygwin", "win32") and self.get_option('register_cygwin')):
     93             setup_mount = self.path_from_chromium_base("third_party",
     94                                                        "cygwin",
     95                                                        "setup_mount.bat")
     96             self._executive.run_command([setup_mount])
     97         return env
     98 
     99     def baseline_path(self):
    100         if self.version() == 'win7':
    101             # Win 7 is the newest version of windows, so it gets the base dir.
    102             return self._webkit_baseline_path('chromium-win')
    103         return self._webkit_baseline_path(self.name())
    104 
    105     def baseline_search_path(self):
    106         port_names = self.FALLBACK_PATHS[self.version()]
    107         return map(self._webkit_baseline_path, port_names)
    108 
    109     def check_build(self, needs_http):
    110         result = chromium.ChromiumPort.check_build(self, needs_http)
    111         if not result:
    112             _log.error('For complete Windows build requirements, please '
    113                        'see:')
    114             _log.error('')
    115             _log.error('    http://dev.chromium.org/developers/how-tos/'
    116                        'build-instructions-windows')
    117         return result
    118 
    119     def relative_test_filename(self, filename):
    120         path = filename[len(self.layout_tests_dir()) + 1:]
    121         return path.replace('\\', '/')
    122 
    123     #
    124     # PROTECTED ROUTINES
    125     #
    126     def _build_path(self, *comps):
    127         if self.get_option('build_directory'):
    128             return self._filesystem.join(self.get_option('build_directory'),
    129                                          *comps)
    130 
    131         p = self.path_from_chromium_base('webkit', *comps)
    132         if self._filesystem.exists(p):
    133             return p
    134         p = self.path_from_chromium_base('chrome', *comps)
    135         if self._filesystem.exists(p):
    136             return p
    137         return self._filesystem.join(self.path_from_webkit_base(), 'Source', 'WebKit', 'chromium', *comps)
    138 
    139     def _lighttpd_path(self, *comps):
    140         return self.path_from_chromium_base('third_party', 'lighttpd', 'win',
    141                                             *comps)
    142 
    143     def _path_to_apache(self):
    144         return self.path_from_chromium_base('third_party', 'cygwin', 'usr',
    145                                             'sbin', 'httpd')
    146 
    147     def _path_to_apache_config_file(self):
    148         return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf', 'cygwin-httpd.conf')
    149 
    150     def _path_to_lighttpd(self):
    151         return self._lighttpd_path('LightTPD.exe')
    152 
    153     def _path_to_lighttpd_modules(self):
    154         return self._lighttpd_path('lib')
    155 
    156     def _path_to_lighttpd_php(self):
    157         return self._lighttpd_path('php5', 'php-cgi.exe')
    158 
    159     def _path_to_driver(self, configuration=None):
    160         if not configuration:
    161             configuration = self.get_option('configuration')
    162         binary_name = 'DumpRenderTree.exe'
    163         return self._build_path(configuration, binary_name)
    164 
    165     def _path_to_helper(self):
    166         binary_name = 'LayoutTestHelper.exe'
    167         return self._build_path(self.get_option('configuration'), binary_name)
    168 
    169     def _path_to_image_diff(self):
    170         binary_name = 'ImageDiff.exe'
    171         return self._build_path(self.get_option('configuration'), binary_name)
    172 
    173     def _path_to_wdiff(self):
    174         return self.path_from_chromium_base('third_party', 'cygwin', 'bin',
    175                                             'wdiff.exe')
    176 
    177     def _shut_down_http_server(self, server_pid):
    178         """Shut down the lighttpd web server. Blocks until it's fully
    179         shut down.
    180 
    181         Args:
    182             server_pid: The process ID of the running server.
    183         """
    184         # FIXME: Why are we ignoring server_pid and calling
    185         # _kill_all instead of Executive.kill_process(pid)?
    186         self._executive.kill_all("LightTPD.exe")
    187         self._executive.kill_all("httpd.exe")
    188