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

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

Issue 159713010: Clean up the webkitpy.layout_tests.servers.pywebsocket implementation. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
« no previous file with comments | « Tools/Scripts/run-blink-websocketserver ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 PyWebSocket server used by layout tests.""" 29 """A class to help start/stop the PyWebSocket server as used by the layout tests ."""
30 30
31 import logging 31 import logging
32 import os 32 import os
33 import sys 33 import sys
34 import time 34 import time
35 35
36 from webkitpy.layout_tests.servers import server_base 36 from webkitpy.layout_tests.servers import server_base
37 from webkitpy.thirdparty import mod_pywebsocket
37 38
38 _log = logging.getLogger(__name__) 39 _log = logging.getLogger(__name__)
39 40
40 41
41 _WS_LOG_PREFIX = 'pywebsocket.ws.log-' 42 _WS_LOG_PREFIX = 'pywebsocket.ws.log-'
42 _WSS_LOG_PREFIX = 'pywebsocket.wss.log-'
43
44 43
45 _DEFAULT_WS_PORT = 8880 44 _DEFAULT_WS_PORT = 8880
46 _DEFAULT_WSS_PORT = 9323
47 45
48 46
49 class PyWebSocket(server_base.ServerBase): 47 class PyWebSocket(server_base.ServerBase):
50 def __init__(self, port_obj, output_dir, port=_DEFAULT_WS_PORT, 48
51 root=None, use_tls=False, 49 def __init__(self, port_obj, output_dir, additional_dirs=None):
52 private_key=None, certificate=None, ca_certificate=None,
53 pidfile=None):
54 """Args:
55 output_dir: the absolute path to the layout test result directory
56 """
57 super(PyWebSocket, self).__init__(port_obj, output_dir) 50 super(PyWebSocket, self).__init__(port_obj, output_dir)
58 self._pid_file = pidfile
59 self._process = None
60
61 self._port = port
62 self._root = root
63 self._use_tls = use_tls
64
65 self._name = 'pywebsocket' 51 self._name = 'pywebsocket'
66 self._log_prefixes = (_WS_LOG_PREFIX,) 52 self._log_prefixes = (_WS_LOG_PREFIX,)
67 if self._use_tls: 53 self._mappings = [{'port': _DEFAULT_WS_PORT}]
68 self._name = 'pywebsocket_secure' 54 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se lf._name)
69 self._log_prefixes = (_WSS_LOG_PREFIX,)
70 55
71 # Self generated certificate for SSL server (for client cert get 56 self._port = _DEFAULT_WS_PORT
72 # <base-path>\chrome\test\data\ssl\certs\root_ca_cert.crt) 57 self._layout_tests = self._port_obj.layout_tests_dir()
73 self._pem_file = os.path.join( 58 self._web_socket_tests = self._filesystem.join(self._layout_tests, 'http ', 'tests', 'websocket')
74 os.path.dirname(os.path.abspath(__file__)), 'httpd2.pem') 59 time_str = time.strftime('%d%b%Y-%H%M%S')
60 log_file_name = _WS_LOG_PREFIX + time_str
61 error_log = self._filesystem.join(self._output_dir, log_file_name + "-er r.txt")
62 pywebsocket_base = self._port_obj.path_from_webkit_base('Tools', 'Script s', 'webkitpy', 'thirdparty')
63 pywebsocket_script = self._filesystem.join(pywebsocket_base, 'mod_pywebs ocket', 'standalone.py')
75 64
76 if private_key: 65 self._start_cmd = [
77 self._private_key = private_key 66 sys.executable, '-u', pywebsocket_script,
78 else:
79 self._private_key = self._pem_file
80 if certificate:
81 self._certificate = certificate
82 else:
83 self._certificate = self._pem_file
84 self._ca_certificate = ca_certificate
85 if self._port:
86 self._port = int(self._port)
87 self._mappings = [{'port': self._port}]
88
89 if not self._pid_file:
90 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % self._name)
91
92 # Webkit tests
93 # FIXME: This is the wrong way to detect if we're in Chrome vs. WebKit!
94 # The port objects are supposed to abstract this.
95 if self._root:
96 self._layout_tests = self._filesystem.abspath(self._root)
97 self._web_socket_tests = self._filesystem.abspath(self._filesystem.j oin(self._root, 'http', 'tests', 'websocket'))
98 else:
99 try:
100 self._layout_tests = self._port_obj.layout_tests_dir()
101 self._web_socket_tests = self._filesystem.join(self._layout_test s, 'http', 'tests', 'websocket')
102 except:
103 self._web_socket_tests = None
104
105 if self._use_tls:
106 self._log_prefix = _WSS_LOG_PREFIX
107 else:
108 self._log_prefix = _WS_LOG_PREFIX
109
110 def _prepare_config(self):
111 time_str = time.strftime('%d%b%Y-%H%M%S')
112 log_file_name = self._log_prefix + time_str
113 # FIXME: Doesn't Executive have a devnull, so that we don't have to use os.devnull directly?
114
115 error_log = self._filesystem.join(self._output_dir, log_file_name + "-er r.txt")
116
117 from webkitpy.thirdparty import mod_pywebsocket
118 python_interp = sys.executable
119 # FIXME: Use self._filesystem.path_to_module(self.__module__) instead of __file__
120 # I think this is trying to get the chrome directory? Doesn't the port object know that?
121 pywebsocket_base = self._filesystem.join(self._filesystem.dirname(self._ filesystem.dirname(self._filesystem.dirname(self._filesystem.abspath(__file__))) ), 'thirdparty')
122 pywebsocket_script = self._filesystem.join(pywebsocket_base, 'mod_pywebs ocket', 'standalone.py')
123 start_cmd = [
124 python_interp, '-u', pywebsocket_script,
125 '--server-host', 'localhost', 67 '--server-host', 'localhost',
126 '--port', str(self._port), 68 '--port', str(self._port),
127 '--document-root', self._web_socket_tests, 69 '--document-root', self._web_socket_tests,
128 '--scan-dir', self._web_socket_tests, 70 '--scan-dir', self._web_socket_tests,
129 '--cgi-paths', '/', 71 '--cgi-paths', '/',
130 '--log-file', error_log, 72 '--log-file', error_log,
131 ] 73 '--websock-handlers-map-file', self._filesystem.join(self._web_socke t_tests, 'handler_map.txt'),
132 74 ]
133 handler_map_file = self._filesystem.join(self._web_socket_tests, 'handle r_map.txt') 75 self._env = self._port_obj.setup_environ_for_server()
134 if self._filesystem.exists(handler_map_file): 76 self._env['PYTHONPATH'] = (pywebsocket_base + os.pathsep + self._env.get ('PYTHONPATH', ''))
135 _log.debug('Using handler_map_file: %s' % handler_map_file)
136 start_cmd.append('--websock-handlers-map-file')
137 start_cmd.append(handler_map_file)
138 else:
139 _log.warning('No handler_map_file found')
140
141 if self._use_tls:
142 start_cmd.extend(['-t', '-k', self._private_key,
143 '-c', self._certificate])
144 if self._ca_certificate:
145 start_cmd.append('--ca-certificate')
146 start_cmd.append(self._ca_certificate)
147
148 self._start_cmd = start_cmd
149 server_name = self._filesystem.basename(pywebsocket_script)
150 self._env = self._port_obj.setup_environ_for_server(server_name)
151 self._env['PYTHONPATH'] = (pywebsocket_base + os.path.pathsep + self._en v.get('PYTHONPATH', ''))
OLDNEW
« no previous file with comments | « Tools/Scripts/run-blink-websocketserver ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698