Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1521)

Side by Side Diff: webkit/tools/layout_tests/layout_package/platform_utils_linux.py

Issue 545145: Move the layout test scripts into a 'webkitpy' subdirectory in preparation... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: try to de-confuse svn and the try bots Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 Linux implementation of the layout_package.platform_utils
6 package. This file should only be imported by that package."""
7
8 import os
9 import signal
10 import subprocess
11 import sys
12 import logging
13
14 import path_utils
15 import platform_utils_win
16
17
18 def PlatformName():
19 """Returns the name of the platform we're currently running on."""
20 return 'chromium-linux' + PlatformVersion()
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 return ''
28
29
30 def GetNumCores():
31 """Returns the number of cores on the machine. For hyperthreaded machines,
32 this will be double the number of actual processors."""
33 num_cores = os.sysconf("SC_NPROCESSORS_ONLN")
34 if isinstance(num_cores, int) and num_cores > 0:
35 return num_cores
36 return 1
37
38
39 def BaselinePath(platform=None):
40 """Returns the path relative to the top of the source tree for the
41 baselines for the specified platform version. If |platform| is None,
42 then the version currently in use is used."""
43 if platform is None:
44 platform = PlatformName()
45 return path_utils.PathFromBase('webkit', 'data', 'layout_tests',
46 'platform', platform, 'LayoutTests')
47
48
49 def BaselineSearchPath(platform=None):
50 """Returns the list of directories to search for baselines/results, in
51 order of preference. Paths are relative to the top of the source tree."""
52 return [BaselinePath(platform),
53 platform_utils_win.BaselinePath('chromium-win'),
54 path_utils.WebKitBaselinePath('win'),
55 path_utils.WebKitBaselinePath('mac')]
56
57
58 def ApacheExecutablePath():
59 """Returns the executable path to start Apache"""
60 path = os.path.join("/usr", "sbin", "apache2")
61 if os.path.exists(path):
62 return path
63 print "Unable to fine Apache executable %s" % path
64 _MissingApache()
65
66
67 def ApacheConfigFilePath():
68 """Returns the path to Apache config file"""
69 return path_utils.PathFromBase("third_party", "WebKit", "LayoutTests",
70 "http", "conf", "apache2-debian-httpd.conf")
71
72
73 def LigHTTPdExecutablePath():
74 """Returns the executable path to start LigHTTPd"""
75 binpath = "/usr/sbin/lighttpd"
76 if os.path.exists(binpath):
77 return binpath
78 print "Unable to find LigHTTPd executable %s" % binpath
79 _MissingLigHTTPd()
80
81
82 def LigHTTPdModulePath():
83 """Returns the library module path for LigHTTPd"""
84 modpath = "/usr/lib/lighttpd"
85 if os.path.exists(modpath):
86 return modpath
87 print "Unable to find LigHTTPd modules %s" % modpath
88 _MissingLigHTTPd()
89
90
91 def LigHTTPdPHPPath():
92 """Returns the PHP executable path for LigHTTPd"""
93 binpath = "/usr/bin/php-cgi"
94 if os.path.exists(binpath):
95 return binpath
96 print "Unable to find PHP CGI executable %s" % binpath
97 _MissingLigHTTPd()
98
99
100 def WDiffPath():
101 """Path to the WDiff executable, which we assume is already installed and
102 in the user's $PATH."""
103 return 'wdiff'
104
105
106 def ImageDiffPath(target):
107 """Path to the image_diff binary.
108
109 Args:
110 target: Build target mode (debug or release)"""
111 return _PathFromBuildResults(target, 'image_diff')
112
113
114 def LayoutTestHelperPath(target):
115 """Path to the layout_test helper binary, if needed, empty otherwise"""
116 return ''
117
118
119 def TestShellPath(target):
120 """Return the platform-specific binary path for our TestShell.
121
122 Args:
123 target: Build target mode (debug or release) """
124 if target in ('Debug', 'Release'):
125 try:
126 debug_path = _PathFromBuildResults('Debug', 'test_shell')
127 release_path = _PathFromBuildResults('Release', 'test_shell')
128
129 debug_mtime = os.stat(debug_path).st_mtime
130 release_mtime = os.stat(release_path).st_mtime
131
132 if debug_mtime > release_mtime and target == 'Release' or \
133 release_mtime > debug_mtime and target == 'Debug':
134 logging.info('\x1b[31mWarning: you are not running the most '
135 'recent test_shell binary. You need to pass '
136 '--debug or not to select between Debug and '
137 'Release.\x1b[0m')
138 # This will fail if we don't have both a debug and release binary.
139 # That's fine because, in this case, we must already be running the
140 # most up-to-date one.
141 except path_utils.PathNotFound:
142 pass
143
144 return _PathFromBuildResults(target, 'test_shell')
145
146
147 def FuzzyMatchPath():
148 """Return the path to the fuzzy matcher binary."""
149 return path_utils.PathFromBase('third_party', 'fuzzymatch', 'fuzzymatch')
150
151
152 def ShutDownHTTPServer(server_pid):
153 """Shut down the lighttpd web server. Blocks until it's fully shut down.
154
155 Args:
156 server_pid: The process ID of the running server.
157 """
158 # server_pid is not set when "http_server.py stop" is run manually.
159 if server_pid is None:
160 # This isn't ideal, since it could conflict with web server processes
161 # not started by http_server.py, but good enough for now.
162 KillAllProcess('lighttpd')
163 KillAllProcess('apache2')
164 else:
165 try:
166 os.kill(server_pid, signal.SIGTERM)
167 #TODO(mmoss) Maybe throw in a SIGKILL just to be sure?
168 except OSError:
169 # Sometimes we get a bad PID (e.g. from a stale httpd.pid file),
170 # so if kill fails on the given PID, just try to 'killall' web
171 # servers.
172 ShutDownHTTPServer(None)
173
174
175 def KillProcess(pid):
176 """Forcefully kill the process.
177
178 Args:
179 pid: The id of the process to be killed.
180 """
181 os.kill(pid, signal.SIGKILL)
182
183
184 def KillAllProcess(process_name):
185 null = open(os.devnull)
186 subprocess.call(['killall', '-TERM', '-u', os.getenv('USER'),
187 process_name], stderr=null)
188 null.close()
189
190
191 def KillAllTestShells():
192 """Kills all instances of the test_shell binary currently running."""
193 KillAllProcess('test_shell')
194
195 #
196 # Private helper functions
197 #
198
199
200 def _MissingLigHTTPd():
201 print 'Please install using: "sudo apt-get install lighttpd php5-cgi"'
202 print 'For complete Linux build requirements, please see:'
203 print 'http://code.google.com/p/chromium/wiki/LinuxBuildInstructions'
204 sys.exit(1)
205
206
207 def _MissingApache():
208 print ('Please install using: "sudo apt-get install apache2 '
209 'libapache2-mod-php5"')
210 print 'For complete Linux build requirements, please see:'
211 print 'http://code.google.com/p/chromium/wiki/LinuxBuildInstructions'
212 sys.exit(1)
213
214
215 def _PathFromBuildResults(*pathies):
216 # FIXME(dkegel): use latest or warn if more than one found?
217 for dir in ["sconsbuild", "out", "xcodebuild"]:
218 try:
219 return path_utils.PathFromBase(dir, *pathies)
220 except:
221 pass
222 raise path_utils.PathNotFound("Unable to find %s in build tree" %
223 (os.path.join(*pathies)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698