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

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/servers/lighttpd.py

Issue 146173004: Fix run-blink-httpd to work w/ Apache and refactor webkitpy.layout_tests.servers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add cli_wrapper and update run-* scripts Created 6 years, 10 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
1 # Copyright (C) 2011 Google Inc. All rights reserved. 1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the 11 # in the documentation and/or other materials provided with the
12 # distribution. 12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its 13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from 14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission. 15 # this software without specific prior written permission.
16 # 16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 """A class to help start/stop the lighttpd server used by layout tests.""" 29 """Start and stop the lighttpd server as it is used by the layout tests."""
30 30
31 import logging 31 import logging
32 import os 32 import os
33 import time 33 import time
34 34
35 from webkitpy.layout_tests.servers import http_server_base 35 from webkitpy.layout_tests.servers import server_base
36 36
37 37
38 _log = logging.getLogger(__name__) 38 _log = logging.getLogger(__name__)
39 39
40 40
41 class Lighttpd(http_server_base.HttpServerBase): 41 class Lighttpd(server_base.ServerBase):
42 42
43 def __init__(self, port_obj, output_dir, background=False, port=None, 43 def __init__(self, port_obj, output_dir):
44 root=None, run_background=None, additional_dirs=None, 44 super(Lighttpd, self).__init__(port_obj, output_dir)
45 layout_tests_dir=None, number_of_servers=None):
46 """Args:
47 output_dir: the absolute path to the layout test result directory
48 """
49 # Webkit tests
50 http_server_base.HttpServerBase.__init__(self, port_obj, number_of_serve rs)
51 self._name = 'lighttpd' 45 self._name = 'lighttpd'
52 self._output_dir = output_dir 46 self._log_prefixes = ('access.log-', 'error.log-')
53 self._port = port
54 self._root = root
55 self._run_background = run_background
56 self._additional_dirs = additional_dirs
57 self._layout_tests_dir = layout_tests_dir
58
59 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se lf._name) 47 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se lf._name)
60 48
61 if self._port: 49 self._layout_tests_dir = self._port_obj.layout_tests_dir()
62 self._port = int(self._port)
63
64 if not self._layout_tests_dir:
65 self._layout_tests_dir = self._port_obj.layout_tests_dir()
66 50
67 self._webkit_tests = os.path.join(self._layout_tests_dir, 'http', 'tests ') 51 self._webkit_tests = os.path.join(self._layout_tests_dir, 'http', 'tests ')
68 self._js_test_resource = os.path.join(self._layout_tests_dir, 'resources ') 52 self._js_test_resource = os.path.join(self._layout_tests_dir, 'resources ')
69 self._media_resource = os.path.join(self._layout_tests_dir, 'media') 53 self._media_resource = os.path.join(self._layout_tests_dir, 'media')
70 54
71 # Self generated certificate for SSL server (for client cert get 55 # Self generated certificate for SSL server (for client cert get
72 # <base-path>\chrome\test\data\ssl\certs\root_ca_cert.crt) 56 # <base-path>\chrome\test\data\ssl\certs\root_ca_cert.crt)
73 self._pem_file = os.path.join( 57 self._pem_file = os.path.join(
74 os.path.dirname(os.path.abspath(__file__)), 'httpd2.pem') 58 os.path.dirname(os.path.abspath(__file__)), 'httpd2.pem')
75 59
76 # One mapping where we can get to everything 60 self.mappings = [
77 self.VIRTUALCONFIG = [] 61 {'port': 8000, 'docroot': self._webkit_tests},
78 62 {'port': 8080, 'docroot': self._webkit_tests},
79 if self._webkit_tests: 63 {'port': 8443, 'docroot': self._webkit_tests, 'sslcert': self._pem_f ile},
80 self.VIRTUALCONFIG.extend( 64 ]
81 # Three mappings (one with SSL) for LayoutTests http tests
82 [{'port': 8000, 'docroot': self._webkit_tests},
83 {'port': 8080, 'docroot': self._webkit_tests},
84 {'port': 8443, 'docroot': self._webkit_tests,
85 'sslcert': self._pem_file}])
86 65
87 def _prepare_config(self): 66 def _prepare_config(self):
88 base_conf_file = self._port_obj.path_from_webkit_base('Tools', 67 base_conf_file = self._port_obj.path_from_webkit_base('Tools',
89 'Scripts', 'webkitpy', 'layout_tests', 'servers', 'lighttpd.conf') 68 'Scripts', 'webkitpy', 'layout_tests', 'servers', 'lighttpd.conf')
90 out_conf_file = os.path.join(self._output_dir, 'lighttpd.conf') 69 out_conf_file = os.path.join(self._output_dir, 'lighttpd.conf')
91 time_str = time.strftime("%d%b%Y-%H%M%S") 70 time_str = time.strftime("%d%b%Y-%H%M%S")
92 access_file_name = "access.log-" + time_str + ".txt" 71 access_file_name = "access.log-" + time_str + ".txt"
93 access_log = os.path.join(self._output_dir, access_file_name) 72 access_log = os.path.join(self._output_dir, access_file_name)
94 log_file_name = "error.log-" + time_str + ".txt" 73 log_file_name = "error.log-" + time_str + ".txt"
95 error_log = os.path.join(self._output_dir, log_file_name) 74 error_log = os.path.join(self._output_dir, log_file_name)
(...skipping 21 matching lines...) Expand all
117 96
118 # Setup upload folders. Upload folder is to hold temporary upload files 97 # Setup upload folders. Upload folder is to hold temporary upload files
119 # and also POST data. This is used to support XHR layout tests that 98 # and also POST data. This is used to support XHR layout tests that
120 # does POST. 99 # does POST.
121 f.write(('server.upload-dirs = ( "%s" )\n\n') % (self._output_dir)) 100 f.write(('server.upload-dirs = ( "%s" )\n\n') % (self._output_dir))
122 101
123 # Setup a link to where the js test templates are stored 102 # Setup a link to where the js test templates are stored
124 f.write(('alias.url = ( "/js-test-resources" => "%s" )\n\n') % 103 f.write(('alias.url = ( "/js-test-resources" => "%s" )\n\n') %
125 (self._js_test_resource)) 104 (self._js_test_resource))
126 105
127 if self._additional_dirs:
128 for alias, path in self._additional_dirs.iteritems():
129 f.write(('alias.url += ( "%s" => "%s" )\n\n') % (alias, path))
130
131 # Setup a link to where the media resources are stored. 106 # Setup a link to where the media resources are stored.
132 f.write(('alias.url += ( "/media-resources" => "%s" )\n\n') % 107 f.write(('alias.url += ( "/media-resources" => "%s" )\n\n') %
133 (self._media_resource)) 108 (self._media_resource))
134 109
135 # dump out of virtual host config at the bottom. 110 # dump out of virtual host config at the bottom.
136 if self._root: 111 for mapping in self.mappings:
137 if self._port:
138 # Have both port and root dir.
139 mappings = [{'port': self._port, 'docroot': self._root}]
140 else:
141 # Have only a root dir - set the ports as for LayoutTests.
142 # This is used in ui_tests to run http tests against a browser.
143
144 # default set of ports as for LayoutTests but with a
145 # specified root.
146 mappings = [{'port': 8000, 'docroot': self._root},
147 {'port': 8080, 'docroot': self._root},
148 {'port': 8443, 'docroot': self._root,
149 'sslcert': self._pem_file}]
150 else:
151 mappings = self.VIRTUALCONFIG
152 for mapping in mappings:
153 ssl_setup = '' 112 ssl_setup = ''
154 if 'sslcert' in mapping: 113 if 'sslcert' in mapping:
155 ssl_setup = (' ssl.engine = "enable"\n' 114 ssl_setup = (' ssl.engine = "enable"\n'
156 ' ssl.pemfile = "%s"\n' % mapping['sslcert']) 115 ' ssl.pemfile = "%s"\n' % mapping['sslcert'])
157 116
158 f.write(('$SERVER["socket"] == "127.0.0.1:%d" {\n' 117 f.write(('$SERVER["socket"] == "127.0.0.1:%d" {\n'
159 ' server.document-root = "%s"\n' + 118 ' server.document-root = "%s"\n' +
160 ssl_setup + 119 ssl_setup +
161 '}\n\n') % (mapping['port'], mapping['docroot'])) 120 '}\n\n') % (mapping['port'], mapping['docroot']))
162 f.close() 121 f.close()
163 122
164 executable = self._port_obj.path_to_lighttpd() 123 executable = self._port_obj.path_to_lighttpd()
165 module_path = self._port_obj.path_to_lighttpd_modules() 124 module_path = self._port_obj.path_to_lighttpd_modules()
166 start_cmd = [executable, 125 start_cmd = [executable,
167 # Newly written config file 126 # Newly written config file
168 '-f', os.path.join(self._output_dir, 'lighttpd.conf'), 127 '-f', os.path.join(self._output_dir, 'lighttpd.conf'),
169 # Where it can find its module dynamic libraries 128 # Where it can find its module dynamic libraries
170 '-m', module_path] 129 '-m', module_path]
171 130
172 if not self._run_background: 131 start_cmd.append('-D')
173 start_cmd.append(# Don't background
174 '-D')
175 132
176 # Copy liblightcomp.dylib to /tmp/lighttpd/lib to work around the 133 # Copy liblightcomp.dylib to /tmp/lighttpd/lib to work around the
177 # bug that mod_alias.so loads it from the hard coded path. 134 # bug that mod_alias.so loads it from the hard coded path.
178 if self._port_obj.host.platform.is_mac(): 135 if self._port_obj.host.platform.is_mac():
179 tmp_module_path = '/tmp/lighttpd/lib' 136 tmp_module_path = '/tmp/lighttpd/lib'
180 if not self._filesystem.exists(tmp_module_path): 137 if not self._filesystem.exists(tmp_module_path):
181 self._filesystem.maybe_make_directory(tmp_module_path) 138 self._filesystem.maybe_make_directory(tmp_module_path)
182 lib_file = 'liblightcomp.dylib' 139 lib_file = 'liblightcomp.dylib'
183 self._filesystem.copyfile(self._filesystem.join(module_path, lib_fil e), 140 self._filesystem.copyfile(self._filesystem.join(module_path, lib_fil e),
184 self._filesystem.join(tmp_module_path, lib _file)) 141 self._filesystem.join(tmp_module_path, lib _file))
185 142
186 self._start_cmd = start_cmd 143 self._start_cmd = start_cmd
187 self._env = self._port_obj.setup_environ_for_server('lighttpd') 144 self._env = self._port_obj.setup_environ_for_server('lighttpd')
188 self._mappings = mappings
189
190 def _remove_stale_logs(self):
191 # Sometimes logs are open in other processes but they should clear event ually.
192 for log_prefix in ('access.log-', 'error.log-'):
193 try:
194 self._remove_log_files(self._output_dir, log_prefix)
195 except OSError, e:
196 _log.warning('Failed to remove old %s %s files' % (self._name, l og_prefix))
197
198 def _spawn_process(self):
199 _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd ))
200 process = self._executive.popen(self._start_cmd, env=self._env, shell=Fa lse, stderr=self._executive.PIPE)
201 pid = process.pid
202 self._filesystem.write_text_file(self._pid_file, str(pid))
203 return pid
204
205 def _stop_running_server(self):
206 # FIXME: It would be nice if we had a cleaner way of killing this proces s.
207 # Currently we throw away the process object created in _spawn_process,
208 # since there doesn't appear to be any way to kill the server any more
209 # cleanly using it than just killing the pid, and we need to support
210 # killing a pid directly anyway for run-webkit-httpd and run-webkit-webs ocketserver.
211 self._wait_for_action(self._check_and_kill)
212 if self._filesystem.exists(self._pid_file):
213 self._filesystem.remove(self._pid_file)
214
215 def _check_and_kill(self):
216 if self._executive.check_running_pid(self._pid):
217 host = self._port_obj.host
218 if host.platform.is_win() and not host.platform.is_cygwin():
219 # FIXME: https://bugs.webkit.org/show_bug.cgi?id=106838
220 # We need to kill all of the child processes as well as the
221 # parent, so we can't use executive.kill_process().
222 #
223 # If this is actually working, we should figure out a clean API.
224 self._executive.run_command(["taskkill.exe", "/f", "/t", "/pid", self._pid], error_handler=self._executive.ignore_error)
225 else:
226 self._executive.kill_process(self._pid)
227 return False
228 return True
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698