| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Runs host-driven tests on a particular device.""" | 5 """Runs host-driven tests on a particular device.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import sys | 8 import sys |
| 9 import time | 9 import time |
| 10 import traceback | 10 import traceback |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 | 43 |
| 44 class HostDrivenTestRunner(base_test_runner.BaseTestRunner): | 44 class HostDrivenTestRunner(base_test_runner.BaseTestRunner): |
| 45 """Orchestrates running a set of host-driven tests. | 45 """Orchestrates running a set of host-driven tests. |
| 46 | 46 |
| 47 Any Python exceptions in the tests are caught and translated into a failed | 47 Any Python exceptions in the tests are caught and translated into a failed |
| 48 result, rather than being re-raised on the main thread. | 48 result, rather than being re-raised on the main thread. |
| 49 """ | 49 """ |
| 50 | 50 |
| 51 #override | 51 #override |
| 52 def __init__(self, device, shard_index, tool, build_type, push_deps, | 52 def __init__(self, device, shard_index, tool, push_deps, |
| 53 cleanup_test_files): | 53 cleanup_test_files): |
| 54 """Creates a new HostDrivenTestRunner. | 54 """Creates a new HostDrivenTestRunner. |
| 55 | 55 |
| 56 Args: | 56 Args: |
| 57 device: Attached android device. | 57 device: Attached android device. |
| 58 shard_index: Shard index. | 58 shard_index: Shard index. |
| 59 tool: Name of the Valgrind tool. | 59 tool: Name of the Valgrind tool. |
| 60 build_type: 'Release' or 'Debug'. | |
| 61 push_deps: If True, push all dependencies to the device. | 60 push_deps: If True, push all dependencies to the device. |
| 62 cleanup_test_files: Whether or not to cleanup test files on device. | 61 cleanup_test_files: Whether or not to cleanup test files on device. |
| 63 """ | 62 """ |
| 64 | 63 |
| 65 super(HostDrivenTestRunner, self).__init__(device, tool, build_type, | 64 super(HostDrivenTestRunner, self).__init__(device, tool, push_deps, |
| 66 push_deps, cleanup_test_files) | 65 cleanup_test_files) |
| 67 | 66 |
| 68 # The shard index affords the ability to create unique port numbers (e.g. | 67 # The shard index affords the ability to create unique port numbers (e.g. |
| 69 # DEFAULT_PORT + shard_index) if the test so wishes. | 68 # DEFAULT_PORT + shard_index) if the test so wishes. |
| 70 self.shard_index = shard_index | 69 self.shard_index = shard_index |
| 71 | 70 |
| 72 #override | 71 #override |
| 73 def RunTest(self, test): | 72 def RunTest(self, test): |
| 74 """Sets up and runs a test case. | 73 """Sets up and runs a test case. |
| 75 | 74 |
| 76 Args: | 75 Args: |
| 77 test: An object which is ostensibly a subclass of HostDrivenTestCase. | 76 test: An object which is ostensibly a subclass of HostDrivenTestCase. |
| 78 | 77 |
| 79 Returns: | 78 Returns: |
| 80 A TestRunResults object which contains the result produced by the test | 79 A TestRunResults object which contains the result produced by the test |
| 81 and, in the case of a failure, the test that should be retried. | 80 and, in the case of a failure, the test that should be retried. |
| 82 """ | 81 """ |
| 83 | 82 |
| 84 assert isinstance(test, test_case.HostDrivenTestCase) | 83 assert isinstance(test, test_case.HostDrivenTestCase) |
| 85 | 84 |
| 86 start_date_ms = int(time.time()) * 1000 | 85 start_date_ms = int(time.time()) * 1000 |
| 87 exception_raised = False | 86 exception_raised = False |
| 88 | 87 |
| 89 try: | 88 try: |
| 90 test.SetUp(self.device, self.shard_index, self.build_type, | 89 test.SetUp(self.device, self.shard_index, self._push_deps, |
| 91 self._push_deps, self._cleanup_test_files) | 90 self._cleanup_test_files) |
| 92 except Exception: | 91 except Exception: |
| 93 logging.exception( | 92 logging.exception( |
| 94 'Caught exception while trying to run SetUp() for test: ' + | 93 'Caught exception while trying to run SetUp() for test: ' + |
| 95 test.tagged_name) | 94 test.tagged_name) |
| 96 # Tests whose SetUp() method has failed are likely to fail, or at least | 95 # Tests whose SetUp() method has failed are likely to fail, or at least |
| 97 # yield invalid results. | 96 # yield invalid results. |
| 98 exc_info = sys.exc_info() | 97 exc_info = sys.exc_info() |
| 99 results = base_test_result.TestRunResults() | 98 results = base_test_result.TestRunResults() |
| 100 results.AddResult(HostDrivenExceptionTestResult( | 99 results.AddResult(HostDrivenExceptionTestResult( |
| 101 test.tagged_name, start_date_ms, exc_info)) | 100 test.tagged_name, start_date_ms, exc_info)) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 126 # until the test is fixed. | 125 # until the test is fixed. |
| 127 exc_info = sys.exc_info() | 126 exc_info = sys.exc_info() |
| 128 results = base_test_result.TestRunResults() | 127 results = base_test_result.TestRunResults() |
| 129 results.AddResult(HostDrivenExceptionTestResult( | 128 results.AddResult(HostDrivenExceptionTestResult( |
| 130 test.tagged_name, start_date_ms, exc_info)) | 129 test.tagged_name, start_date_ms, exc_info)) |
| 131 | 130 |
| 132 if not results.DidRunPass(): | 131 if not results.DidRunPass(): |
| 133 return results, test | 132 return results, test |
| 134 else: | 133 else: |
| 135 return results, None | 134 return results, None |
| OLD | NEW |