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

Side by Side Diff: build/android/provision_devices.py

Issue 481433004: [Android] Fix the location prompt flake in provision_devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + remove persist property changes. Created 6 years, 4 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Provisions Android devices with settings required for bots. 7 """Provisions Android devices with settings required for bots.
8 8
9 Usage: 9 Usage:
10 ./provision_devices.py [-d <device serial number>] 10 ./provision_devices.py [-d <device serial number>]
(...skipping 17 matching lines...) Expand all
28 28
29 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 29 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT,
30 'third_party', 'android_testrunner')) 30 'third_party', 'android_testrunner'))
31 import errors 31 import errors
32 32
33 def KillHostHeartbeat(): 33 def KillHostHeartbeat():
34 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) 34 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE)
35 stdout, _ = ps.communicate() 35 stdout, _ = ps.communicate()
36 matches = re.findall('\\n.*host_heartbeat.*', stdout) 36 matches = re.findall('\\n.*host_heartbeat.*', stdout)
37 for match in matches: 37 for match in matches:
38 print 'An instance of host heart beart running... will kill' 38 logging.info('An instance of host heart beart running... will kill')
39 pid = re.findall('(\d+)', match)[0] 39 pid = re.findall('(\d+)', match)[0]
40 subprocess.call(['kill', str(pid)]) 40 subprocess.call(['kill', str(pid)])
41 41
42 42
43 def LaunchHostHeartbeat(): 43 def LaunchHostHeartbeat():
44 # Kill if existing host_heartbeat 44 # Kill if existing host_heartbeat
45 KillHostHeartbeat() 45 KillHostHeartbeat()
46 # Launch a new host_heartbeat 46 # Launch a new host_heartbeat
47 print 'Spawning host heartbeat...' 47 logging.info('Spawning host heartbeat...')
48 subprocess.Popen([os.path.join(constants.DIR_SOURCE_ROOT, 48 subprocess.Popen([os.path.join(constants.DIR_SOURCE_ROOT,
49 'build/android/host_heartbeat.py')]) 49 'build/android/host_heartbeat.py')])
50 50
51 51
52 def PushAndLaunchAdbReboot(devices, target): 52 def PushAndLaunchAdbReboot(devices, target):
53 """Pushes and launches the adb_reboot binary on the device. 53 """Pushes and launches the adb_reboot binary on the device.
54 54
55 Arguments: 55 Arguments:
56 devices: The list of serial numbers of the device to which the 56 devices: The list of serial numbers of the device to which the
57 adb_reboot binary should be pushed. 57 adb_reboot binary should be pushed.
58 target : The build target (example, Debug or Release) which helps in 58 target : The build target (example, Debug or Release) which helps in
59 locating the adb_reboot binary. 59 locating the adb_reboot binary.
60 """ 60 """
61 for device_serial in devices: 61 for device_serial in devices:
62 print 'Will push and launch adb_reboot on %s' % device_serial 62 logging.info('Will push and launch adb_reboot on %s' % device_serial)
63 device = device_utils.DeviceUtils(device_serial) 63 device = device_utils.DeviceUtils(device_serial)
64 # Kill if adb_reboot is already running. 64 # Kill if adb_reboot is already running.
65 try: 65 try:
66 # Don't try to kill adb_reboot more than once. We don't expect it to be 66 # Don't try to kill adb_reboot more than once. We don't expect it to be
67 # running at all. 67 # running at all.
68 device.KillAll('adb_reboot', blocking=True, timeout=2, retries=0) 68 device.KillAll('adb_reboot', blocking=True, timeout=2, retries=0)
69 except device_errors.CommandFailedError: 69 except device_errors.CommandFailedError:
70 # We can safely ignore the exception because we don't expect adb_reboot 70 # We can safely ignore the exception because we don't expect adb_reboot
71 # to be running. 71 # to be running.
72 pass 72 pass
73 # Push adb_reboot 73 # Push adb_reboot
74 print ' Pushing adb_reboot ...' 74 logging.info(' Pushing adb_reboot ...')
75 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, 75 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT,
76 'out/%s/adb_reboot' % target) 76 'out/%s/adb_reboot' % target)
77 device.PushChangedFiles(adb_reboot, '/data/local/tmp/') 77 device.PushChangedFiles(adb_reboot, '/data/local/tmp/')
78 # Launch adb_reboot 78 # Launch adb_reboot
79 print ' Launching adb_reboot ...' 79 logging.info(' Launching adb_reboot ...')
80 device.old_interface.GetAndroidToolStatusAndOutput( 80 device.old_interface.GetAndroidToolStatusAndOutput(
81 '/data/local/tmp/adb_reboot') 81 '/data/local/tmp/adb_reboot')
82 LaunchHostHeartbeat() 82 LaunchHostHeartbeat()
83 83
84 84
85 def _ConfigureLocalProperties(device, is_perf): 85 def _ConfigureLocalProperties(device, is_perf):
86 """Set standard readonly testing device properties prior to reboot.""" 86 """Set standard readonly testing device properties prior to reboot."""
87 local_props = [ 87 local_props = [
88 'ro.monkey=1', 88 'ro.monkey=1',
89 'ro.test_harness=1', 89 'ro.test_harness=1',
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 except errors.DeviceUnresponsiveError: 153 except errors.DeviceUnresponsiveError:
154 pass 154 pass
155 for device_serial in devices_to_reboot: 155 for device_serial in devices_to_reboot:
156 device.WaitUntilFullyBooted(timeout=90) 156 device.WaitUntilFullyBooted(timeout=90)
157 157
158 158
159 def ProvisionDevice(device_serial, is_perf, disable_location): 159 def ProvisionDevice(device_serial, is_perf, disable_location):
160 device = device_utils.DeviceUtils(device_serial) 160 device = device_utils.DeviceUtils(device_serial)
161 device.old_interface.EnableAdbRoot() 161 device.old_interface.EnableAdbRoot()
162 _ConfigureLocalProperties(device, is_perf) 162 _ConfigureLocalProperties(device, is_perf)
163 device_settings_map = device_settings.DETERMINISTIC_DEVICE_SETTINGS 163 device_settings.ConfigureContentSettings(
164 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS)
164 if disable_location: 165 if disable_location:
165 device_settings_map.update(device_settings.DISABLE_LOCATION_SETTING) 166 device_settings.ConfigureContentSettings(
167 device, device_settings.DISABLE_LOCATION_SETTINGS)
166 else: 168 else:
167 device_settings_map.update(device_settings.ENABLE_LOCATION_SETTING) 169 device_settings.ConfigureContentSettings(
168 device_settings.ConfigureContentSettingsDict(device, device_settings_map) 170 device, device_settings.ENABLE_LOCATION_SETTINGS)
169 device_settings.SetLockScreenSettings(device) 171 device_settings.SetLockScreenSettings(device)
170 if is_perf: 172 if is_perf:
171 # TODO(tonyg): We eventually want network on. However, currently radios 173 # TODO(tonyg): We eventually want network on. However, currently radios
172 # can cause perfbots to drain faster than they charge. 174 # can cause perfbots to drain faster than they charge.
173 device_settings.ConfigureContentSettingsDict( 175 device_settings.ConfigureContentSettings(
174 device, device_settings.NETWORK_DISABLED_SETTINGS) 176 device, device_settings.NETWORK_DISABLED_SETTINGS)
175 # Some perf bots run benchmarks with USB charging disabled which leads 177 # Some perf bots run benchmarks with USB charging disabled which leads
176 # to gradual draining of the battery. We must wait for a full charge 178 # to gradual draining of the battery. We must wait for a full charge
177 # before starting a run in order to keep the devices online. 179 # before starting a run in order to keep the devices online.
178 try: 180 try:
179 battery_info = device.old_interface.GetBatteryInfo() 181 battery_info = device.old_interface.GetBatteryInfo()
180 except Exception as e: 182 except Exception as e:
181 battery_info = {} 183 battery_info = {}
182 logging.error('Unable to obtain battery info for %s, %s', 184 logging.error('Unable to obtain battery info for %s, %s',
183 device_serial, e) 185 device_serial, e)
(...skipping 23 matching lines...) Expand all
207 209
208 # Wipe devices (unless --skip-wipe was specified) 210 # Wipe devices (unless --skip-wipe was specified)
209 if not options.skip_wipe: 211 if not options.skip_wipe:
210 WipeDevicesIfPossible(devices) 212 WipeDevicesIfPossible(devices)
211 213
212 bad_devices = [] 214 bad_devices = []
213 # Provision devices 215 # Provision devices
214 for device_serial in devices: 216 for device_serial in devices:
215 try: 217 try:
216 ProvisionDevice(device_serial, is_perf, options.disable_location) 218 ProvisionDevice(device_serial, is_perf, options.disable_location)
217 except errors.WaitForResponseTimedOutError: 219 except (errors.WaitForResponseTimedOutError,
220 device_errors.CommandTimeoutError):
218 logging.info('Timed out waiting for device %s. Adding to blacklist.', 221 logging.info('Timed out waiting for device %s. Adding to blacklist.',
219 device_serial) 222 device_serial)
220 bad_devices.append(device_serial) 223 bad_devices.append(device_serial)
221 # Device black list is reset by bb_device_status_check.py per build. 224 # Device black list is reset by bb_device_status_check.py per build.
222 device_blacklist.ExtendBlacklist([device_serial]) 225 device_blacklist.ExtendBlacklist([device_serial])
226 except device_errors.CommandFailedError:
227 logging.info('Failed to provision device %s. Adding to blacklist.',
228 device_serial)
229 bad_devices.append(device_serial)
230 device_blacklist.ExtendBlacklist([device_serial])
223 devices = [device for device in devices if device not in bad_devices] 231 devices = [device for device in devices if device not in bad_devices]
224 232
225 # If there are no good devices 233 # If there are no good devices
226 if not devices: 234 if not devices:
227 raise device_errors.NoDevicesError 235 raise device_errors.NoDevicesError
228 236
229 try: 237 try:
230 device_utils.DeviceUtils.parallel(devices).Reboot(True) 238 device_utils.DeviceUtils.parallel(devices).Reboot(True)
231 except errors.DeviceUnresponsiveError: 239 except errors.DeviceUnresponsiveError:
232 pass 240 pass
233 241
234 bad_devices = [] 242 bad_devices = []
235 for device_serial in devices: 243 for device_serial in devices:
236 device = device_utils.DeviceUtils(device_serial) 244 device = device_utils.DeviceUtils(device_serial)
237 try: 245 try:
238 device.WaitUntilFullyBooted(timeout=90) 246 device.WaitUntilFullyBooted(timeout=90)
239 (_, prop) = device.old_interface.GetShellCommandStatusAndOutput('getprop') 247 (_, prop) = device.old_interface.GetShellCommandStatusAndOutput('getprop')
240 for p in prop: 248 for p in prop:
241 print p 249 logging.info(p)
242 except errors.WaitForResponseTimedOutError: 250 except (errors.WaitForResponseTimedOutError,
251 device_errors.CommandTimeoutError):
243 logging.info('Timed out waiting for device %s. Adding to blacklist.', 252 logging.info('Timed out waiting for device %s. Adding to blacklist.',
244 device_serial) 253 device_serial)
245 bad_devices.append(device_serial) 254 bad_devices.append(device_serial)
246 # Device black list is reset by bb_device_status_check.py per build. 255 # Device black list is reset by bb_device_status_check.py per build.
247 device_blacklist.ExtendBlacklist([device_serial]) 256 device_blacklist.ExtendBlacklist([device_serial])
257 except device_errors.CommandFailedError:
258 logging.info('Failed to provision device %s. Adding to blacklist.',
259 device_serial)
260 bad_devices.append(device_serial)
261 device_blacklist.ExtendBlacklist([device_serial])
248 devices = [device for device in devices if device not in bad_devices] 262 devices = [device for device in devices if device not in bad_devices]
249 263
250 # If there are no good devices 264 # If there are no good devices
251 if not devices: 265 if not devices:
252 raise device_errors.NoDevicesError 266 raise device_errors.NoDevicesError
253 267
254 if options.auto_reconnect: 268 if options.auto_reconnect:
255 PushAndLaunchAdbReboot(devices, options.target) 269 PushAndLaunchAdbReboot(devices, options.target)
256 270
257 271
(...skipping 19 matching lines...) Expand all
277 291
278 if args: 292 if args:
279 print >> sys.stderr, 'Unused args %s' % args 293 print >> sys.stderr, 'Unused args %s' % args
280 return 1 294 return 1
281 295
282 ProvisionDevices(options) 296 ProvisionDevices(options)
283 297
284 298
285 if __name__ == '__main__': 299 if __name__ == '__main__':
286 sys.exit(main(sys.argv)) 300 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device_settings.py » ('j') | build/android/pylib/device_settings.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698