| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import fnmatch | 5 import fnmatch |
| 6 import imp | 6 import imp |
| 7 import logging | 7 import logging |
| 8 import posixpath | 8 import posixpath |
| 9 import signal | 9 import signal |
| 10 import thread | 10 import thread |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 exit_now = threading.Event() | 67 exit_now = threading.Event() |
| 68 | 68 |
| 69 @local_device_environment.handle_shard_failures | 69 @local_device_environment.handle_shard_failures |
| 70 def run_tests_on_device(dev, tests, results): | 70 def run_tests_on_device(dev, tests, results): |
| 71 for test in tests: | 71 for test in tests: |
| 72 if exit_now.isSet(): | 72 if exit_now.isSet(): |
| 73 thread.exit() | 73 thread.exit() |
| 74 | 74 |
| 75 result = None | 75 result = None |
| 76 rerun = None |
| 76 try: | 77 try: |
| 77 result = self._RunTest(dev, test) | 78 result, rerun = self._RunTest(dev, test) |
| 78 if isinstance(result, base_test_result.BaseTestResult): | 79 if isinstance(result, base_test_result.BaseTestResult): |
| 79 results.AddResult(result) | 80 results.AddResult(result) |
| 80 elif isinstance(result, list): | 81 elif isinstance(result, list): |
| 81 results.AddResults(result) | 82 results.AddResults(result) |
| 82 else: | 83 else: |
| 83 raise Exception( | 84 raise Exception( |
| 84 'Unexpected result type: %s' % type(result).__name__) | 85 'Unexpected result type: %s' % type(result).__name__) |
| 85 except: | 86 except: |
| 86 if isinstance(tests, test_collection.TestCollection): | 87 if isinstance(tests, test_collection.TestCollection): |
| 87 tests.add(test) | 88 rerun = test |
| 88 raise | 89 raise |
| 89 finally: | 90 finally: |
| 90 if isinstance(tests, test_collection.TestCollection): | 91 if isinstance(tests, test_collection.TestCollection): |
| 92 if rerun: |
| 93 tests.add(rerun) |
| 91 tests.test_completed() | 94 tests.test_completed() |
| 92 | 95 |
| 93 | |
| 94 logging.info('Finished running tests on this device.') | 96 logging.info('Finished running tests on this device.') |
| 95 | 97 |
| 96 class TestsTerminated(Exception): | 98 class TestsTerminated(Exception): |
| 97 pass | 99 pass |
| 98 | 100 |
| 99 def stop_tests(_signum, _frame): | 101 def stop_tests(_signum, _frame): |
| 100 logging.critical('Received SIGTERM. Stopping test execution.') | 102 logging.critical('Received SIGTERM. Stopping test execution.') |
| 101 exit_now.set() | 103 exit_now.set() |
| 102 raise TestsTerminated() | 104 raise TestsTerminated() |
| 103 | 105 |
| 104 try: | 106 try: |
| 105 with signal_handler.SignalHandler(signal.SIGTERM, stop_tests): | 107 with signal_handler.SignalHandler(signal.SIGTERM, stop_tests): |
| 106 tries = 0 | 108 tries = 0 |
| 107 results = [] | 109 results = [] |
| 108 while tries < self._env.max_tries and tests: | 110 while tries < self._env.max_tries and tests: |
| 109 logging.info('STARTING TRY #%d/%d', tries + 1, self._env.max_tries) | 111 logging.info('STARTING TRY #%d/%d', tries + 1, self._env.max_tries) |
| 110 logging.info('Will run %d tests on %d devices: %s', | 112 logging.info('Will run %d tests on %d devices: %s', |
| 111 len(tests), len(self._env.devices), | 113 len(tests), len(self._env.devices), |
| 112 ', '.join(str(d) for d in self._env.devices)) | 114 ', '.join(str(d) for d in self._env.devices)) |
| 113 for t in tests: | 115 for t in tests: |
| 114 logging.debug(' %s', t) | 116 logging.debug(' %s', t) |
| 115 | 117 |
| 116 try_results = base_test_result.TestRunResults() | 118 try_results = base_test_result.TestRunResults() |
| 117 test_names = (self._GetUniqueTestName(t) for t in tests) | 119 test_names = (self._GetUniqueTestName(t) for t in tests) |
| 118 try_results.AddResults( | 120 try_results.AddResults( |
| 119 base_test_result.BaseTestResult( | 121 base_test_result.BaseTestResult( |
| 120 t, base_test_result.ResultType.UNKNOWN) | 122 t, base_test_result.ResultType.NOTRUN) |
| 121 for t in test_names if not t.endswith('*')) | 123 for t in test_names if not t.endswith('*')) |
| 122 | 124 |
| 123 try: | 125 try: |
| 124 if self._ShouldShard(): | 126 if self._ShouldShard(): |
| 125 tc = test_collection.TestCollection(self._CreateShards(tests)) | 127 tc = test_collection.TestCollection(self._CreateShards(tests)) |
| 126 self._env.parallel_devices.pMap( | 128 self._env.parallel_devices.pMap( |
| 127 run_tests_on_device, tc, try_results).pGet(None) | 129 run_tests_on_device, tc, try_results).pGet(None) |
| 128 else: | 130 else: |
| 129 self._env.parallel_devices.pMap( | 131 self._env.parallel_devices.pMap( |
| 130 run_tests_on_device, tests, try_results).pGet(None) | 132 run_tests_on_device, tests, try_results).pGet(None) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 199 |
| 198 def _RunTest(self, device, test): | 200 def _RunTest(self, device, test): |
| 199 raise NotImplementedError | 201 raise NotImplementedError |
| 200 | 202 |
| 201 def _ShouldShard(self): | 203 def _ShouldShard(self): |
| 202 raise NotImplementedError | 204 raise NotImplementedError |
| 203 | 205 |
| 204 | 206 |
| 205 class NoTestsError(Exception): | 207 class NoTestsError(Exception): |
| 206 """Error for when no tests are found.""" | 208 """Error for when no tests are found.""" |
| OLD | NEW |