summaryrefslogtreecommitdiffstats
path: root/build/android/pylib/host_driven
diff options
context:
space:
mode:
authornyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-01 22:54:43 +0000
committernyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-01 22:54:43 +0000
commit5d90fbebb5095e403cf753af35914efebf43efe4 (patch)
tree1c42400d0afd586358cab68e66056ab6d3a91edd /build/android/pylib/host_driven
parent4f8a6dc3c4fda1674257a5c153998fc44461d17f (diff)
downloadchromium_src-5d90fbebb5095e403cf753af35914efebf43efe4.zip
chromium_src-5d90fbebb5095e403cf753af35914efebf43efe4.tar.gz
chromium_src-5d90fbebb5095e403cf753af35914efebf43efe4.tar.bz2
Add test_server_setup.py and add support for additional flags.
Whenever a host driven test need to setup a server as part of a test, the command line needs of the application to be instrumented needs to change. This CL adds a helper class for setting up a test server, and also adds support for tests to setup additional flags (typically the URL for how to connect to the test server). Depends on: https://codereview.chromium.org/23467004/ BUG=272584 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/23726004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/android/pylib/host_driven')
-rw-r--r--build/android/pylib/host_driven/test_case.py11
-rwxr-xr-xbuild/android/pylib/host_driven/test_server.py92
2 files changed, 99 insertions, 4 deletions
diff --git a/build/android/pylib/host_driven/test_case.py b/build/android/pylib/host_driven/test_case.py
index 3387c94..7ce1c30 100644
--- a/build/android/pylib/host_driven/test_case.py
+++ b/build/android/pylib/host_driven/test_case.py
@@ -77,12 +77,13 @@ class HostDrivenTestCase(object):
# Get the test method on the derived class and execute it
return getattr(self, self.test_name)()
- def __RunJavaTest(self, test, test_pkg):
+ def __RunJavaTest(self, test, test_pkg, additional_flags=None):
"""Runs a single Java test in a Java TestRunner.
Args:
test: Fully qualified test name (ex. foo.bar.TestClass#testMethod)
test_pkg: TestPackage object.
+ additional_flags: A list of additional flags to add to the command line.
Returns:
TestRunResults object with a single test result.
@@ -90,14 +91,15 @@ class HostDrivenTestCase(object):
java_test_runner = test_runner.TestRunner(self.instrumentation_options,
self.device_id,
self.shard_index, test_pkg,
- self.ports_to_forward)
+ self.ports_to_forward,
+ additional_flags=additional_flags)
try:
java_test_runner.SetUp()
return java_test_runner.RunTest(test)[0]
finally:
java_test_runner.TearDown()
- def _RunJavaTestFilters(self, test_filters):
+ def _RunJavaTestFilters(self, test_filters, additional_flags=None):
"""Calls a list of tests and stops at the first test failure.
This method iterates until either it encounters a non-passing test or it
@@ -109,6 +111,7 @@ class HostDrivenTestCase(object):
Args:
test_filters: A list of Java test filters.
+ additional_flags: A list of addition flags to add to the command line.
Returns:
A TestRunResults object containing an overall result for this set of Java
@@ -132,7 +135,7 @@ class HostDrivenTestCase(object):
for test in tests:
# We're only running one test at a time, so this TestRunResults object
# will hold only one result.
- java_result = self.__RunJavaTest(test, test_pkg)
+ java_result = self.__RunJavaTest(test, test_pkg, additional_flags)
assert len(java_result.GetAll()) == 1
if not java_result.DidRunPass():
result = java_result.GetNotPass().pop()
diff --git a/build/android/pylib/host_driven/test_server.py b/build/android/pylib/host_driven/test_server.py
new file mode 100755
index 0000000..23d6820
--- /dev/null
+++ b/build/android/pylib/host_driven/test_server.py
@@ -0,0 +1,92 @@
+# 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.
+
+"""Host driven test server controller.
+
+This class controls the startup and shutdown of a python driven test server that
+runs in a separate process.
+
+The server starts up automatically when the object is created.
+
+After it starts up, it is possible to retreive the hostname it started on
+through accessing the member field |host| and the port name through |port|.
+
+For shutting down the server, call TearDown().
+"""
+
+import subprocess
+import os
+import os.path
+
+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 = [
+ '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/'
+]
+
+_TEST_SERVER_HOST = '127.0.0.1'
+# Paths for supported test server executables.
+TEST_NET_SERVER_PATH = 'net/tools/testserver/testserver.py'
+TEST_SYNC_SERVER_PATH = 'sync/tools/testserver/sync_testserver.py'
+
+
+class TestServer(object):
+ """Sets up a host driven test server on the host machine.
+
+ For shutting down the server, call TearDown().
+ """
+
+ def __init__(self, shard_index, test_server_port, test_server_path):
+ """Sets up a Python driven test server on the host machine.
+
+ Args:
+ shard_index: Index of the current shard.
+ test_server_port: Port to run the test server on. This is multiplexed with
+ the shard index. To retrieve the real port access the
+ member variable |port|.
+ test_server_path: The path (relative to the root src dir) of the server
+ """
+ self.host = _TEST_SERVER_HOST
+ self.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])
+ current_python_path = os.environ.get('PYTHONPATH')
+ extra_python_path = ':'.join(abs_dirs)
+ if current_python_path:
+ python_path = current_python_path + ':' + extra_python_path
+ else:
+ python_path = extra_python_path
+
+ # NOTE: A separate python process is used to simplify getting the right
+ # system path for finding includes.
+ cmd = ['python', os.path.join(src_dir, test_server_path),
+ '--log-to-console',
+ ('--host=%s' % self.host),
+ ('--port=%d' % self.port)]
+ self._test_server_process = subprocess.Popen(
+ cmd, env={'PYTHONPATH': python_path})
+
+ def TearDown(self):
+ self._test_server_process.kill()