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 """Takes care of sharding the python-drive tests in multiple devices.""" | 5 """Takes care of sharding the python-drive tests in multiple devices.""" |
6 | 6 |
7 import copy | 7 import copy |
8 import logging | 8 import logging |
9 import multiprocessing | 9 import multiprocessing |
10 | 10 |
11 from pylib.base import sharded_tests_queue | 11 from pylib.base import sharded_tests_queue |
12 from pylib.base.test_result import TestResults | 12 from pylib.base.test_result import TestResults |
13 from pylib.instrumentation.run_java_tests import FatalTestException | |
14 | 13 |
15 from python_test_caller import CallPythonTest | 14 from python_test_caller import CallPythonTest |
16 | 15 |
17 | 16 |
18 def SetTestsContainer(tests_container): | 17 def SetTestsContainer(tests_container): |
19 """Sets PythonTestSharder as a top-level field. | 18 """Sets PythonTestSharder as a top-level field. |
20 | 19 |
21 PythonTestSharder uses multiprocessing.Pool, which creates a pool of | 20 PythonTestSharder uses multiprocessing.Pool, which creates a pool of |
22 processes. This is used to initialize each worker in the pool, ensuring that | 21 processes. This is used to initialize each worker in the pool, ensuring that |
23 each worker has access to this shared pool of tests. | 22 each worker has access to this shared pool of tests. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 pool = multiprocessing.Pool(len(self.attached_devices), | 131 pool = multiprocessing.Pool(len(self.attached_devices), |
133 SetTestsContainer, | 132 SetTestsContainer, |
134 [PythonTestSharder.tests_container]) | 133 [PythonTestSharder.tests_container]) |
135 | 134 |
136 # List of TestResults objects from each test execution. | 135 # List of TestResults objects from each test execution. |
137 try: | 136 try: |
138 results_lists = pool.map(_DefaultRunnable, test_runners) | 137 results_lists = pool.map(_DefaultRunnable, test_runners) |
139 except Exception: | 138 except Exception: |
140 logging.exception('Unable to run tests. Something with the ' | 139 logging.exception('Unable to run tests. Something with the ' |
141 'PythonTestRunners has gone wrong.') | 140 'PythonTestRunners has gone wrong.') |
142 raise FatalTestException('PythonTestRunners were unable to run tests.') | 141 raise Exception('PythonTestRunners were unable to run tests.') |
143 | 142 |
144 test_results = TestResults.FromTestResults(results_lists) | 143 test_results = TestResults.FromTestResults(results_lists) |
145 # Accumulate passing results. | 144 # Accumulate passing results. |
146 all_passed += test_results.ok | 145 all_passed += test_results.ok |
147 # If we have failed tests, map them to tests to retry. | 146 # If we have failed tests, map them to tests to retry. |
148 failed_tests = test_results.GetAllBroken() | 147 failed_tests = test_results.GetAllBroken() |
149 tests_to_run = self._GetTestsToRetry(self.tests, | 148 tests_to_run = self._GetTestsToRetry(self.tests, |
150 failed_tests) | 149 failed_tests) |
151 | 150 |
152 # Bail out early if we have no more tests. This can happen if all tests | 151 # Bail out early if we have no more tests. This can happen if all tests |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 failed_tests: a list of SingleTestResults representing failed tests. | 194 failed_tests: a list of SingleTestResults representing failed tests. |
196 | 195 |
197 Returns: | 196 Returns: |
198 A list of test objects which correspond to test names found in | 197 A list of test objects which correspond to test names found in |
199 failed_tests, or an empty list if there is no correspondence. | 198 failed_tests, or an empty list if there is no correspondence. |
200 """ | 199 """ |
201 failed_test_names = map(lambda t: t.test_name, failed_tests) | 200 failed_test_names = map(lambda t: t.test_name, failed_tests) |
202 tests_to_retry = [t for t in available_tests | 201 tests_to_retry = [t for t in available_tests |
203 if t.qualified_name in failed_test_names] | 202 if t.qualified_name in failed_test_names] |
204 return tests_to_retry | 203 return tests_to_retry |
OLD | NEW |