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 """Runs host-driven tests on a particular device.""" |
| 6 |
| 7 from pylib.base import base_test_runner |
| 8 |
| 9 import test_case |
| 10 |
| 11 |
| 12 class HostDrivenTestRunner(base_test_runner.BaseTestRunner): |
| 13 """Thin wrapper around a list of HostDrivenTestCase instances. |
| 14 |
| 15 This is meant to be a long-lived object which can run multiple host-driven |
| 16 tests within its lifetime. Tests will receive the device_id and shard_index. |
| 17 |
| 18 The shard index affords the ability to create unique port numbers (e.g. |
| 19 DEFAULT_PORT + shard_index) if the test so wishes. |
| 20 """ |
| 21 |
| 22 #override |
| 23 def __init__(self, device, shard_index, tool, build_type, push_deps, |
| 24 cleanup_test_files): |
| 25 """Create a new HostDrivenTestRunner |
| 26 |
| 27 Args: |
| 28 device: Attached android device. |
| 29 shard_index: Shard index. |
| 30 tool: Name of the Valgrind tool. |
| 31 build_type: 'Release' or 'Debug'. |
| 32 push_deps: If True, push all dependencies to the device. |
| 33 cleanup_test_files: Whether or not to cleanup test files on device. |
| 34 """ |
| 35 |
| 36 super(HostDrivenTestRunner, self).__init__(device, tool, build_type, |
| 37 push_deps, cleanup_test_files) |
| 38 self.shard_index = shard_index |
| 39 |
| 40 #override |
| 41 def RunTest(self, test): |
| 42 """Sets up and runs a test case. |
| 43 |
| 44 Args: |
| 45 test: An object which is ostensibly a subclass of HostDrivenTestCase. |
| 46 |
| 47 Returns: |
| 48 A TestRunResults object which contains the result produced by the test |
| 49 and, in the case of a failure, the test that should be retried. |
| 50 """ |
| 51 |
| 52 assert(isinstance(test, test_case.HostDrivenTestCase)) |
| 53 test.SetUp(self.device, self.shard_index, self.build_type, self._push_deps, |
| 54 self._cleanup_test_files) |
| 55 try: |
| 56 exception_thrown = False |
| 57 results = test.Run() |
| 58 except: |
| 59 # Set a flag to make sure exceptions in Run() take priority |
| 60 exception_thrown = True |
| 61 raise |
| 62 finally: |
| 63 try: |
| 64 test.TearDown() |
| 65 except: |
| 66 # Re-raise only if Run() didn't fail, since exceptions in Run() take |
| 67 # priority for reporting. |
| 68 if not exception_thrown: |
| 69 raise |
| 70 |
| 71 if not results.DidRunPass(): |
| 72 return results, test |
| 73 else: |
| 74 return results, None |
OLD | NEW |