OLD | NEW |
| (Empty) |
1 # Copyright (c) 2008-2009 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 """This is the Mac implementation of the layout_package.platform_utils | |
6 package. This file should only be imported by that package.""" | |
7 | |
8 import os | |
9 import platform | |
10 import signal | |
11 import subprocess | |
12 | |
13 import path_utils | |
14 | |
15 | |
16 def PlatformName(): | |
17 """Returns the name of the platform we're currently running on.""" | |
18 # At the moment all chromium mac results are version-independent. At some | |
19 # point we may need to return 'chromium-mac' + PlatformVersion() | |
20 return 'chromium-mac' | |
21 | |
22 | |
23 def PlatformVersion(): | |
24 """Returns the version string for the platform, e.g. '-vista' or | |
25 '-snowleopard'. If the platform does not distinguish between | |
26 minor versions, it returns ''.""" | |
27 os_version_string = platform.mac_ver()[0] # e.g. "10.5.6" | |
28 if not os_version_string: | |
29 return '-leopard' | |
30 | |
31 release_version = int(os_version_string.split('.')[1]) | |
32 | |
33 # we don't support 'tiger' or earlier releases | |
34 if release_version == 5: | |
35 return '-leopard' | |
36 elif release_version == 6: | |
37 return '-snowleopard' | |
38 | |
39 return '' | |
40 | |
41 | |
42 def GetNumCores(): | |
43 """Returns the number of cores on the machine. For hyperthreaded machines, | |
44 this will be double the number of actual processors.""" | |
45 return int(os.popen2("sysctl -n hw.ncpu")[1].read()) | |
46 | |
47 | |
48 def BaselinePath(platform=None): | |
49 """Returns the path relative to the top of the source tree for the | |
50 baselines for the specified platform version. If |platform| is None, | |
51 then the version currently in use is used.""" | |
52 if platform is None: | |
53 platform = PlatformName() | |
54 return path_utils.PathFromBase('webkit', 'data', 'layout_tests', | |
55 'platform', platform, 'LayoutTests') | |
56 | |
57 # TODO: We should add leopard and snowleopard to the list of paths to check | |
58 # once we start running the tests from snowleopard. | |
59 | |
60 | |
61 def BaselineSearchPath(platform=None): | |
62 """Returns the list of directories to search for baselines/results, in | |
63 order of preference. Paths are relative to the top of the source tree.""" | |
64 return [BaselinePath(platform), | |
65 path_utils.WebKitBaselinePath('mac' + PlatformVersion()), | |
66 path_utils.WebKitBaselinePath('mac')] | |
67 | |
68 | |
69 def WDiffPath(): | |
70 """Path to the WDiff executable, which we assume is already installed and | |
71 in the user's $PATH.""" | |
72 return 'wdiff' | |
73 | |
74 | |
75 def ImageDiffPath(target): | |
76 """Path to the image_diff executable | |
77 | |
78 Args: | |
79 target: build type - 'Debug','Release',etc.""" | |
80 return path_utils.PathFromBase('xcodebuild', target, 'image_diff') | |
81 | |
82 | |
83 def LayoutTestHelperPath(target): | |
84 """Path to the layout_test_helper executable, if needed, empty otherwise | |
85 | |
86 Args: | |
87 target: build type - 'Debug','Release',etc.""" | |
88 return path_utils.PathFromBase('xcodebuild', target, 'layout_test_helper') | |
89 | |
90 | |
91 def TestShellPath(target): | |
92 """Path to the test_shell executable. | |
93 | |
94 Args: | |
95 target: build type - 'Debug','Release',etc.""" | |
96 # TODO(pinkerton): make |target| happy with case-sensitive file systems. | |
97 return path_utils.PathFromBase('xcodebuild', target, 'TestShell.app', | |
98 'Contents', 'MacOS', 'TestShell') | |
99 | |
100 | |
101 def ApacheExecutablePath(): | |
102 """Returns the executable path to start Apache""" | |
103 return os.path.join("/usr", "sbin", "httpd") | |
104 | |
105 | |
106 def ApacheConfigFilePath(): | |
107 """Returns the path to Apache config file""" | |
108 return path_utils.PathFromBase("third_party", "WebKit", "LayoutTests", | |
109 "http", "conf", "apache2-httpd.conf") | |
110 | |
111 | |
112 def LigHTTPdExecutablePath(): | |
113 """Returns the executable path to start LigHTTPd""" | |
114 return path_utils.PathFromBase('third_party', 'lighttpd', 'mac', | |
115 'bin', 'lighttpd') | |
116 | |
117 | |
118 def LigHTTPdModulePath(): | |
119 """Returns the library module path for LigHTTPd""" | |
120 return path_utils.PathFromBase('third_party', 'lighttpd', 'mac', 'lib') | |
121 | |
122 | |
123 def LigHTTPdPHPPath(): | |
124 """Returns the PHP executable path for LigHTTPd""" | |
125 return path_utils.PathFromBase('third_party', 'lighttpd', 'mac', 'bin', | |
126 'php-cgi') | |
127 | |
128 | |
129 def ShutDownHTTPServer(server_pid): | |
130 """Shut down the lighttpd web server. Blocks until it's fully shut down. | |
131 | |
132 Args: | |
133 server_pid: The process ID of the running server. | |
134 """ | |
135 # server_pid is not set when "http_server.py stop" is run manually. | |
136 if server_pid is None: | |
137 # TODO(mmoss) This isn't ideal, since it could conflict with lighttpd | |
138 # processes not started by http_server.py, but good enough for now. | |
139 KillAllProcess('lighttpd') | |
140 KillAllProcess('httpd') | |
141 else: | |
142 try: | |
143 os.kill(server_pid, signal.SIGTERM) | |
144 # TODO(mmoss) Maybe throw in a SIGKILL just to be sure? | |
145 except OSError: | |
146 # Sometimes we get a bad PID (e.g. from a stale httpd.pid file), | |
147 # so if kill fails on the given PID, just try to 'killall' web | |
148 # servers. | |
149 ShutDownHTTPServer(None) | |
150 | |
151 | |
152 def KillProcess(pid): | |
153 """Forcefully kill the process. | |
154 | |
155 Args: | |
156 pid: The id of the process to be killed. | |
157 """ | |
158 os.kill(pid, signal.SIGKILL) | |
159 | |
160 | |
161 def KillAllProcess(process_name): | |
162 # On Mac OS X 10.6, killall has a new constraint: -SIGNALNAME or | |
163 # -SIGNALNUMBER must come first. Example problem: | |
164 # $ killall -u $USER -TERM lighttpd | |
165 # killall: illegal option -- T | |
166 # Use of the earlier -TERM placement is just fine on 10.5. | |
167 null = open(os.devnull) | |
168 subprocess.call(['killall', '-TERM', '-u', os.getenv('USER'), | |
169 process_name], stderr=null) | |
170 null.close() | |
171 | |
172 | |
173 def KillAllTestShells(): | |
174 """Kills all instances of the test_shell binary currently running.""" | |
175 KillAllProcess('TestShell') | |
OLD | NEW |