OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 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 """Start and stop the WPTserve servers as they're used by the layout tests.""" |
| 6 |
| 7 import logging |
| 8 import os |
| 9 import socket |
| 10 |
| 11 from webkitpy.layout_tests.servers import server_base |
| 12 |
| 13 |
| 14 _log = logging.getLogger(__name__) |
| 15 |
| 16 |
| 17 class WPTServeHTTP(server_base.ServerBase): |
| 18 def __init__(self, port_obj, output_dir): |
| 19 super(WPTServeHTTP, self).__init__(port_obj, output_dir) |
| 20 # TODO(burnik): This should be the only place where we set up the ports. |
| 21 secure_port, insecure_port = (8001, 8444) |
| 22 self._name = 'wptserve' |
| 23 self._log_prefixes = ('access_log', 'error_log') |
| 24 self._mappings = [{'port': secure_port}, |
| 25 {'port': insecure_port, 'sslcert': True}] |
| 26 |
| 27 # TODO(burnik): We can probably avoid PID files for WPT in the future. |
| 28 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se
lf._name) |
| 29 |
| 30 script_path = os.path.dirname(os.path.abspath(__file__)) |
| 31 self._path_to_wpt = os.path.abspath(os.path.join(script_path, "wpt_suppo
rt", "wpt")) |
| 32 self._executable = os.path.join(self._path_to_wpt, "serve") |
| 33 self._path_to_wpt_config = os.path.join(self._path_to_wpt, "config.json"
) |
| 34 self._path_to_wpt_tests = os.path.abspath(os.path.join(self._port_obj.la
yout_tests_dir(), |
| 35 "imported", "web-
platform-tests")) |
| 36 self._wpt_config = {"host": "web-platform.test", |
| 37 "doc_root": self._path_to_wpt_tests, |
| 38 "insecure_port": secure_port, |
| 39 "secure_port": insecure_port} |
| 40 self._start_cmd = [self._executable, "--config", self._path_to_wpt_confi
g] |
| 41 |
| 42 def _spawn_process(self): |
| 43 _log.debug('Starting %s server, cmd="%s"' % (self._name, str(self._start
_cmd))) |
| 44 |
| 45 # TODO(burnik): This config should probably be available in advance. |
| 46 config = ('{' |
| 47 '"host": "%(host)s",' |
| 48 '"doc_root": "%(doc_root)s",' |
| 49 '"ports":{' |
| 50 '"http":[%(insecure_port)d, "auto"],' |
| 51 '"https":[%(secure_port)d],' |
| 52 '"ws":["auto"],' |
| 53 '"wss":["auto"]}' |
| 54 '}') % self._wpt_config |
| 55 fs = self._port_obj.host.filesystem |
| 56 fs.write_text_file(self._path_to_wpt_config, config) |
| 57 |
| 58 self._process = self._executive.popen(self._start_cmd, |
| 59 cwd=self._path_to_wpt, |
| 60 shell=True, |
| 61 stdout=self._executive.DEVNULL, |
| 62 stderr=self._executive.DEVNULL, |
| 63 preexec_fn=os.setsid) |
| 64 |
| 65 # We probably won't need a PID file, but server_base needs it. |
| 66 fs.write_text_file(self._pid_file, str(self._process.pid)) |
| 67 return self._process.pid |
| 68 |
| 69 def stop(self): |
| 70 self._stop_running_server() |
| 71 |
| 72 def _stop_running_server(self): |
| 73 # Clean up the pid file. |
| 74 if self._pid and not self._executive.check_running_pid(self._pid): |
| 75 self._filesystem.remove(self._pid_file) |
| 76 return |
| 77 |
| 78 self._executive.kill_process(self._pid) |
OLD | NEW |