| Index: build/android/pylib/host_driven/TestServer.py
|
| diff --git a/build/android/pylib/host_driven/TestServer.py b/build/android/pylib/host_driven/TestServer.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..310f59e572ce4761255924b0cea1929cfd8ea77f
|
| --- /dev/null
|
| +++ b/build/android/pylib/host_driven/TestServer.py
|
| @@ -0,0 +1,99 @@
|
| +#!/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
|
| +from pylib import flag_changer
|
| +
|
| +_HOST = '127.0.0.1'
|
| +
|
| +_SYNC_TEST_SERVER_PATH = 'sync/tools/testserver/sync_testserver.py'
|
| +
|
| +# 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 = [
|
| + '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/'
|
| +]
|
| +
|
| +
|
| +def setUpTestSyncServer(adb, shard_index, command_line_file):
|
| + return __setUpTestServer(adb, shard_index,
|
| + constants.TEST_SYNC_SERVER_PORT,
|
| + command_line_file,
|
| + '--sync-url=http://%s:%d/chromiumsync',
|
| + [],
|
| + _SYNC_TEST_SERVER_PATH)
|
| +
|
| +def setUpTestSearchByImageServer(adb, shard_index):
|
| + return __setUpTestServer(
|
| + adb, shard_index,
|
| + constants.TEST_SEARCH_BY_IMAGE_SERVER_PORT,
|
| + '--host-resolver-rules="MAP * %s:%d, EXCLUDE localhost"',
|
| + [],
|
| + _NET_TEST_SERVER_PATH)
|
| +
|
| +def __setUpTestServer(adb, shard_index, test_server_port, command_line_file,
|
| + chrome_flags_to_append, test_server_flags,
|
| + test_server_path):
|
| + """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.
|
| + chrome_flags_to_append: additional flags to post to Chrome.
|
| + test_server_flags: flags to use when starting the test server.
|
| + test_server_path: the path (relative to the root Chrome dir) of the server
|
| +
|
| + Returns:
|
| + A tuple where the first element is the command line flags used by the
|
| + tests, and the second is the mock server that was setup.
|
| + """
|
| + port = test_server_port + shard_index
|
| + flags = flag_changer.FlagChanger(adb, command_line_file)
|
| + flags.AddFlags([chrome_flags_to_append % (_HOST, port)])
|
| +
|
| + chrome_dir = os.getcwd()
|
| +
|
| + # Make dirs into a list of absolute paths.
|
| + abs_dirs = [os.path.join(chrome_dir, d) for d in PYTHONPATH_DIRS]
|
| + # Add the generated python files to the path
|
| + abs_dirs.extend([os.path.join(chrome_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)
|
| +
|
| + # NOTE: A separate python process is used to simplify getting the right system
|
| + # path for finding includes.
|
| + server_flags = ['python', os.path.join(chrome_dir, test_server_path),
|
| + '--log-to-console', ('--host=%s' % _HOST),
|
| + ('--port=%d' % port)]
|
| + server_flags.extend(test_server_flags)
|
| + test_server = subprocess.Popen(server_flags, env={'PYTHONPATH': python_path})
|
| + return (port, flags, test_server)
|
| +
|
| +
|
| +def tearDown(setup_params):
|
| + flags, test_server = setup_params
|
| + flags.Restore()
|
| + test_server.kill()
|
|
|