Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2488)

Unified Diff: build/android/pylib/host_driven/test_runner.py

Issue 19537004: [Android] Converts host driven tests to common test_dispatcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sharding_refactoring
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/host_driven/test_runner.py
diff --git a/build/android/pylib/host_driven/test_runner.py b/build/android/pylib/host_driven/test_runner.py
new file mode 100644
index 0000000000000000000000000000000000000000..a2506444a8d0b84adcdf81ff5abd4737c10cd585
--- /dev/null
+++ b/build/android/pylib/host_driven/test_runner.py
@@ -0,0 +1,96 @@
+# Copyright (c) 2012 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.
+
+"""Takes care of sharding the python-drive tests in multiple devices."""
+
+# TODO(gkanwar): Rename to python_test_runner.py
+
+import copy
+import logging
+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 python_test_base
+
+
+class PythonExceptionTestResult(test_result.InstrumentationTestResult):
bulach 2013/07/23 17:27:52 since we're renaming and willing to break, rather
gkanwar1 2013/07/23 18:38:55 Good point. I'll make this change throughout.
frankf 2013/07/24 01:04:55 SGTM
+ """Helper class for creating a test result from python exception."""
+
+ def __init__(self, test_name, start_date_ms, exc_info):
+ """Constructs an PythonExceptionTestResult object.
+
+ Args:
+ test_name: name of the test which raised an exception.
+ start_date_ms: the starting time for the test.
+ exc_info: exception info, ostensibly from sys.exc_info().
+ """
+ exc_type, exc_value, exc_traceback = exc_info
+ trace_info = ''.join(traceback.format_exception(exc_type, exc_value,
+ exc_traceback))
+ log_msg = 'Exception:\n' + trace_info
+ duration_ms = (int(time.time()) * 1000) - start_date_ms
+
+ super(PythonExceptionTestResult, self).__init__(
+ 'PythonWrapper#' + test_name,
+ base_test_result.ResultType.FAIL,
+ start_date_ms,
+ duration_ms,
+ log=str(exc_type) + ' ' + log_msg)
+
+
+class PythonTestRunner(base_test_runner.BaseTestRunner):
+ """Thin wrapper around a list of PythonTestBase instances.
+
+ This is meant to be a long-lived object which can run multiple Python tests
+ within its lifetime. Tests will receive the device_id and shard_index.
+
+ The shard index affords the ability to create unique port numbers (e.g.
+ DEFAULT_PORT + shard_index) if the test so wishes.
+ """
+
+ #override
+ def __init__(self, device, shard_index, tool, build_type, push_deps,
+ cleanup_test_files):
+ """Create a new PythonTestRunner
+
+ 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.
+ """
+
+ super(PythonTestRunner, self).__init__(device, tool, build_type, push_deps,
+ cleanup_test_files)
+ self.shard_index = shard_index
+
+ #override
+ def RunTest(self, test):
+ """Sets up and runs a test case.
+
+ Args:
+ test: An object which is ostensibly a subclass of PythonTestBase.
+
+ 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, python_test_base.PythonTestBase))
+ test.SetUp(self.device, self.shard_index, self.build_type, self._push_deps,
+ self._cleanup_test_files)
+ results = test.Run()
+ test.TearDown()
+
+ if not results.DidRunPass():
+ return results, test
+ else:
+ return results, None

Powered by Google App Engine
This is Rietveld 408576698