OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 | 5 |
6 import logging | 6 import logging |
7 import multiprocessing | 7 import multiprocessing |
8 | 8 |
9 from pylib import android_commands | 9 from pylib import android_commands |
10 from pylib.base.test_result import TestResults | 10 from pylib.base.test_result import TestResults |
(...skipping 29 matching lines...) Expand all Loading... |
40 Args: | 40 Args: |
41 attached_devices: A list of attached devices. | 41 attached_devices: A list of attached devices. |
42 """ | 42 """ |
43 # See more in SetTestsContainer. | 43 # See more in SetTestsContainer. |
44 tests_container = None | 44 tests_container = None |
45 | 45 |
46 def __init__(self, attached_devices, build_type='Debug'): | 46 def __init__(self, attached_devices, build_type='Debug'): |
47 self.attached_devices = attached_devices | 47 self.attached_devices = attached_devices |
48 # Worst case scenario: a device will drop offline per run, so we need | 48 # Worst case scenario: a device will drop offline per run, so we need |
49 # to retry until we're out of devices. | 49 # to retry until we're out of devices. |
50 | |
51 # TODO(frankf): There are two sources of flakiness: | |
52 # 1. Device flakiness | |
53 # 2. Test/product flakiness | |
54 # We should differentiate between these. Otherwise, blindly retrying tests | |
55 # might mask test/product flakiness. For type 2, we should follow the | |
56 # general chrome best practices. | |
57 self.retries = len(self.attached_devices) | 50 self.retries = len(self.attached_devices) |
58 self.tests = [] | 51 self.tests = [] |
59 self.build_type = build_type | 52 self.build_type = build_type |
60 | 53 |
61 def CreateShardedTestRunner(self, device, index): | 54 def CreateShardedTestRunner(self, device, index): |
62 """Factory function to create a suite-specific test runner. | 55 """Factory function to create a suite-specific test runner. |
63 | 56 |
64 Args: | 57 Args: |
65 device: Device serial where this shard will run | 58 device: Device serial where this shard will run |
66 index: Index of this device in the pool. | 59 index: Index of this device in the pool. |
(...skipping 23 matching lines...) Expand all Loading... |
90 logging.warning('*' * 80) | 83 logging.warning('*' * 80) |
91 logging.warning('Sharding in ' + str(len(self.attached_devices)) + | 84 logging.warning('Sharding in ' + str(len(self.attached_devices)) + |
92 ' devices.') | 85 ' devices.') |
93 logging.warning('Note that the output is not synchronized.') | 86 logging.warning('Note that the output is not synchronized.') |
94 logging.warning('Look for the "Final result" banner in the end.') | 87 logging.warning('Look for the "Final result" banner in the end.') |
95 logging.warning('*' * 80) | 88 logging.warning('*' * 80) |
96 final_results = TestResults() | 89 final_results = TestResults() |
97 self._KillHostForwarder() | 90 self._KillHostForwarder() |
98 for retry in xrange(self.retries): | 91 for retry in xrange(self.retries): |
99 logging.warning('Try %d of %d', retry + 1, self.retries) | 92 logging.warning('Try %d of %d', retry + 1, self.retries) |
100 logging.warning('Attempting to run %d tests: %s' | |
101 % (len(self.tests), self.tests)) | |
102 self.SetupSharding(self.tests) | 93 self.SetupSharding(self.tests) |
103 test_runners = [] | 94 test_runners = [] |
104 | 95 |
105 # Try to create N shards, and retrying on failure. | 96 # Try to create N shards, and retrying on failure. |
106 try: | 97 try: |
107 for index, device in enumerate(self.attached_devices): | 98 for index, device in enumerate(self.attached_devices): |
108 logging.warning('*' * 80) | 99 logging.warning('*' * 80) |
109 logging.warning('Creating shard %d for %s', index, device) | 100 logging.warning('Creating shard %d for %s', index, device) |
110 logging.warning('*' * 80) | 101 logging.warning('*' * 80) |
111 test_runner = self.CreateShardedTestRunner(device, index) | 102 test_runner = self.CreateShardedTestRunner(device, index) |
(...skipping 18 matching lines...) Expand all Loading... |
130 continue | 121 continue |
131 test_results = TestResults.FromTestResults(results_lists) | 122 test_results = TestResults.FromTestResults(results_lists) |
132 # Re-check the attached devices for some devices may | 123 # Re-check the attached devices for some devices may |
133 # become offline | 124 # become offline |
134 retry_devices = set(android_commands.GetAttachedDevices()) | 125 retry_devices = set(android_commands.GetAttachedDevices()) |
135 # Remove devices that had exceptions. | 126 # Remove devices that had exceptions. |
136 retry_devices -= TestResults.DeviceExceptions(results_lists) | 127 retry_devices -= TestResults.DeviceExceptions(results_lists) |
137 # Retry on devices that didn't have any exception. | 128 # Retry on devices that didn't have any exception. |
138 self.attached_devices = list(retry_devices) | 129 self.attached_devices = list(retry_devices) |
139 | 130 |
140 # TODO(frankf): Do not break TestResults encapsulation. | 131 # TODO(frankf): Fix the retry logic: |
| 132 # - GetAllBroken() should report all tests not ran. |
| 133 # - Do not break TestResults encapsulation. |
141 if (retry == self.retries - 1 or | 134 if (retry == self.retries - 1 or |
142 len(self.attached_devices) == 0): | 135 len(self.attached_devices) == 0): |
143 all_passed = final_results.ok + test_results.ok | 136 all_passed = final_results.ok + test_results.ok |
144 final_results = test_results | 137 final_results = test_results |
145 final_results.ok = all_passed | 138 final_results.ok = all_passed |
146 break | 139 break |
147 else: | 140 else: |
148 final_results.ok += test_results.ok | 141 final_results.ok += test_results.ok |
| 142 final_results.overall_timed_out = (final_results.overall_timed_out or |
| 143 test_results.overall_timed_out) |
| 144 final_results.overall_fail = (final_results.overall_fail or |
| 145 test_results.overall_fail) |
149 | 146 |
150 self.tests = [] | 147 self.tests = [] |
151 for t in test_results.GetAllBroken(): | 148 for t in test_results.GetAllBroken(): |
152 self.tests += [t.name] | 149 self.tests += [t.name] |
153 if not self.tests: | 150 if not self.tests: |
154 break | 151 break |
155 else: | 152 else: |
156 # We ran out retries, possibly out of healthy devices. | 153 # We ran out retries, possibly out of healthy devices. |
157 # There's no recovery at this point. | 154 # There's no recovery at this point. |
158 raise Exception('Unrecoverable error while retrying test runs.') | 155 raise Exception('Unrecoverable error while retrying test runs.') |
159 self.OnTestsCompleted(test_runners, final_results) | 156 self.OnTestsCompleted(test_runners, final_results) |
160 self._KillHostForwarder() | 157 self._KillHostForwarder() |
161 return final_results | 158 return final_results |
OLD | NEW |