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 32import os 33import platform 34import signal 35import subprocess 36import sys 37 38import chromium 39 40 41class ChromiumWinPort(chromium.ChromiumPort): 42 """Chromium Win implementation of the Port class.""" 43 44 def __init__(self, port_name=None, options=None): 45 if port_name is None: 46 port_name = 'chromium-win' + self.version() 47 chromium.ChromiumPort.__init__(self, port_name, options) 48 49 def baseline_search_path(self): 50 dirs = [] 51 if self._name == 'chromium-win-xp': 52 dirs.append(self._chromium_baseline_path(self._name)) 53 if self._name in ('chromium-win-xp', 'chromium-win-vista'): 54 dirs.append(self._chromium_baseline_path('chromium-win-vista')) 55 dirs.append(self._chromium_baseline_path('chromium-win')) 56 dirs.append(self._webkit_baseline_path('win')) 57 dirs.append(self._webkit_baseline_path('mac')) 58 return dirs 59 60 def check_sys_deps(self): 61 # TODO(dpranke): implement this 62 return True 63 64 def get_absolute_path(self, filename): 65 """Return the absolute path in unix format for the given filename.""" 66 abspath = os.path.abspath(filename) 67 return abspath.replace('\\', '/') 68 69 def num_cores(self): 70 return int(os.environ.get('NUMBER_OF_PROCESSORS', 1)) 71 72 def relative_test_filename(self, filename): 73 path = filename[len(self.layout_tests_dir()) + 1:] 74 return path.replace('\\', '/') 75 76 def test_platform_name(self): 77 # We return 'win-xp', not 'chromium-win-xp' here, for convenience. 78 return 'win' + self.version() 79 80 def version(self): 81 winver = sys.getwindowsversion() 82 if winver[0] == 6 and (winver[1] == 1): 83 return '-7' 84 if winver[0] == 6 and (winver[1] == 0): 85 return '-vista' 86 if winver[0] == 5 and (winver[1] == 1 or winver[1] == 2): 87 return '-xp' 88 return '' 89 90 # 91 # PROTECTED ROUTINES 92 # 93 94 def _build_path(self, *comps): 95 # FIXME(dpranke): allow for builds under 'chrome' as well. 96 return self.path_from_chromium_base('webkit', self._options.target, 97 *comps) 98 99 def _lighttpd_path(self, *comps): 100 return self.path_from_chromium_base('third_party', 'lighttpd', 'win', 101 *comps) 102 103 def _kill_process(self, pid): 104 """Forcefully kill the process. 105 106 Args: 107 pid: The id of the process to be killed. 108 """ 109 subprocess.call(('taskkill.exe', '/f', '/pid', str(pid)), 110 stdout=subprocess.PIPE, 111 stderr=subprocess.PIPE) 112 113 def _path_to_apache(self): 114 return self.path_from_chromium_base('third_party', 'cygwin', 'usr', 115 'sbin', 'httpd') 116 117 def _path_to_apache_config_file(self): 118 return os.path.join(self.layout_tests_dir(), 'http', 'conf', 119 'cygwin-httpd.conf') 120 121 def _path_to_lighttpd(self): 122 return self._lighttpd_path('LightTPD.exe') 123 124 def _path_to_lighttpd_modules(self): 125 return self._lighttpd_path('lib') 126 127 def _path_to_lighttpd_php(self): 128 return self._lighttpd_path('php5', 'php-cgi.exe') 129 130 def _path_to_driver(self): 131 return self._build_path('test_shell.exe') 132 133 def _path_to_helper(self): 134 return self._build_path('layout_test_helper.exe') 135 136 def _path_to_image_diff(self): 137 return self._build_path('image_diff.exe') 138 139 def _path_to_wdiff(self): 140 return self.path_from_chromium_base('third_party', 'cygwin', 'bin', 141 'wdiff.exe') 142 143 def _shut_down_http_server(self, server_pid): 144 """Shut down the lighttpd web server. Blocks until it's fully 145 shut down. 146 147 Args: 148 server_pid: The process ID of the running server. 149 """ 150 subprocess.Popen(('taskkill.exe', '/f', '/im', 'LightTPD.exe'), 151 stdout=subprocess.PIPE, 152 stderr=subprocess.PIPE).wait() 153 subprocess.Popen(('taskkill.exe', '/f', '/im', 'httpd.exe'), 154 stdout=subprocess.PIPE, 155 stderr=subprocess.PIPE).wait() 156