Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: build/android/pylib/base/base_test_sharder.py

Issue 11879031: [Android] Move base tests classes to pylib/base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 5
6 import android_commands
7 import logging 6 import logging
8 import multiprocessing 7 import multiprocessing
9 8
10 from android_commands import errors 9 from pylib import android_commands
11 from forwarder import Forwarder 10 from pylib.base.test_result import TestResults
12 from test_result import TestResults 11 from pylib.forwarder import Forwarder
13 12
14 13
15 def _ShardedTestRunnable(test): 14 def _ShardedTestRunnable(test):
16 """Standalone function needed by multiprocessing.Pool.""" 15 """Standalone function needed by multiprocessing.Pool."""
17 log_format = '[' + test.device + '] # %(asctime)-15s: %(message)s' 16 log_format = '[' + test.device + '] # %(asctime)-15s: %(message)s'
18 if logging.getLogger().handlers: 17 if logging.getLogger().handlers:
19 logging.getLogger().handlers[0].setFormatter(logging.Formatter(log_format)) 18 logging.getLogger().handlers[0].setFormatter(logging.Formatter(log_format))
20 else: 19 else:
21 logging.basicConfig(format=log_format) 20 logging.basicConfig(format=log_format)
22 # Handle SystemExit here since python has a bug to exit current process 21 # Handle SystemExit here since python has a bug to exit current process
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 test_runners = [] 94 test_runners = []
96 95
97 # Try to create N shards, and retrying on failure. 96 # Try to create N shards, and retrying on failure.
98 try: 97 try:
99 for index, device in enumerate(self.attached_devices): 98 for index, device in enumerate(self.attached_devices):
100 logging.warning('*' * 80) 99 logging.warning('*' * 80)
101 logging.warning('Creating shard %d for %s', index, device) 100 logging.warning('Creating shard %d for %s', index, device)
102 logging.warning('*' * 80) 101 logging.warning('*' * 80)
103 test_runner = self.CreateShardedTestRunner(device, index) 102 test_runner = self.CreateShardedTestRunner(device, index)
104 test_runners += [test_runner] 103 test_runners += [test_runner]
105 except errors.DeviceUnresponsiveError as e: 104 except android_commands.errors.DeviceUnresponsiveError as e:
106 logging.critical('****Failed to create a shard: [%s]', e) 105 logging.critical('****Failed to create a shard: [%s]', e)
107 self.attached_devices.remove(device) 106 self.attached_devices.remove(device)
108 continue 107 continue
109 108
110 logging.warning('Starting...') 109 logging.warning('Starting...')
111 pool = multiprocessing.Pool(len(self.attached_devices), 110 pool = multiprocessing.Pool(len(self.attached_devices),
112 SetTestsContainer, 111 SetTestsContainer,
113 [BaseTestSharder.tests_container]) 112 [BaseTestSharder.tests_container])
114 # map can't handle KeyboardInterrupt exception. It's a python bug. 113 # map can't handle KeyboardInterrupt exception. It's a python bug.
115 # So use map_async instead. 114 # So use map_async instead.
116 async_results = pool.map_async(_ShardedTestRunnable, test_runners) 115 async_results = pool.map_async(_ShardedTestRunnable, test_runners)
117 try: 116 try:
118 results_lists = async_results.get(999999) 117 results_lists = async_results.get(999999)
119 except errors.DeviceUnresponsiveError as e: 118 except android_commands.errors.DeviceUnresponsiveError as e:
120 logging.critical('****Failed to run test: [%s]', e) 119 logging.critical('****Failed to run test: [%s]', e)
121 self.attached_devices = android_commands.GetAttachedDevices() 120 self.attached_devices = android_commands.GetAttachedDevices()
122 continue 121 continue
123 test_results = TestResults.FromTestResults(results_lists) 122 test_results = TestResults.FromTestResults(results_lists)
124 # Re-check the attached devices for some devices may 123 # Re-check the attached devices for some devices may
125 # become offline 124 # become offline
126 retry_devices = set(android_commands.GetAttachedDevices()) 125 retry_devices = set(android_commands.GetAttachedDevices())
127 # Remove devices that had exceptions. 126 # Remove devices that had exceptions.
128 retry_devices -= TestResults.DeviceExceptions(results_lists) 127 retry_devices -= TestResults.DeviceExceptions(results_lists)
129 # Retry on devices that didn't have any exception. 128 # Retry on devices that didn't have any exception.
(...skipping 14 matching lines...) Expand all
144 self.tests += [t.name] 143 self.tests += [t.name]
145 if not self.tests: 144 if not self.tests:
146 break 145 break
147 else: 146 else:
148 # We ran out retries, possibly out of healthy devices. 147 # We ran out retries, possibly out of healthy devices.
149 # There's no recovery at this point. 148 # There's no recovery at this point.
150 raise Exception('Unrecoverable error while retrying test runs.') 149 raise Exception('Unrecoverable error while retrying test runs.')
151 self.OnTestsCompleted(test_runners, final_results) 150 self.OnTestsCompleted(test_runners, final_results)
152 self._KillHostForwarder() 151 self._KillHostForwarder()
153 return final_results 152 return final_results
OLDNEW
« no previous file with comments | « build/android/pylib/base/base_test_runner.py ('k') | build/android/pylib/base/sharded_tests_queue.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698