Index: build/android/pylib/host_driven/test_runner.py |
diff --git a/build/android/pylib/host_driven/python_test_caller.py b/build/android/pylib/host_driven/test_runner.py |
similarity index 24% |
rename from build/android/pylib/host_driven/python_test_caller.py |
rename to build/android/pylib/host_driven/test_runner.py |
index fc53d7725f9bb8291eab00accd67fa128e8168d1..aad527b35714d168f0324daa570d04872936d405 100644 |
--- a/build/android/pylib/host_driven/python_test_caller.py |
+++ b/build/android/pylib/host_driven/test_runner.py |
@@ -2,23 +2,25 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-"""Helper module for calling python-based tests.""" |
- |
+"""Runs host-driven tests on a particular device.""" |
+import copy |
import logging |
-import sys |
-import time |
-import traceback |
+import multiprocessing |
from pylib.base import base_test_result |
+from pylib.base import base_test_runner |
+from pylib.base import sharded_tests_queue |
from pylib.instrumentation import test_result |
+import test_base |
+ |
-class PythonExceptionTestResult(test_result.InstrumentationTestResult): |
- """Helper class for creating a test result from python exception.""" |
+class HostDrivenExceptionTestResult(test_result.InstrumentationTestResult): |
+ """A test result from an exception in a host-driven test.""" |
def __init__(self, test_name, start_date_ms, exc_info): |
- """Constructs an PythonExceptionTestResult object. |
+ """Constructs an HostDrivenExceptionTestResult object. |
Args: |
test_name: name of the test which raised an exception. |
@@ -31,85 +33,62 @@ class PythonExceptionTestResult(test_result.InstrumentationTestResult): |
log_msg = 'Exception:\n' + trace_info |
duration_ms = (int(time.time()) * 1000) - start_date_ms |
- super(PythonExceptionTestResult, self).__init__( |
- 'PythonWrapper#' + test_name, |
+ super(HostDrivenExceptionTestResult, self).__init__( |
+ 'HostDrivenWrapper#' + test_name, |
base_test_result.ResultType.FAIL, |
start_date_ms, |
duration_ms, |
log=str(exc_type) + ' ' + log_msg) |
-def CallPythonTest(test, options): |
- """Invokes a test function and translates Python exceptions into test results. |
+class HostDrivenTestRunner(base_test_runner.BaseTestRunner): |
frankf
2013/07/24 01:04:55
By deriving from BaseTestRunner, you're inheriting
gkanwar1
2013/07/24 17:38:04
Yes, I took a look at the BaseTestRunner before ma
|
+ """Thin wrapper around a list of HostDrivenTestBase instances. |
- This method invokes SetUp()/TearDown() on the test. It is intended to be |
- resilient to exceptions in SetUp(), the test itself, and TearDown(). Any |
- Python exception means the test is marked as failed, and the test result will |
- contain information about the exception. |
+ This is meant to be a long-lived object which can run multiple host-driven |
+ tests within its lifetime. Tests will receive the device_id and shard_index. |
- If SetUp() raises an exception, the test is not run. |
+ The shard index affords the ability to create unique port numbers (e.g. |
+ DEFAULT_PORT + shard_index) if the test so wishes. |
+ """ |
- If TearDown() raises an exception, the test is treated as a failure. However, |
- if the test itself raised an exception beforehand, that stack trace will take |
- precedence whether or not TearDown() also raised an exception. |
+ #override |
+ def __init__(self, device, shard_index, tool, build_type, push_deps, |
+ cleanup_test_files): |
+ """Create a new HostDrivenTestRunner |
- shard_index is not applicable in single-device scenarios, when test execution |
- is serial rather than parallel. Tests can use this to bring up servers with |
- unique port numbers, for example. See also python_test_sharder. |
+ Args: |
+ device: Attached android device. |
+ shard_index: Shard index. |
+ tool: Name of the Valgrind tool. |
+ build_type: 'Release' or 'Debug'. |
+ push_deps: If True, push all dependencies to the device. |
+ cleanup_test_files: Whether or not to cleanup test files on device. |
+ """ |
- Args: |
- test: an object which is ostensibly a subclass of PythonTestBase. |
- options: Options to use for setting up tests. |
+ super(HostDrivenTestRunner, self).__init__(device, tool, build_type, |
+ push_deps, cleanup_test_files) |
+ self.shard_index = shard_index |
- Returns: |
- A TestRunResults object which contains any results produced by the test or, |
- in the case of a Python exception, the Python exception info. |
- """ |
+ #override |
+ def RunTest(self, test): |
+ """Sets up and runs a test case. |
- start_date_ms = int(time.time()) * 1000 |
- failed = False |
- |
- try: |
- test.SetUp(options) |
- except Exception: |
- failed = True |
- logging.exception( |
- 'Caught exception while trying to run SetUp() for test: ' + |
- test.qualified_name) |
- # Tests whose SetUp() method has failed are likely to fail, or at least |
- # yield invalid results. |
- exc_info = sys.exc_info() |
- results = base_test_result.TestRunResults() |
- results.AddResult(PythonExceptionTestResult( |
- test.qualified_name, start_date_ms, exc_info)) |
- return results |
- |
- try: |
+ Args: |
+ test: An object which is ostensibly a subclass of HostDrivenTestBase. |
+ |
+ Returns: |
+ A TestRunResults object which contains any results produced by the test |
+ or, in the case of a Python exception, the Python exception info, and |
+ which tests to retry or None. |
+ """ |
+ |
+ assert(isinstance(test, test_base.HostDrivenTestBase)) |
+ test.SetUp(self.device, self.shard_index, self.build_type, self._push_deps, |
+ self._cleanup_test_files) |
results = test.Run() |
- except Exception: |
- # Setting this lets TearDown() avoid stomping on our stack trace from Run() |
- # should TearDown() also raise an exception. |
- failed = True |
- logging.exception('Caught exception while trying to run test: ' + |
- test.qualified_name) |
- exc_info = sys.exc_info() |
- results = base_test_result.TestRunResults() |
- results.AddResult(PythonExceptionTestResult( |
- test.qualified_name, start_date_ms, exc_info)) |
- |
- try: |
test.TearDown() |
frankf
2013/07/24 01:04:55
There's no exception handling here. Think about th
gkanwar1
2013/07/24 17:38:04
Ah, I removed the try/excepts because we're using
|
- except Exception: |
- logging.exception( |
- 'Caught exception while trying run TearDown() for test: ' + |
- test.qualified_name) |
- if not failed: |
- # Don't stomp the error during the test if TearDown blows up. This is a |
- # trade-off: if the test fails, this will mask any problem with TearDown |
- # until the test is fixed. |
- exc_info = sys.exc_info() |
- results = base_test_result.TestRunResults() |
- results.AddResult(PythonExceptionTestResult( |
- test.qualified_name, start_date_ms, exc_info)) |
- |
- return results |
+ |
+ if not results.DidRunPass(): |
+ return results, test |
+ else: |
+ return results, None |