OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 """Implements test sharding logic.""" | 5 """Implements test sharding logic.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import threading | 8 import threading |
9 | 9 |
10 from pylib import android_commands | 10 from pylib import android_commands |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 Returns: | 198 Returns: |
199 A TestRunResults object. | 199 A TestRunResults object. |
200 """ | 200 """ |
201 logging.warning('****Running %s tests with %s test runners.' % | 201 logging.warning('****Running %s tests with %s test runners.' % |
202 (len(tests), len(runners))) | 202 (len(tests), len(runners))) |
203 tests_collection = _TestCollection([_Test(t) for t in tests]) | 203 tests_collection = _TestCollection([_Test(t) for t in tests]) |
204 results = [] | 204 results = [] |
205 watcher = watchdog_timer.WatchdogTimer(timeout) | 205 watcher = watchdog_timer.WatchdogTimer(timeout) |
206 workers = reraiser_thread.ReraiserThreadGroup( | 206 workers = reraiser_thread.ReraiserThreadGroup( |
207 [reraiser_thread.ReraiserThread(_RunTestsFromQueue, | 207 [reraiser_thread.ReraiserThread(_RunTestsFromQueue, |
208 [r, tests_collection, results, watcher]) | 208 [r, tests_collection, results, watcher], |
| 209 name=r.device[-4:]) |
209 for r in runners]) | 210 for r in runners]) |
210 workers.StartAll() | 211 workers.StartAll() |
211 workers.JoinAll(watcher) | 212 workers.JoinAll(watcher) |
212 run_results = base_test_result.TestRunResults() | 213 run_results = base_test_result.TestRunResults() |
213 for r in results: | 214 for r in results: |
214 run_results.AddTestRunResults(r) | 215 run_results.AddTestRunResults(r) |
215 return run_results | 216 return run_results |
216 | 217 |
217 | 218 |
218 def _CreateRunners(runner_factory, devices, timeout=None): | 219 def _CreateRunners(runner_factory, devices, timeout=None): |
219 """Creates a test runner for each device and calls SetUp() in parallel. | 220 """Creates a test runner for each device and calls SetUp() in parallel. |
220 | 221 |
221 Note: if a device is unresponsive the corresponding TestRunner will not be | 222 Note: if a device is unresponsive the corresponding TestRunner will not be |
222 included in the returned list. | 223 included in the returned list. |
223 | 224 |
224 Args: | 225 Args: |
225 runner_factory: callable that takes a device and index and returns a | 226 runner_factory: callable that takes a device and index and returns a |
226 TestRunner object. | 227 TestRunner object. |
227 devices: list of device serial numbers as strings. | 228 devices: list of device serial numbers as strings. |
228 timeout: watchdog timeout in seconds, defaults to the default timeout. | 229 timeout: watchdog timeout in seconds, defaults to the default timeout. |
229 | 230 |
230 Returns: | 231 Returns: |
231 A list of TestRunner objects. | 232 A list of TestRunner objects. |
232 """ | 233 """ |
233 logging.warning('****Creating %s test runners.' % len(devices)) | 234 logging.warning('****Creating %s test runners.' % len(devices)) |
234 runners = [] | 235 runners = [] |
235 counter = _ThreadSafeCounter() | 236 counter = _ThreadSafeCounter() |
236 threads = reraiser_thread.ReraiserThreadGroup( | 237 threads = reraiser_thread.ReraiserThreadGroup( |
237 [reraiser_thread.ReraiserThread(_SetUp, [runner_factory, d, runners, | 238 [reraiser_thread.ReraiserThread(_SetUp, |
238 counter]) | 239 [runner_factory, d, runners, counter], |
| 240 name=d[-4:]) |
239 for d in devices]) | 241 for d in devices]) |
240 threads.StartAll() | 242 threads.StartAll() |
241 threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) | 243 threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) |
242 return runners | 244 return runners |
243 | 245 |
244 | 246 |
245 def _TearDownRunners(runners, timeout=None): | 247 def _TearDownRunners(runners, timeout=None): |
246 """Calls TearDown() for each test runner in parallel. | 248 """Calls TearDown() for each test runner in parallel. |
247 Args: | 249 Args: |
248 runners: a list of TestRunner objects. | 250 runners: a list of TestRunner objects. |
249 timeout: watchdog timeout in seconds, defaults to the default timeout. | 251 timeout: watchdog timeout in seconds, defaults to the default timeout. |
250 """ | 252 """ |
251 threads = reraiser_thread.ReraiserThreadGroup( | 253 threads = reraiser_thread.ReraiserThreadGroup( |
252 [reraiser_thread.ReraiserThread(runner.TearDown) | 254 [reraiser_thread.ReraiserThread(r.TearDown, name=r.device[-4:]) |
253 for runner in runners]) | 255 for r in runners]) |
254 threads.StartAll() | 256 threads.StartAll() |
255 threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) | 257 threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) |
256 | 258 |
257 | 259 |
258 def ShardAndRunTests(runner_factory, devices, tests, build_type='Debug', | 260 def ShardAndRunTests(runner_factory, devices, tests, build_type='Debug', |
259 test_timeout=DEFAULT_TIMEOUT, | 261 test_timeout=DEFAULT_TIMEOUT, |
260 setup_timeout=DEFAULT_TIMEOUT): | 262 setup_timeout=DEFAULT_TIMEOUT): |
261 """Run all tests on attached devices, retrying tests that don't pass. | 263 """Run all tests on attached devices, retrying tests that don't pass. |
262 | 264 |
263 Args: | 265 Args: |
(...skipping 14 matching lines...) Expand all Loading... |
278 runners = _CreateRunners(runner_factory, devices, setup_timeout) | 280 runners = _CreateRunners(runner_factory, devices, setup_timeout) |
279 try: | 281 try: |
280 return _RunAllTests(runners, tests, test_timeout) | 282 return _RunAllTests(runners, tests, test_timeout) |
281 finally: | 283 finally: |
282 try: | 284 try: |
283 _TearDownRunners(runners, setup_timeout) | 285 _TearDownRunners(runners, setup_timeout) |
284 except android_commands.errors.DeviceUnresponsiveError as e: | 286 except android_commands.errors.DeviceUnresponsiveError as e: |
285 logging.warning('****Device unresponsive during TearDown: [%s]', e) | 287 logging.warning('****Device unresponsive during TearDown: [%s]', e) |
286 finally: | 288 finally: |
287 forwarder.Forwarder.KillHost(build_type) | 289 forwarder.Forwarder.KillHost(build_type) |
OLD | NEW |