Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """A "Test Server Spawner" that handles killing/stopping per-test test servers. | 5 """A "Test Server Spawner" that handles killing/stopping per-test test servers. |
| 6 | 6 |
| 7 It's used to accept requests from the device to spawn and kill instances of the | 7 It's used to accept requests from the device to spawn and kill instances of the |
| 8 chrome test server on the host. | 8 chrome test server on the host. |
| 9 """ | 9 """ |
| 10 # pylint: disable=W0702 | 10 # pylint: disable=W0702 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 return False | 172 return False |
| 173 | 173 |
| 174 def _GenerateCommandLineArguments(self): | 174 def _GenerateCommandLineArguments(self): |
| 175 """Generates the command line to run the test server. | 175 """Generates the command line to run the test server. |
| 176 | 176 |
| 177 Note that all options are processed by following the definitions in | 177 Note that all options are processed by following the definitions in |
| 178 testserver.py. | 178 testserver.py. |
| 179 """ | 179 """ |
| 180 if self.command_line: | 180 if self.command_line: |
| 181 return | 181 return |
| 182 # The following arguments must exist. | 182 |
| 183 type_cmd = _GetServerTypeCommandLine(self.arguments['server-type']) | 183 args_copy = dict(self.arguments) |
| 184 | |
| 185 # Translate the server type. | |
| 186 type_cmd = _GetServerTypeCommandLine(args_copy.pop('server-type')) | |
| 184 if type_cmd: | 187 if type_cmd: |
| 185 self.command_line.append(type_cmd) | 188 self.command_line.append(type_cmd) |
| 186 self.command_line.append('--port=%d' % self.host_port) | 189 |
| 187 # Use a pipe to get the port given by the instance of Python test server | 190 # Use a pipe to get the port given by the instance of Python test server |
| 188 # if the test does not specify the port. | 191 # if the test does not specify the port. |
| 192 assert self.host_port == args_copy['port'] | |
| 189 if self.host_port == 0: | 193 if self.host_port == 0: |
| 190 (self.pipe_in, self.pipe_out) = os.pipe() | 194 (self.pipe_in, self.pipe_out) = os.pipe() |
| 191 self.command_line.append('--startup-pipe=%d' % self.pipe_out) | 195 self.command_line.append('--startup-pipe=%d' % self.pipe_out) |
| 192 self.command_line.append('--host=%s' % self.arguments['host']) | 196 |
| 193 data_dir = self.arguments['data-dir'] or 'chrome/test/data' | 197 # --data-dir gets mangled. |
| 198 data_dir = args_copy.pop('data-dir') or 'chrome/test/data' | |
| 194 if not os.path.isabs(data_dir): | 199 if not os.path.isabs(data_dir): |
| 195 data_dir = os.path.join(constants.DIR_SOURCE_ROOT, data_dir) | 200 data_dir = os.path.join(constants.DIR_SOURCE_ROOT, data_dir) |
| 196 self.command_line.append('--data-dir=%s' % data_dir) | 201 self.command_line.append('--data-dir=%s' % data_dir) |
| 197 # The following arguments are optional depending on the individual test. | 202 |
| 198 if self.arguments.has_key('log-to-console'): | 203 # Pass the remaining arguments as-is. |
| 199 self.command_line.append('--log-to-console') | 204 for key, values in args_copy.iteritems(): |
| 200 if self.arguments.has_key('auth-token'): | 205 if not isinstance(values, list): |
| 201 self.command_line.append('--auth-token=%s' % self.arguments['auth-token']) | 206 values = [values] |
| 202 if self.arguments.has_key('https'): | 207 for value in values: |
| 203 self.command_line.append('--https') | 208 if value is None: |
|
bulach
2014/04/22 09:09:48
nit: no need for "is None":
if value:
self.comma
davidben
2014/04/22 16:23:13
That would probably cause troubles if value is 0.
| |
| 204 if self.arguments.has_key('cert-and-key-file'): | 209 self.command_line.append('--%s' % key) |
|
bulach
2014/04/22 09:09:48
nit: just want to point out: these arguments would
davidben
2014/04/22 16:23:13
The C++ side contains that logic anyway. It should
| |
| 205 self.command_line.append('--cert-and-key-file=%s' % os.path.join( | 210 else: |
| 206 constants.DIR_SOURCE_ROOT, self.arguments['cert-and-key-file'])) | 211 self.command_line.append('--%s=%s' % (key, value)) |
| 207 if self.arguments.has_key('ocsp'): | |
| 208 self.command_line.append('--ocsp=%s' % self.arguments['ocsp']) | |
| 209 if self.arguments.has_key('https-record-resume'): | |
| 210 self.command_line.append('--https-record-resume') | |
| 211 if self.arguments.has_key('ssl-client-auth'): | |
| 212 self.command_line.append('--ssl-client-auth') | |
| 213 if self.arguments.has_key('tls-intolerant'): | |
| 214 self.command_line.append('--tls-intolerant=%s' % | |
| 215 self.arguments['tls-intolerant']) | |
| 216 if self.arguments.has_key('ssl-client-ca'): | |
| 217 for ca in self.arguments['ssl-client-ca']: | |
| 218 self.command_line.append('--ssl-client-ca=%s' % | |
| 219 os.path.join(constants.DIR_SOURCE_ROOT, ca)) | |
| 220 if self.arguments.has_key('ssl-bulk-cipher'): | |
| 221 for bulk_cipher in self.arguments['ssl-bulk-cipher']: | |
| 222 self.command_line.append('--ssl-bulk-cipher=%s' % bulk_cipher) | |
| 223 | 212 |
| 224 def _CloseUnnecessaryFDsForTestServerProcess(self): | 213 def _CloseUnnecessaryFDsForTestServerProcess(self): |
| 225 # This is required to avoid subtle deadlocks that could be caused by the | 214 # This is required to avoid subtle deadlocks that could be caused by the |
| 226 # test server child process inheriting undesirable file descriptors such as | 215 # test server child process inheriting undesirable file descriptors such as |
| 227 # file lock file descriptors. | 216 # file lock file descriptors. |
| 228 for fd in xrange(0, 1024): | 217 for fd in xrange(0, 1024): |
| 229 if fd != self.pipe_out: | 218 if fd != self.pipe_out: |
| 230 try: | 219 try: |
| 231 os.close(fd) | 220 os.close(fd) |
| 232 except: | 221 except: |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 | 419 |
| 431 def CleanupState(self): | 420 def CleanupState(self): |
| 432 """Cleans up the spawning server state. | 421 """Cleans up the spawning server state. |
| 433 | 422 |
| 434 This should be called if the test server spawner is reused, | 423 This should be called if the test server spawner is reused, |
| 435 to avoid sharing the test server instance. | 424 to avoid sharing the test server instance. |
| 436 """ | 425 """ |
| 437 if self.server.test_server_instance: | 426 if self.server.test_server_instance: |
| 438 self.server.test_server_instance.Stop() | 427 self.server.test_server_instance.Stop() |
| 439 self.server.test_server_instance = None | 428 self.server.test_server_instance = None |
| OLD | NEW |