| 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. |
| 50 self.retries = len(self.attached_devices) | 57 self.retries = len(self.attached_devices) |
| 51 self.tests = [] | 58 self.tests = [] |
| 52 self.build_type = build_type | 59 self.build_type = build_type |
| 53 | 60 |
| 54 def CreateShardedTestRunner(self, device, index): | 61 def CreateShardedTestRunner(self, device, index): |
| 55 """Factory function to create a suite-specific test runner. | 62 """Factory function to create a suite-specific test runner. |
| 56 | 63 |
| 57 Args: | 64 Args: |
| 58 device: Device serial where this shard will run | 65 device: Device serial where this shard will run |
| 59 index: Index of this device in the pool. | 66 index: Index of this device in the pool. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 83 logging.warning('*' * 80) | 90 logging.warning('*' * 80) |
| 84 logging.warning('Sharding in ' + str(len(self.attached_devices)) + | 91 logging.warning('Sharding in ' + str(len(self.attached_devices)) + |
| 85 ' devices.') | 92 ' devices.') |
| 86 logging.warning('Note that the output is not synchronized.') | 93 logging.warning('Note that the output is not synchronized.') |
| 87 logging.warning('Look for the "Final result" banner in the end.') | 94 logging.warning('Look for the "Final result" banner in the end.') |
| 88 logging.warning('*' * 80) | 95 logging.warning('*' * 80) |
| 89 final_results = TestResults() | 96 final_results = TestResults() |
| 90 self._KillHostForwarder() | 97 self._KillHostForwarder() |
| 91 for retry in xrange(self.retries): | 98 for retry in xrange(self.retries): |
| 92 logging.warning('Try %d of %d', retry + 1, self.retries) | 99 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)) |
| 93 self.SetupSharding(self.tests) | 102 self.SetupSharding(self.tests) |
| 94 test_runners = [] | 103 test_runners = [] |
| 95 | 104 |
| 96 # Try to create N shards, and retrying on failure. | 105 # Try to create N shards, and retrying on failure. |
| 97 try: | 106 try: |
| 98 for index, device in enumerate(self.attached_devices): | 107 for index, device in enumerate(self.attached_devices): |
| 99 logging.warning('*' * 80) | 108 logging.warning('*' * 80) |
| 100 logging.warning('Creating shard %d for %s', index, device) | 109 logging.warning('Creating shard %d for %s', index, device) |
| 101 logging.warning('*' * 80) | 110 logging.warning('*' * 80) |
| 102 test_runner = self.CreateShardedTestRunner(device, index) | 111 test_runner = self.CreateShardedTestRunner(device, index) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 continue | 130 continue |
| 122 test_results = TestResults.FromTestResults(results_lists) | 131 test_results = TestResults.FromTestResults(results_lists) |
| 123 # Re-check the attached devices for some devices may | 132 # Re-check the attached devices for some devices may |
| 124 # become offline | 133 # become offline |
| 125 retry_devices = set(android_commands.GetAttachedDevices()) | 134 retry_devices = set(android_commands.GetAttachedDevices()) |
| 126 # Remove devices that had exceptions. | 135 # Remove devices that had exceptions. |
| 127 retry_devices -= TestResults.DeviceExceptions(results_lists) | 136 retry_devices -= TestResults.DeviceExceptions(results_lists) |
| 128 # Retry on devices that didn't have any exception. | 137 # Retry on devices that didn't have any exception. |
| 129 self.attached_devices = list(retry_devices) | 138 self.attached_devices = list(retry_devices) |
| 130 | 139 |
| 131 # TODO(frankf): Fix the retry logic: | 140 # TODO(frankf): Do not break TestResults encapsulation. |
| 132 # - GetAllBroken() should report all tests not ran. | |
| 133 # - Do not break TestResults encapsulation. | |
| 134 if (retry == self.retries - 1 or | 141 if (retry == self.retries - 1 or |
| 135 len(self.attached_devices) == 0): | 142 len(self.attached_devices) == 0): |
| 136 all_passed = final_results.ok + test_results.ok | 143 all_passed = final_results.ok + test_results.ok |
| 137 final_results = test_results | 144 final_results = test_results |
| 138 final_results.ok = all_passed | 145 final_results.ok = all_passed |
| 139 break | 146 break |
| 140 else: | 147 else: |
| 141 final_results.ok += test_results.ok | 148 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) | |
| 146 | 149 |
| 147 self.tests = [] | 150 self.tests = [] |
| 148 for t in test_results.GetAllBroken(): | 151 for t in test_results.GetAllBroken(): |
| 149 self.tests += [t.name] | 152 self.tests += [t.name] |
| 150 if not self.tests: | 153 if not self.tests: |
| 151 break | 154 break |
| 152 else: | 155 else: |
| 153 # We ran out retries, possibly out of healthy devices. | 156 # We ran out retries, possibly out of healthy devices. |
| 154 # There's no recovery at this point. | 157 # There's no recovery at this point. |
| 155 raise Exception('Unrecoverable error while retrying test runs.') | 158 raise Exception('Unrecoverable error while retrying test runs.') |
| 156 self.OnTestsCompleted(test_runners, final_results) | 159 self.OnTestsCompleted(test_runners, final_results) |
| 157 self._KillHostForwarder() | 160 self._KillHostForwarder() |
| 158 return final_results | 161 return final_results |
| OLD | NEW |