Chromium Code Reviews| Index: build/android/pylib/host_driven/test_base.py |
| diff --git a/build/android/pylib/host_driven/python_test_base.py b/build/android/pylib/host_driven/test_base.py |
| similarity index 21% |
| rename from build/android/pylib/host_driven/python_test_base.py |
| rename to build/android/pylib/host_driven/test_base.py |
| index 9d8f8faeb429ff4a3907ed5f87ef58f284bc9347..d568e622caa1a5b175198e22a103f3e0fe43d981 100644 |
| --- a/build/android/pylib/host_driven/python_test_base.py |
| +++ b/build/android/pylib/host_driven/test_base.py |
| @@ -2,40 +2,26 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| -"""Base class for Android Python-driven tests. |
| +"""Base class for Android host-driven tests. |
|
frankf
2013/07/24 01:04:55
remove 'Android' from docs, it's implied.
gkanwar1
2013/07/24 17:38:04
Done.
|
| -This test case is intended to serve as the base class for any Python-driven |
| +This test case is intended to serve as the base class for any host-driven |
| tests. It is similar to the Python unitttest module in that the user's tests |
|
frankf
2013/07/24 01:04:55
Didn't we discuss using unittest? You'll get a lot
gkanwar1
2013/07/24 17:38:04
Yes, I was intending to look into that after this
|
| inherit from this case and add their tests in that case. |
| -When a PythonTestBase object is instantiated, its purpose is to run only one of |
| -its tests. The test runner gives it the name of the test the instance will |
| +When a HostDrivenTestBase object is instantiated, its purpose is to run only one |
| +of its tests. The test runner gives it the name of the test the instance will |
| run. The test runner calls SetUp with the Android device ID which the test will |
| run against. The runner runs the test method itself, collecting the result, |
| and calls TearDown. |
| - |
| -Tests can basically do whatever they want in the test methods, such as call |
| -Java tests using _RunJavaTests. Those methods have the advantage of massaging |
| -the Java test results into Python test results. |
| """ |
| import logging |
| -import os |
| -import time |
| from pylib import android_commands |
| -from pylib.base import base_test_result |
| -from pylib.instrumentation import test_package |
| -from pylib.instrumentation import test_result |
| -from pylib.instrumentation import test_runner |
| - |
| -# aka the parent of com.google.android |
| -BASE_ROOT = 'src' + os.sep |
| - |
| -class PythonTestBase(object): |
| - """Base class for Python-driven tests.""" |
| +class HostDrivenTestBase(object): |
| + """Base class for host-driven tests.""" |
| def __init__(self, test_name): |
| # test_name must match one of the test methods defined on a subclass which |
| @@ -46,99 +32,22 @@ class PythonTestBase(object): |
| class_name = self.__class__.__name__ |
| self.qualified_name = class_name + '.' + self.test_name |
| - def SetUp(self, options): |
| - self.options = options |
| - self.shard_index = self.options.shard_index |
| - self.device_id = self.options.device_id |
| + def SetUp(self, device, shard_index, build_type, push_deps, |
| + cleanup_test_files): |
| + self.device_id = device |
| + self.shard_index = shard_index |
| + self.build_type = build_type |
| self.adb = android_commands.AndroidCommands(self.device_id) |
| - self.ports_to_forward = [] |
| + self.push_deps = push_deps |
| + self.cleanup_test_files = cleanup_test_files |
| def TearDown(self): |
| pass |
| def GetOutDir(self): |
| return os.path.join(os.environ['CHROME_SRC'], 'out', |
| - self.options.build_type) |
| + self.build_type) |
| def Run(self): |
| - logging.warning('Running Python-driven test: %s', self.test_name) |
| + logging.warning('Running host-driven test: %s', self.test_name) |
|
frankf
2013/07/24 01:04:55
warning -> info
gkanwar1
2013/07/24 17:38:04
Done.
|
| return getattr(self, self.test_name)() |
| - |
| - def _RunJavaTest(self, fname, suite, test): |
| - """Runs a single Java test with a Java TestRunner. |
| - |
| - Args: |
| - fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py) |
| - suite: name of the Java test suite (e.g. FooTest) |
| - test: name of the test method to run (e.g. testFooBar) |
| - |
| - Returns: |
| - TestRunResults object with a single test result. |
| - """ |
| - test = self._ComposeFullTestName(fname, suite, test) |
| - test_pkg = test_package.TestPackage( |
| - self.options.test_apk_path, self.options.test_apk_jar_path) |
| - java_test_runner = test_runner.TestRunner(self.options.build_type, |
| - self.options.test_data, |
| - self.options.install_apk, |
| - self.options.save_perf_json, |
| - self.options.screenshot_failures, |
| - self.options.tool, |
| - self.options.wait_for_debugger, |
| - self.options.disable_assertions, |
| - self.options.push_deps, |
| - self.options.cleanup_test_files, |
| - self.device_id, |
| - self.shard_index, test_pkg, |
| - self.ports_to_forward) |
| - try: |
| - java_test_runner.SetUp() |
| - return java_test_runner.RunTest(test)[0] |
| - finally: |
| - java_test_runner.TearDown() |
| - |
| - def _RunJavaTests(self, fname, tests): |
| - """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 |
| - exhausts the list of tests. Then it returns the appropriate Python result. |
| - |
| - Args: |
| - fname: filename for the Python test |
| - tests: a list of Java test names which will be run |
| - |
| - Returns: |
| - A TestRunResults object containing a result for this Python test. |
| - """ |
| - test_type = base_test_result.ResultType.PASS |
| - log = '' |
| - |
| - start_ms = int(time.time()) * 1000 |
| - for test in tests: |
| - # We're only running one test at a time, so this TestRunResults object |
| - # will hold only one result. |
| - suite, test_name = test.split('.') |
| - java_results = self._RunJavaTest(fname, suite, test_name) |
| - assert len(java_results.GetAll()) == 1 |
| - if not java_results.DidRunPass(): |
| - result = java_results.GetNotPass().pop() |
| - log = result.GetLog() |
| - test_type = result.GetType() |
| - break |
| - duration_ms = int(time.time()) * 1000 - start_ms |
| - |
| - python_results = base_test_result.TestRunResults() |
| - python_results.AddResult( |
| - test_result.InstrumentationTestResult( |
| - self.qualified_name, test_type, start_ms, duration_ms, log=log)) |
| - return python_results |
| - |
| - def _ComposeFullTestName(self, fname, suite, test): |
| - package_name = self._GetPackageName(fname) |
| - return package_name + '.' + suite + '#' + test |
| - |
| - def _GetPackageName(self, fname): |
| - """Extracts the package name from the test file path.""" |
| - dirname = os.path.dirname(fname) |
| - package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):] |
| - return package.replace(os.sep, '.') |