Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Takes care of sharding the python-drive tests in multiple devices.""" | |
| 6 | |
| 7 # TODO(gkanwar): Rename to python_test_runner.py | |
| 8 | |
| 9 import copy | |
| 10 import logging | |
| 11 import multiprocessing | |
| 12 | |
| 13 from pylib.base import base_test_result | |
| 14 from pylib.base import base_test_runner | |
| 15 from pylib.base import sharded_tests_queue | |
| 16 from pylib.instrumentation import test_result | |
| 17 | |
| 18 import python_test_base | |
| 19 | |
| 20 | |
| 21 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
| |
| 22 """Helper class for creating a test result from python exception.""" | |
| 23 | |
| 24 def __init__(self, test_name, start_date_ms, exc_info): | |
| 25 """Constructs an PythonExceptionTestResult object. | |
| 26 | |
| 27 Args: | |
| 28 test_name: name of the test which raised an exception. | |
| 29 start_date_ms: the starting time for the test. | |
| 30 exc_info: exception info, ostensibly from sys.exc_info(). | |
| 31 """ | |
| 32 exc_type, exc_value, exc_traceback = exc_info | |
| 33 trace_info = ''.join(traceback.format_exception(exc_type, exc_value, | |
| 34 exc_traceback)) | |
| 35 log_msg = 'Exception:\n' + trace_info | |
| 36 duration_ms = (int(time.time()) * 1000) - start_date_ms | |
| 37 | |
| 38 super(PythonExceptionTestResult, self).__init__( | |
| 39 'PythonWrapper#' + test_name, | |
| 40 base_test_result.ResultType.FAIL, | |
| 41 start_date_ms, | |
| 42 duration_ms, | |
| 43 log=str(exc_type) + ' ' + log_msg) | |
| 44 | |
| 45 | |
| 46 class PythonTestRunner(base_test_runner.BaseTestRunner): | |
| 47 """Thin wrapper around a list of PythonTestBase instances. | |
| 48 | |
| 49 This is meant to be a long-lived object which can run multiple Python tests | |
| 50 within its lifetime. Tests will receive the device_id and shard_index. | |
| 51 | |
| 52 The shard index affords the ability to create unique port numbers (e.g. | |
| 53 DEFAULT_PORT + shard_index) if the test so wishes. | |
| 54 """ | |
| 55 | |
| 56 #override | |
| 57 def __init__(self, device, shard_index, tool, build_type, push_deps, | |
| 58 cleanup_test_files): | |
| 59 """Create a new PythonTestRunner | |
| 60 | |
| 61 Args: | |
| 62 device: Attached android device. | |
| 63 shard_index: Shard index. | |
| 64 tool: Name of the Valgrind tool. | |
| 65 build_type: 'Release' or 'Debug'. | |
| 66 push_deps: If True, push all dependencies to the device. | |
| 67 cleanup_test_files: Whether or not to cleanup test files on device. | |
| 68 """ | |
| 69 | |
| 70 super(PythonTestRunner, self).__init__(device, tool, build_type, push_deps, | |
| 71 cleanup_test_files) | |
| 72 self.shard_index = shard_index | |
| 73 | |
| 74 #override | |
| 75 def RunTest(self, test): | |
| 76 """Sets up and runs a test case. | |
| 77 | |
| 78 Args: | |
| 79 test: An object which is ostensibly a subclass of PythonTestBase. | |
| 80 | |
| 81 Returns: | |
| 82 A TestRunResults object which contains any results produced by the test | |
| 83 or, in the case of a Python exception, the Python exception info, and | |
| 84 which tests to retry or None. | |
| 85 """ | |
| 86 | |
| 87 assert(isinstance(test, python_test_base.PythonTestBase)) | |
| 88 test.SetUp(self.device, self.shard_index, self.build_type, self._push_deps, | |
| 89 self._cleanup_test_files) | |
| 90 results = test.Run() | |
| 91 test.TearDown() | |
| 92 | |
| 93 if not results.DidRunPass(): | |
| 94 return results, test | |
| 95 else: | |
| 96 return results, None | |
| OLD | NEW |