OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (C) 2015 Google Inc. All rights reserved. | |
jsbell
2015/06/04 17:43:25
Don't copy/paste the header, use the latest from:
burnik
2015/06/05 12:59:29
Done.
| |
2 # | |
Dirk Pranke
2015/06/04 20:51:53
Put this file in layout_tests/servers; you do not
burnik
2015/06/05 12:59:29
Done.
| |
3 # Redistribution and use in source and binary forms, with or without | |
4 # modification, are permitted provided that the following conditions are | |
5 # met: | |
6 # | |
7 # * Redistributions of source code must retain the above copyright | |
8 # notice, this list of conditions and the following disclaimer. | |
9 # * Redistributions in binary form must reproduce the above | |
10 # copyright notice, this list of conditions and the following disclaimer | |
11 # in the documentation and/or other materials provided with the | |
12 # distribution. | |
13 # * Neither the name of Google Inc. nor the names of its | |
14 # contributors may be used to endorse or promote products derived from | |
15 # this software without specific prior written permission. | |
16 # | |
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
28 | |
29 """Start and stop the Apache HTTP server as it is used by the layout tests.""" | |
30 | |
31 import logging | |
32 import os | |
33 import socket | |
34 | |
35 from webkitpy.layout_tests.servers import server_base | |
36 | |
37 | |
38 _log = logging.getLogger(__name__) | |
39 | |
40 | |
41 class WPTServeHTTP(server_base.ServerBase): | |
42 def __init__(self, port_obj, output_dir): | |
43 super(WPTServeHTTP, self).__init__(port_obj, output_dir) | |
44 # TODO(burnik): This should be the only place where we set up the ports. | |
45 secure_port, insecure_port = (8001, 8444) | |
46 self._name = 'wptserve' | |
47 self._log_prefixes = ('access_log', 'error_log') | |
48 self._mappings = [{'port': secure_port}, | |
49 {'port': insecure_port, 'sslcert': True}] | |
50 | |
51 # TODO(burnik): We can probably avoid PID files for WPT in the future. | |
52 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se lf._name) | |
53 | |
54 script_path = os.path.dirname(os.path.abspath(__file__)) | |
55 self._path_to_wpt = os.path.abspath(os.path.join(script_path, "wpt")) | |
56 self._executable = os.path.join(self._path_to_wpt, "serve") | |
57 self._path_to_wpt_config = os.path.join(self._path_to_wpt, "config.json" ) | |
58 self._path_to_wpt_tests = os.path.abspath(os.path.join(self._port_obj.la yout_tests_dir(), | |
59 "imported", "web- platform-tests")) | |
60 self._wpt_config = {"host": "web-platform.test", | |
61 "doc_root": self._path_to_wpt_tests, | |
62 "insecure_port": secure_port, | |
63 "secure_port": insecure_port} | |
64 self._start_cmd = [self._executable, "--config", self._path_to_wpt_confi g] | |
65 | |
66 def _spawn_process(self): | |
67 _log.debug('Starting %s server, cmd="%s"' % (self._name, str(self._start _cmd))) | |
68 | |
69 # TODO(burnik): This config should probably be available in advance. | |
70 config = ('{' | |
71 '"host": "%(host)s",' | |
72 '"doc_root": "%(doc_root)s",' | |
73 '"ports":{' | |
74 '"http":[%(insecure_port)d, "auto"],' | |
75 '"https":[%(secure_port)d],' | |
76 '"ws":["auto"],' | |
77 '"wss":["auto"]}' | |
78 '}') % self._wpt_config | |
79 fs = self._port_obj.host.filesystem | |
80 fs.write_text_file(self._path_to_wpt_config, config) | |
81 | |
82 self._process = self._executive.popen(self._start_cmd, | |
83 cwd=self._path_to_wpt, | |
84 shell=True, | |
85 stdout=self._executive.DEVNULL, | |
86 stderr=self._executive.DEVNULL, | |
87 preexec_fn=os.setsid) | |
88 | |
89 # We probably won't need a PID file, but server_base needs it. | |
90 fs.write_text_file(self._pid_file, str(self._process.pid)) | |
91 return self._process.pid | |
92 | |
93 def stop(self): | |
94 self._stop_running_server() | |
95 | |
96 def _stop_running_server(self): | |
97 # Clean up the pid file. | |
98 if self._pid and not self._executive.check_running_pid(self._pid): | |
99 self._filesystem.remove(self._pid_file) | |
100 return | |
101 | |
102 self._executive.kill_process(self._pid) | |
OLD | NEW |