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 """Dispatches tests, either sharding or replicating them. | 5 """Dispatches tests, either sharding or replicating them. |
6 | 6 |
7 Performs the following steps: | 7 Performs the following steps: |
8 * Create a test collection factory, using the given tests | 8 * Create a test collection factory, using the given tests |
9 - If sharding: test collection factory returns the same shared test collection | 9 - If sharding: test collection factory returns the same shared test collection |
10 to all test runners | 10 to all test runners |
11 - If replciating: test collection factory returns a unique test collection to | 11 - If replciating: test collection factory returns a unique test collection to |
12 each test runner, with the same set of tests in each. | 12 each test runner, with the same set of tests in each. |
13 * Create a test runner for each device. | 13 * Create a test runner for each device. |
14 * Run each test runner in its own thread, grabbing tests from the test | 14 * Run each test runner in its own thread, grabbing tests from the test |
15 collection until there are no tests left. | 15 collection until there are no tests left. |
16 """ | 16 """ |
17 | 17 |
18 import logging | 18 import logging |
19 import threading | 19 import threading |
20 | 20 |
21 from pylib import android_commands | 21 from pylib import android_commands |
22 from pylib import constants | 22 from pylib import constants |
23 from pylib.utils import reraiser_thread | 23 from pylib.utils import reraiser_thread |
24 from pylib.utils import watchdog_timer | 24 from pylib.utils import watchdog_timer |
25 | 25 |
26 import base_test_result | 26 from . import base_test_result |
27 | 27 |
28 | 28 |
29 DEFAULT_TIMEOUT = 7 * 60 # seven minutes | 29 DEFAULT_TIMEOUT = 7 * 60 # seven minutes |
30 | 30 |
31 | 31 |
32 class _ThreadSafeCounter(object): | 32 class _ThreadSafeCounter(object): |
33 """A threadsafe counter.""" | 33 """A threadsafe counter.""" |
34 | 34 |
35 def __init__(self): | 35 def __init__(self): |
36 self._lock = threading.Lock() | 36 self._lock = threading.Lock() |
(...skipping 25 matching lines...) Expand all Loading... |
62 self.tries = tries | 62 self.tries = tries |
63 | 63 |
64 | 64 |
65 class _TestCollection(object): | 65 class _TestCollection(object): |
66 """A threadsafe collection of tests. | 66 """A threadsafe collection of tests. |
67 | 67 |
68 Args: | 68 Args: |
69 tests: List of tests to put in the collection. | 69 tests: List of tests to put in the collection. |
70 """ | 70 """ |
71 | 71 |
72 def __init__(self, tests=[]): | 72 def __init__(self, tests=None): |
| 73 if not tests: |
| 74 tests = [] |
73 self._lock = threading.Lock() | 75 self._lock = threading.Lock() |
74 self._tests = [] | 76 self._tests = [] |
75 self._tests_in_progress = 0 | 77 self._tests_in_progress = 0 |
76 # Used to signal that an item is avaliable or all items have been handled. | 78 # Used to signal that an item is avaliable or all items have been handled. |
77 self._item_avaliable_or_all_done = threading.Event() | 79 self._item_avaliable_or_all_done = threading.Event() |
78 for t in tests: | 80 for t in tests: |
79 self.add(t) | 81 self.add(t) |
80 | 82 |
81 def _pop(self): | 83 def _pop(self): |
82 """Pop a test from the collection. | 84 """Pop a test from the collection. |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 logging.info('Will run %d tests (%s): %s', len(tests), log_string, str(tests)) | 359 logging.info('Will run %d tests (%s): %s', len(tests), log_string, str(tests)) |
358 runners = _CreateRunners(runner_factory, devices, setup_timeout) | 360 runners = _CreateRunners(runner_factory, devices, setup_timeout) |
359 try: | 361 try: |
360 return _RunAllTests(runners, test_collection_factory, | 362 return _RunAllTests(runners, test_collection_factory, |
361 num_retries, test_timeout, tag_results_with_device) | 363 num_retries, test_timeout, tag_results_with_device) |
362 finally: | 364 finally: |
363 try: | 365 try: |
364 _TearDownRunners(runners, setup_timeout) | 366 _TearDownRunners(runners, setup_timeout) |
365 except android_commands.errors.DeviceUnresponsiveError as e: | 367 except android_commands.errors.DeviceUnresponsiveError as e: |
366 logging.warning('Device unresponsive during TearDown: [%s]', e) | 368 logging.warning('Device unresponsive during TearDown: [%s]', e) |
OLD | NEW |