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 30 matching lines...) Expand all Loading... |
41 | 41 |
42 | 42 |
43 class HostDrivenTestRunner(base_test_runner.BaseTestRunner): | 43 class HostDrivenTestRunner(base_test_runner.BaseTestRunner): |
44 """Orchestrates running a set of host-driven tests. | 44 """Orchestrates running a set of host-driven tests. |
45 | 45 |
46 Any Python exceptions in the tests are caught and translated into a failed | 46 Any Python exceptions in the tests are caught and translated into a failed |
47 result, rather than being re-raised on the main thread. | 47 result, rather than being re-raised on the main thread. |
48 """ | 48 """ |
49 | 49 |
50 #override | 50 #override |
51 def __init__(self, device, shard_index, tool, cleanup_test_files): | 51 def __init__(self, device, shard_index, tool): |
52 """Creates a new HostDrivenTestRunner. | 52 """Creates a new HostDrivenTestRunner. |
53 | 53 |
54 Args: | 54 Args: |
55 device: Attached android device. | 55 device: Attached android device. |
56 shard_index: Shard index. | 56 shard_index: Shard index. |
57 tool: Name of the Valgrind tool. | 57 tool: Name of the Valgrind tool. |
58 cleanup_test_files: Whether or not to cleanup test files on device. | |
59 """ | 58 """ |
60 | 59 |
61 super(HostDrivenTestRunner, self).__init__(device, tool, cleanup_test_files) | 60 super(HostDrivenTestRunner, self).__init__(device, tool) |
62 | 61 |
63 # The shard index affords the ability to create unique port numbers (e.g. | 62 # The shard index affords the ability to create unique port numbers (e.g. |
64 # DEFAULT_PORT + shard_index) if the test so wishes. | 63 # DEFAULT_PORT + shard_index) if the test so wishes. |
65 self.shard_index = shard_index | 64 self.shard_index = shard_index |
66 | 65 |
67 #override | 66 #override |
68 def RunTest(self, test): | 67 def RunTest(self, test): |
69 """Sets up and runs a test case. | 68 """Sets up and runs a test case. |
70 | 69 |
71 Args: | 70 Args: |
72 test: An object which is ostensibly a subclass of HostDrivenTestCase. | 71 test: An object which is ostensibly a subclass of HostDrivenTestCase. |
73 | 72 |
74 Returns: | 73 Returns: |
75 A TestRunResults object which contains the result produced by the test | 74 A TestRunResults object which contains the result produced by the test |
76 and, in the case of a failure, the test that should be retried. | 75 and, in the case of a failure, the test that should be retried. |
77 """ | 76 """ |
78 | 77 |
79 assert isinstance(test, test_case.HostDrivenTestCase) | 78 assert isinstance(test, test_case.HostDrivenTestCase) |
80 | 79 |
81 start_date_ms = int(time.time()) * 1000 | 80 start_date_ms = int(time.time()) * 1000 |
82 exception_raised = False | 81 exception_raised = False |
83 | 82 |
84 try: | 83 try: |
85 test.SetUp(str(self.device), self.shard_index, self._cleanup_test_files) | 84 test.SetUp(str(self.device), self.shard_index) |
86 except Exception: | 85 except Exception: |
87 logging.exception( | 86 logging.exception( |
88 'Caught exception while trying to run SetUp() for test: ' + | 87 'Caught exception while trying to run SetUp() for test: ' + |
89 test.tagged_name) | 88 test.tagged_name) |
90 # Tests whose SetUp() method has failed are likely to fail, or at least | 89 # Tests whose SetUp() method has failed are likely to fail, or at least |
91 # yield invalid results. | 90 # yield invalid results. |
92 exc_info = sys.exc_info() | 91 exc_info = sys.exc_info() |
93 results = base_test_result.TestRunResults() | 92 results = base_test_result.TestRunResults() |
94 results.AddResult(HostDrivenExceptionTestResult( | 93 results.AddResult(HostDrivenExceptionTestResult( |
95 test.tagged_name, start_date_ms, exc_info)) | 94 test.tagged_name, start_date_ms, exc_info)) |
(...skipping 24 matching lines...) Expand all Loading... |
120 # until the test is fixed. | 119 # until the test is fixed. |
121 exc_info = sys.exc_info() | 120 exc_info = sys.exc_info() |
122 results = base_test_result.TestRunResults() | 121 results = base_test_result.TestRunResults() |
123 results.AddResult(HostDrivenExceptionTestResult( | 122 results.AddResult(HostDrivenExceptionTestResult( |
124 test.tagged_name, start_date_ms, exc_info)) | 123 test.tagged_name, start_date_ms, exc_info)) |
125 | 124 |
126 if not results.DidRunPass(): | 125 if not results.DidRunPass(): |
127 return results, test | 126 return results, test |
128 else: | 127 else: |
129 return results, None | 128 return results, None |
OLD | NEW |