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

Side by Side Diff: build/android/pylib/host_driven/test_server.py

Issue 23726004: Add test_server_setup.py and add support for additional flags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Additional typo fix Created 7 years, 3 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
OLDNEW
(Empty)
1 #!/usr/bin/python
frankf 2013/08/30 18:22:43 Remove the shebang, this module is only imported.
nyquist 2013/08/30 21:50:59 Done.
2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Python driven test server controller.
7
8 This class controls the startup and shutdown of a python driven test server that
9 runs in a separate process.
10
11 The server starts up automatically when the object is created.
12
13 After it starts up, it is possible to retreive the port it started on through
14 accessing the member field |port|.
15
16 For shutting down the server, call TearDown().
17 """
18
19 import subprocess
20 import os
21 import os.path
22
23 from pylib import constants
24
25 # NOTE: when adding or modifying these lines, omit any leading slashes!
26 # Otherwise os.path.join() will (correctly) treat them as absolute paths
27 # instead of relative paths, and will do nothing.
28 _PYTHONPATH_DIRS = [
29 'net/tools/testserver/',
30 'third_party/',
31 'third_party/pyftpdlib/src/',
32 'third_party/pywebsocket/src',
33 'third_party/tlslite/',
34 ]
35
36 # Python files in these directories are generated as part of the build.
37 # These dirs are located in out/(Debug|Release) directory.
38 # The correct path is determined based on the build type. E.g. out/Debug for
39 # debug builds and out/Release for release builds.
40 _GENERATED_PYTHONPATH_DIRS = [
41 'pyproto/sync/protocol/',
42 'pyproto/'
43 ]
44
45
46 class TestServer(object):
47 """Sets up a Python driven test server on the host machine.
frankf 2013/08/30 18:22:43 s/python driven/host driven/g
nyquist 2013/08/30 21:50:59 Done.
48
49 For shutting down the server, call TearDown().
50 """
51
52 def __init__(self, shard_index, test_server_port, test_server_path):
53 """Sets up a Python driven test server on the host machine.
54
55 Args:
56 shard_index: Index of the current shard.
57 test_server_port: Port to run the test server on. This is multiplexed with
58 the shard index. To retrieve the real port access the
59 member variable |port|.
60 test_server_path: The path (relative to the root src dir) of the server
61
62 Returns:
frankf 2013/08/30 18:22:43 Update this
nyquist 2013/08/30 21:50:59 Done. Removed "Returns" since this is now a constr
63 A tuple where the first element is the port used by the server, and the
64 second is the mock server that was setup.
65 """
66 self.port = test_server_port + shard_index
67
68 src_dir = constants.DIR_SOURCE_ROOT
69 # Make dirs into a list of absolute paths.
70 abs_dirs = [os.path.join(src_dir, d) for d in _PYTHONPATH_DIRS]
71 # Add the generated python files to the path
72 abs_dirs.extend([os.path.join(src_dir, 'out', constants.GetBuildType(), d)
73 for d in _GENERATED_PYTHONPATH_DIRS])
74 # Note the colon after $PYTHONPATH. This appends the list of
craigdh 2013/08/30 17:55:50 nit: update comment, or perhaps just remove it?
nyquist 2013/08/30 21:50:59 Done. Removed.
75 # _PYTHONPATH_DIRS to the existing PYTHONPATH.
76 current_python_path = os.environ.get('PYTHONPATH')
77 extra_python_path = ':'.join(abs_dirs)
78 if current_python_path:
79 python_path = current_python_path + ':' + extra_python_path
80 else:
81 python_path = extra_python_path
82
83 # NOTE: A separate python process is used to simplify getting the right
84 # system path for finding includes.
85 server_flags = ['python', os.path.join(src_dir, test_server_path),
frankf 2013/08/30 18:22:43 server_flags -> cmd
nyquist 2013/08/30 21:50:59 Done.
86 '--log-to-console',
87 ('--host=%s' % constants.TEST_SERVER_HOST),
88 ('--port=%d' % self.port)]
89 self._test_server_process = subprocess.Popen(
90 server_flags, env={'PYTHONPATH': python_path})
91
92 def TearDown(self):
93 self._test_server_process.kill()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698