Index: build/android/pylib/host_driven/test_server_setup.py |
diff --git a/build/android/pylib/host_driven/test_server_setup.py b/build/android/pylib/host_driven/test_server_setup.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..5d8904a654758e8a31486e72617c245259a9209e |
--- /dev/null |
+++ b/build/android/pylib/host_driven/test_server_setup.py |
@@ -0,0 +1,64 @@ |
+#!/usr/bin/python |
+# Copyright 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import os |
+import os.path |
+import subprocess |
+ |
+from pylib import constants |
+ |
+# NOTE: when adding or modifying these lines, omit any leading slashes! |
+# Otherwise os.path.join() will (correctly) treat them as absolute paths |
+# instead of relative paths, and will do nothing. |
+PYTHONPATH_DIRS = [ |
frankf
2013/08/29 00:07:19
Add a leading underscore since these are private.
nyquist
2013/08/29 23:59:43
Done.
|
+ 'net/tools/testserver/', |
+ 'third_party/', |
+ 'third_party/pyftpdlib/src/', |
+ 'third_party/pywebsocket/src', |
+ 'third_party/tlslite/', |
+] |
+ |
+# Python files in these directories are generated as part of the build. |
+# These dirs are located in out/(Debug|Release) directory. |
+# The correct path is determined based on the build type. E.g. out/Debug for |
+# debug builds and out/Release for release builds. |
+GENERATED_PYTHONPATH_DIRS = [ |
+ 'pyproto/sync/protocol/', |
+ 'pyproto/' |
+] |
+ |
frankf
2013/08/29 00:07:19
run gpylint. 2 blank lines between top-level decla
nyquist
2013/08/29 23:59:43
Done.
|
+def SetUpTestServer(adb, shard_index, test_server_port, test_server_path): |
frankf
2013/08/29 00:07:19
So it makes sense to make this into a class and en
nyquist
2013/08/29 23:59:43
Done.
|
+ """Sets up a server. |
+ |
+ Args: |
+ adb: AndroidCommands object. |
+ shard_index: Index of the current shard. |
+ test_server_port: port to run the test server on. |
frankf
2013/08/29 00:07:19
Capital first letter.
nyquist
2013/08/29 23:59:43
Done.
|
+ test_server_path: the path (relative to the root src dir) of the server |
+ |
+ Returns: |
+ A tuple where the first element is the port used by the server, and the |
+ second is the mock server that was setup. |
+ """ |
+ port = test_server_port + shard_index |
+ |
+ src_dir = constants.DIR_SOURCE_ROOT |
+ # Make dirs into a list of absolute paths. |
+ abs_dirs = [os.path.join(src_dir, d) for d in PYTHONPATH_DIRS] |
+ # Add the generated python files to the path |
+ abs_dirs.extend([os.path.join(src_dir, 'out', constants.GetBuildType(), d) |
+ for d in GENERATED_PYTHONPATH_DIRS]) |
+ # Note the colon after $PYTHONPATH. This appends the list of PYTHONPATH_DIRS |
+ # to the existing PYTHONPATH. |
+ python_path = '$PYTHONPATH:' + ':'.join(abs_dirs) |
craigdh
2013/08/29 00:06:46
just modify os.environ
nyquist
2013/08/29 23:59:43
Uses os.environ now, but does not edit it here, si
|
+ |
+ # NOTE: A separate python process is used to simplify getting the right system |
+ # path for finding includes. |
+ server_flags = ['python', os.path.join(src_dir, test_server_path), |
+ '--log-to-console', |
+ ('--host=%s' % constants.TEST_SERVER_HOST), |
+ ('--port=%d' % port)] |
+ test_server = subprocess.Popen(server_flags, env={'PYTHONPATH': python_path}) |
craigdh
2013/08/29 00:06:46
We've had issues with bugs in Python 2.x's subproc
nyquist
2013/08/29 23:59:43
There is no waiting for output here, so that does
craigdh
2013/08/30 17:55:50
Ah, you're right, I thought it was returning a Pop
|
+ return (port, test_server) |