OLD | NEW |
---|---|
1 # Copyright (c) 2012 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 | 10 |
11 import BaseHTTPServer | 11 import BaseHTTPServer |
12 import json | 12 import json |
13 import logging | 13 import logging |
14 import os | 14 import os |
15 import select | 15 import select |
16 import struct | 16 import struct |
17 import subprocess | 17 import subprocess |
18 import threading | 18 import threading |
19 import time | 19 import time |
20 import urlparse | 20 import urlparse |
21 | 21 |
22 import constants | 22 import constants |
23 from forwarder import Forwarder | 23 from forwarder import Forwarder |
24 import ports | 24 import ports |
25 | 25 |
26 | 26 |
27 # Path that are needed to import necessary modules when running testserver.py. | 27 # Path that are needed to import necessary modules when launching a testserver. |
28 os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + ':%s:%s:%s:%s' % ( | 28 os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + (':%s:%s:%s:%s:%s' |
29 os.path.join(constants.CHROME_DIR, 'third_party'), | 29 % (os.path.join(constants.CHROME_DIR, 'third_party'), |
30 os.path.join(constants.CHROME_DIR, 'third_party', 'tlslite'), | 30 os.path.join(constants.CHROME_DIR, 'third_party', 'tlslite'), |
31 os.path.join(constants.CHROME_DIR, 'third_party', 'pyftpdlib', 'src'), | 31 os.path.join(constants.CHROME_DIR, 'third_party', 'pyftpdlib', 'src'), |
32 os.path.join(constants.CHROME_DIR, 'net', 'tools', 'testserver')) | 32 os.path.join(constants.CHROME_DIR, 'net', 'tools', 'testserver'), |
33 os.path.join(constants.CHROME_DIR, 'sync', 'tools', 'testserver'))) | |
33 | 34 |
34 | 35 |
35 SERVER_TYPES = { | 36 SERVER_TYPES = { |
36 'http': '', | 37 'http': '', |
37 'ftp': '-f', | 38 'ftp': '-f', |
38 'sync': '--sync', | 39 'sync': '', # Sync uses its own script, and doesn't take a server type arg. |
39 'tcpecho': '--tcp-echo', | 40 'tcpecho': '--tcp-echo', |
40 'udpecho': '--udp-echo', | 41 'udpecho': '--udp-echo', |
41 } | 42 } |
42 | 43 |
43 | 44 |
44 # The timeout (in seconds) of starting up the Python test server. | 45 # The timeout (in seconds) of starting up the Python test server. |
45 TEST_SERVER_STARTUP_TIMEOUT = 10 | 46 TEST_SERVER_STARTUP_TIMEOUT = 10 |
46 | 47 |
47 | 48 |
48 def _CheckPortStatus(port, expected_status): | 49 def _CheckPortStatus(port, expected_status): |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 self.command_line.append('--ssl-client-ca=%s' % | 201 self.command_line.append('--ssl-client-ca=%s' % |
201 os.path.join(constants.CHROME_DIR, ca)) | 202 os.path.join(constants.CHROME_DIR, ca)) |
202 if self.arguments.has_key('ssl-bulk-cipher'): | 203 if self.arguments.has_key('ssl-bulk-cipher'): |
203 for bulk_cipher in self.arguments['ssl-bulk-cipher']: | 204 for bulk_cipher in self.arguments['ssl-bulk-cipher']: |
204 self.command_line.append('--ssl-bulk-cipher=%s' % bulk_cipher) | 205 self.command_line.append('--ssl-bulk-cipher=%s' % bulk_cipher) |
205 | 206 |
206 def run(self): | 207 def run(self): |
207 logging.info('Start running the thread!') | 208 logging.info('Start running the thread!') |
208 self.wait_event.clear() | 209 self.wait_event.clear() |
209 self._GenerateCommandLineArguments() | 210 self._GenerateCommandLineArguments() |
210 command = [os.path.join(constants.CHROME_DIR, 'net', 'tools', | 211 command = constants.CHROME_DIR |
211 'testserver', 'testserver.py')] + self.command_line | 212 if self.arguments['server-type'] is 'sync': |
Paweł Hajdan Jr.
2013/01/18 22:41:29
nit: is -> ==
Raghu Simha
2013/01/18 22:49:02
Done.
| |
213 command = [os.path.join(command, 'sync', 'tools', 'testserver', | |
214 'sync_testserver.py')] + self.command_line | |
215 else: | |
216 command = [os.path.join(command, 'net', 'tools', 'testserver', | |
217 'testserver.py')] + self.command_line | |
212 logging.info('Running: %s', command) | 218 logging.info('Running: %s', command) |
213 self.process = subprocess.Popen(command) | 219 self.process = subprocess.Popen(command) |
214 if self.process: | 220 if self.process: |
215 if self.pipe_out: | 221 if self.pipe_out: |
216 self.is_ready = self._WaitToStartAndGetPortFromTestServer() | 222 self.is_ready = self._WaitToStartAndGetPortFromTestServer() |
217 else: | 223 else: |
218 self.is_ready = _CheckPortStatus(self.host_port, True) | 224 self.is_ready = _CheckPortStatus(self.host_port, True) |
219 if self.is_ready: | 225 if self.is_ready: |
220 self._test_server_forwarder = Forwarder(self.adb, self.build_type) | 226 self._test_server_forwarder = Forwarder(self.adb, self.build_type) |
221 self._test_server_forwarder.Run( | 227 self._test_server_forwarder.Run( |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 def Start(self): | 399 def Start(self): |
394 listener_thread = threading.Thread(target=self._Listen) | 400 listener_thread = threading.Thread(target=self._Listen) |
395 listener_thread.setDaemon(True) | 401 listener_thread.setDaemon(True) |
396 listener_thread.start() | 402 listener_thread.start() |
397 time.sleep(1) | 403 time.sleep(1) |
398 | 404 |
399 def Stop(self): | 405 def Stop(self): |
400 if self.server.test_server_instance: | 406 if self.server.test_server_instance: |
401 self.server.test_server_instance.Stop() | 407 self.server.test_server_instance.Stop() |
402 self.server.shutdown() | 408 self.server.shutdown() |
OLD | NEW |