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.base import base_test_result |
23 from pylib.utils import reraiser_thread | 24 from pylib.utils import reraiser_thread |
24 from pylib.utils import watchdog_timer | 25 from pylib.utils import watchdog_timer |
25 | 26 |
26 import base_test_result | |
27 | |
28 | 27 |
29 DEFAULT_TIMEOUT = 7 * 60 # seven minutes | 28 DEFAULT_TIMEOUT = 7 * 60 # seven minutes |
30 | 29 |
31 | 30 |
32 class _ThreadSafeCounter(object): | 31 class _ThreadSafeCounter(object): |
33 """A threadsafe counter.""" | 32 """A threadsafe counter.""" |
34 | 33 |
35 def __init__(self): | 34 def __init__(self): |
36 self._lock = threading.Lock() | 35 self._lock = threading.Lock() |
37 self._value = 0 | 36 self._value = 0 |
(...skipping 24 matching lines...) Expand all Loading... |
62 self.tries = tries | 61 self.tries = tries |
63 | 62 |
64 | 63 |
65 class _TestCollection(object): | 64 class _TestCollection(object): |
66 """A threadsafe collection of tests. | 65 """A threadsafe collection of tests. |
67 | 66 |
68 Args: | 67 Args: |
69 tests: List of tests to put in the collection. | 68 tests: List of tests to put in the collection. |
70 """ | 69 """ |
71 | 70 |
72 def __init__(self, tests=[]): | 71 def __init__(self, tests=None): |
| 72 if not tests: |
| 73 tests = [] |
73 self._lock = threading.Lock() | 74 self._lock = threading.Lock() |
74 self._tests = [] | 75 self._tests = [] |
75 self._tests_in_progress = 0 | 76 self._tests_in_progress = 0 |
76 # Used to signal that an item is avaliable or all items have been handled. | 77 # Used to signal that an item is avaliable or all items have been handled. |
77 self._item_avaliable_or_all_done = threading.Event() | 78 self._item_avaliable_or_all_done = threading.Event() |
78 for t in tests: | 79 for t in tests: |
79 self.add(t) | 80 self.add(t) |
80 | 81 |
81 def _pop(self): | 82 def _pop(self): |
82 """Pop a test from the collection. | 83 """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)) | 358 logging.info('Will run %d tests (%s): %s', len(tests), log_string, str(tests)) |
358 runners = _CreateRunners(runner_factory, devices, setup_timeout) | 359 runners = _CreateRunners(runner_factory, devices, setup_timeout) |
359 try: | 360 try: |
360 return _RunAllTests(runners, test_collection_factory, | 361 return _RunAllTests(runners, test_collection_factory, |
361 num_retries, test_timeout, tag_results_with_device) | 362 num_retries, test_timeout, tag_results_with_device) |
362 finally: | 363 finally: |
363 try: | 364 try: |
364 _TearDownRunners(runners, setup_timeout) | 365 _TearDownRunners(runners, setup_timeout) |
365 except android_commands.errors.DeviceUnresponsiveError as e: | 366 except android_commands.errors.DeviceUnresponsiveError as e: |
366 logging.warning('Device unresponsive during TearDown: [%s]', e) | 367 logging.warning('Device unresponsive during TearDown: [%s]', e) |
OLD | NEW |