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 android_commands |
6 import logging | 7 import logging |
7 import multiprocessing | 8 import multiprocessing |
8 | 9 |
9 from test_result import TestResults | 10 from test_result import TestResults |
10 | 11 |
11 | 12 |
12 def _ShardedTestRunnable(test): | 13 def _ShardedTestRunnable(test): |
13 """Standalone function needed by multiprocessing.Pool.""" | 14 """Standalone function needed by multiprocessing.Pool.""" |
14 log_format = '[' + test.device + '] # %(asctime)-15s: %(message)s' | 15 log_format = '[' + test.device + '] # %(asctime)-15s: %(message)s' |
15 if logging.getLogger().handlers: | 16 if logging.getLogger().handlers: |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 test_runner = self.CreateShardedTestRunner(device, index) | 90 test_runner = self.CreateShardedTestRunner(device, index) |
90 test_runners += [test_runner] | 91 test_runners += [test_runner] |
91 logging.warning('Starting...') | 92 logging.warning('Starting...') |
92 pool = multiprocessing.Pool(len(self.attached_devices), | 93 pool = multiprocessing.Pool(len(self.attached_devices), |
93 SetTestsContainer, | 94 SetTestsContainer, |
94 [BaseTestSharder.tests_container]) | 95 [BaseTestSharder.tests_container]) |
95 # map can't handle KeyboardInterrupt exception. It's a python bug. | 96 # map can't handle KeyboardInterrupt exception. It's a python bug. |
96 # So use map_async instead. | 97 # So use map_async instead. |
97 async_results = pool.map_async(_ShardedTestRunnable, test_runners) | 98 async_results = pool.map_async(_ShardedTestRunnable, test_runners) |
98 results_lists = async_results.get(999999) | 99 results_lists = async_results.get(999999) |
| 100 |
99 test_results = TestResults.FromTestResults(results_lists) | 101 test_results = TestResults.FromTestResults(results_lists) |
100 if retry == self.retries - 1: | 102 # Re-check the attached devices for some devices may |
| 103 # become offline |
| 104 retry_devices = set(android_commands.GetAttachedDevices()) |
| 105 # Remove devices that had exceptions. |
| 106 retry_devices -= TestResults.DeviceExceptions(results_lists) |
| 107 # Retry on devices that didn't have any exception. |
| 108 self.attached_devices = list(retry_devices) |
| 109 if (retry == self.retries - 1 or |
| 110 len(self.attached_devices) == 0): |
101 all_passed = final_results.ok + test_results.ok | 111 all_passed = final_results.ok + test_results.ok |
102 final_results = test_results | 112 final_results = test_results |
103 final_results.ok = all_passed | 113 final_results.ok = all_passed |
104 break | 114 break |
105 else: | 115 else: |
106 final_results.ok += test_results.ok | 116 final_results.ok += test_results.ok |
107 self.tests = [] | 117 self.tests = [] |
108 for t in test_results.GetAllBroken(): | 118 for t in test_results.GetAllBroken(): |
109 self.tests += [t.name] | 119 self.tests += [t.name] |
110 if not self.tests: | 120 if not self.tests: |
111 break | 121 break |
112 self.OnTestsCompleted(test_runners, final_results) | 122 self.OnTestsCompleted(test_runners, final_results) |
113 return final_results | 123 return final_results |
OLD | NEW |