OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 from pylib import device_settings | 23 from pylib import device_settings |
24 from pylib.device import device_blacklist | 24 from pylib.device import device_blacklist |
25 from pylib.device import device_errors | 25 from pylib.device import device_errors |
26 from pylib.device import device_utils | 26 from pylib.device import device_utils |
27 from pylib.utils import run_tests_helper | 27 from pylib.utils import run_tests_helper |
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 |
| 34 class _DEFAULT_TIMEOUTS(object): |
| 35 # L can take a while to reboot after a wipe. |
| 36 LOLLIPOP = 600 |
| 37 PRE_LOLLIPOP = 180 |
| 38 |
| 39 HELP_TEXT = '{}s on L, {}s on pre-L'.format(LOLLIPOP, PRE_LOLLIPOP) |
| 40 |
| 41 |
33 def KillHostHeartbeat(): | 42 def KillHostHeartbeat(): |
34 ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE) | 43 ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE) |
35 stdout, _ = ps.communicate() | 44 stdout, _ = ps.communicate() |
36 matches = re.findall('\\n.*host_heartbeat.*', stdout) | 45 matches = re.findall('\\n.*host_heartbeat.*', stdout) |
37 for match in matches: | 46 for match in matches: |
38 logging.info('An instance of host heart beart running... will kill') | 47 logging.info('An instance of host heart beart running... will kill') |
39 pid = re.findall(r'(\S+)', match)[1] | 48 pid = re.findall(r'(\S+)', match)[1] |
40 subprocess.call(['kill', str(pid)]) | 49 subprocess.call(['kill', str(pid)]) |
41 | 50 |
42 | 51 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 def WipeDeviceIfPossible(device, timeout): | 143 def WipeDeviceIfPossible(device, timeout): |
135 try: | 144 try: |
136 device.EnableRoot() | 145 device.EnableRoot() |
137 WipeDeviceData(device) | 146 WipeDeviceData(device) |
138 device.Reboot(True, timeout=timeout, retries=0) | 147 device.Reboot(True, timeout=timeout, retries=0) |
139 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): | 148 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): |
140 pass | 149 pass |
141 | 150 |
142 | 151 |
143 def ProvisionDevice(device, options): | 152 def ProvisionDevice(device, options): |
| 153 if options.reboot_timeout: |
| 154 reboot_timeout = options.reboot_timeout |
| 155 elif (device.build_version_sdk >= |
| 156 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): |
| 157 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP |
| 158 else: |
| 159 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP |
| 160 |
144 try: | 161 try: |
145 if not options.skip_wipe: | 162 if not options.skip_wipe: |
146 WipeDeviceIfPossible(device, options.reboot_timeout) | 163 WipeDeviceIfPossible(device, reboot_timeout) |
147 try: | 164 try: |
148 device.EnableRoot() | 165 device.EnableRoot() |
149 except device_errors.CommandFailedError as e: | 166 except device_errors.CommandFailedError as e: |
150 logging.warning(str(e)) | 167 logging.warning(str(e)) |
151 _ConfigureLocalProperties(device, options.enable_java_debug) | 168 _ConfigureLocalProperties(device, options.enable_java_debug) |
152 device_settings.ConfigureContentSettings( | 169 device_settings.ConfigureContentSettings( |
153 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) | 170 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) |
154 if options.disable_location: | 171 if options.disable_location: |
155 device_settings.ConfigureContentSettings( | 172 device_settings.ConfigureContentSettings( |
156 device, device_settings.DISABLE_LOCATION_SETTINGS) | 173 device, device_settings.DISABLE_LOCATION_SETTINGS) |
(...skipping 17 matching lines...) Expand all Loading... |
174 if device.old_interface.CanControlUsbCharging(): | 191 if device.old_interface.CanControlUsbCharging(): |
175 device.old_interface.EnableUsbCharging() | 192 device.old_interface.EnableUsbCharging() |
176 else: | 193 else: |
177 logging.error('Device is not charging') | 194 logging.error('Device is not charging') |
178 break | 195 break |
179 logging.info('Waiting for device to charge. Current level=%s', | 196 logging.info('Waiting for device to charge. Current level=%s', |
180 battery_info.get('level', 0)) | 197 battery_info.get('level', 0)) |
181 time.sleep(60) | 198 time.sleep(60) |
182 battery_info = device.old_interface.GetBatteryInfo() | 199 battery_info = device.old_interface.GetBatteryInfo() |
183 if not options.skip_wipe: | 200 if not options.skip_wipe: |
184 device.Reboot(True, timeout=options.reboot_timeout, retries=0) | 201 device.Reboot(True, timeout=reboot_timeout, retries=0) |
185 device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', | 202 device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', |
186 time.gmtime()), | 203 time.gmtime()), |
187 as_root=True) | 204 as_root=True) |
188 props = device.RunShellCommand('getprop') | 205 props = device.RunShellCommand('getprop') |
189 for prop in props: | 206 for prop in props: |
190 logging.info(' %s' % prop) | 207 logging.info(' %s' % prop) |
191 if options.auto_reconnect: | 208 if options.auto_reconnect: |
192 PushAndLaunchAdbReboot(device, options.target) | 209 PushAndLaunchAdbReboot(device, options.target) |
193 except (errors.WaitForResponseTimedOutError, | 210 except (errors.WaitForResponseTimedOutError, |
194 device_errors.CommandTimeoutError): | 211 device_errors.CommandTimeoutError): |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 # to gradual draining of the battery. We must wait for a full charge | 263 # to gradual draining of the battery. We must wait for a full charge |
247 # before starting a run in order to keep the devices online. | 264 # before starting a run in order to keep the devices online. |
248 | 265 |
249 parser = argparse.ArgumentParser( | 266 parser = argparse.ArgumentParser( |
250 description='Provision Android devices with settings required for bots.') | 267 description='Provision Android devices with settings required for bots.') |
251 parser.add_argument('-d', '--device', metavar='SERIAL', | 268 parser.add_argument('-d', '--device', metavar='SERIAL', |
252 help='the serial number of the device to be provisioned' | 269 help='the serial number of the device to be provisioned' |
253 ' (the default is to provision all devices attached)') | 270 ' (the default is to provision all devices attached)') |
254 parser.add_argument('--skip-wipe', action='store_true', default=False, | 271 parser.add_argument('--skip-wipe', action='store_true', default=False, |
255 help="don't wipe device data during provisioning") | 272 help="don't wipe device data during provisioning") |
256 parser.add_argument('--reboot-timeout', default=600, type=int, | 273 parser.add_argument('--reboot-timeout', metavar='SECS', type=int, |
257 metavar='SECS', | |
258 help='when wiping the device, max number of seconds to' | 274 help='when wiping the device, max number of seconds to' |
259 ' wait after each reboot (default: %(default)s)') | 275 ' wait after each reboot ' |
| 276 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) |
260 parser.add_argument('--wait-for-battery', action='store_true', | 277 parser.add_argument('--wait-for-battery', action='store_true', |
261 default=is_perf, | 278 default=is_perf, |
262 help='wait for the battery on the devices to charge') | 279 help='wait for the battery on the devices to charge') |
263 parser.add_argument('--min-battery-level', default=95, type=int, | 280 parser.add_argument('--min-battery-level', default=95, type=int, |
264 metavar='NUM', | 281 metavar='NUM', |
265 help='when waiting for battery, minimum battery level' | 282 help='when waiting for battery, minimum battery level' |
266 ' required to continue (default: %(default)s)') | 283 ' required to continue (default: %(default)s)') |
267 parser.add_argument('--disable-location', action='store_true', | 284 parser.add_argument('--disable-location', action='store_true', |
268 help='disable Google location services on devices') | 285 help='disable Google location services on devices') |
269 parser.add_argument('--disable-network', action='store_true', | 286 parser.add_argument('--disable-network', action='store_true', |
270 default=is_perf, | 287 default=is_perf, |
271 help='disable network access on devices') | 288 help='disable network access on devices') |
272 parser.add_argument('--disable-java-debug', action='store_false', | 289 parser.add_argument('--disable-java-debug', action='store_false', |
273 dest='enable_java_debug', default=not is_perf, | 290 dest='enable_java_debug', default=not is_perf, |
274 help='disable Java property asserts and JNI checking') | 291 help='disable Java property asserts and JNI checking') |
275 parser.add_argument('-t', '--target', default='Debug', | 292 parser.add_argument('-t', '--target', default='Debug', |
276 help='the build target (default: %(default)s)') | 293 help='the build target (default: %(default)s)') |
277 parser.add_argument('-r', '--auto-reconnect', action='store_true', | 294 parser.add_argument('-r', '--auto-reconnect', action='store_true', |
278 help='push binary which will reboot the device on adb' | 295 help='push binary which will reboot the device on adb' |
279 ' disconnections') | 296 ' disconnections') |
280 args = parser.parse_args() | 297 args = parser.parse_args() |
281 constants.SetBuildType(args.target) | 298 constants.SetBuildType(args.target) |
282 | 299 |
283 return ProvisionDevices(args) | 300 return ProvisionDevices(args) |
284 | 301 |
285 | 302 |
286 if __name__ == '__main__': | 303 if __name__ == '__main__': |
287 sys.exit(main()) | 304 sys.exit(main()) |
OLD | NEW |