| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if options.disable_location: | 171 if options.disable_location: |
| 172 device_settings.ConfigureContentSettings( | 172 device_settings.ConfigureContentSettings( |
| 173 device, device_settings.DISABLE_LOCATION_SETTINGS) | 173 device, device_settings.DISABLE_LOCATION_SETTINGS) |
| 174 else: | 174 else: |
| 175 device_settings.ConfigureContentSettings( | 175 device_settings.ConfigureContentSettings( |
| 176 device, device_settings.ENABLE_LOCATION_SETTINGS) | 176 device, device_settings.ENABLE_LOCATION_SETTINGS) |
| 177 device_settings.SetLockScreenSettings(device) | 177 device_settings.SetLockScreenSettings(device) |
| 178 if options.disable_network: | 178 if options.disable_network: |
| 179 device_settings.ConfigureContentSettings( | 179 device_settings.ConfigureContentSettings( |
| 180 device, device_settings.NETWORK_DISABLED_SETTINGS) | 180 device, device_settings.NETWORK_DISABLED_SETTINGS) |
| 181 if options.wait_for_battery: | 181 if options.min_battery_level is not None: |
| 182 try: | 182 try: |
| 183 battery_info = device.old_interface.GetBatteryInfo() | 183 battery_info = device.old_interface.GetBatteryInfo() |
| 184 except Exception as e: | 184 except Exception as e: |
| 185 battery_info = {} | 185 battery_info = {} |
| 186 logging.error('Unable to obtain battery info for %s, %s', | 186 logging.error('Unable to obtain battery info for %s, %s', |
| 187 str(device), e) | 187 str(device), e) |
| 188 | 188 |
| 189 while int(battery_info.get('level', 100)) < options.min_battery_level: | 189 while int(battery_info.get('level', 100)) < options.min_battery_level: |
| 190 if not device.old_interface.IsDeviceCharging(): | 190 if not device.old_interface.IsDeviceCharging(): |
| 191 if device.old_interface.CanControlUsbCharging(): | 191 if device.old_interface.CanControlUsbCharging(): |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 raise device_errors.NoDevicesError | 234 raise device_errors.NoDevicesError |
| 235 return 0 | 235 return 0 |
| 236 | 236 |
| 237 | 237 |
| 238 def main(): | 238 def main(): |
| 239 custom_handler = logging.StreamHandler(sys.stdout) | 239 custom_handler = logging.StreamHandler(sys.stdout) |
| 240 custom_handler.setFormatter(run_tests_helper.CustomFormatter()) | 240 custom_handler.setFormatter(run_tests_helper.CustomFormatter()) |
| 241 logging.getLogger().addHandler(custom_handler) | 241 logging.getLogger().addHandler(custom_handler) |
| 242 logging.getLogger().setLevel(logging.INFO) | 242 logging.getLogger().setLevel(logging.INFO) |
| 243 | 243 |
| 244 # TODO(perezju): This script used to rely on the builder name to determine | |
| 245 # the desired device configuration for perf bots. To safely phase this out, | |
| 246 # we now: | |
| 247 # - expose these configuration settings as command line options | |
| 248 # - set default values for these options based on the builder name, thus | |
| 249 # matching the previous behaviour of the script on all bots. | |
| 250 # - explicitly adding these options on the perf bots will also maintain the | |
| 251 # script behaviour, namely: | |
| 252 # --wait-for-battery --disable-network --disable-java-debug | |
| 253 # - after all perf-bot recipes are updated, we can remove the following | |
| 254 # builder-name-sniffing code and replace |is_perf| with |False|. | |
| 255 is_perf = 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower() | |
| 256 | |
| 257 # Recommended options on perf bots: | 244 # Recommended options on perf bots: |
| 258 # --disable-network | 245 # --disable-network |
| 259 # TODO(tonyg): We eventually want network on. However, currently radios | 246 # TODO(tonyg): We eventually want network on. However, currently radios |
| 260 # can cause perfbots to drain faster than they charge. | 247 # can cause perfbots to drain faster than they charge. |
| 261 # --wait-for-battery | 248 # --min-battery-level 95 |
| 262 # Some perf bots run benchmarks with USB charging disabled which leads | 249 # Some perf bots run benchmarks with USB charging disabled which leads |
| 263 # to gradual draining of the battery. We must wait for a full charge | 250 # to gradual draining of the battery. We must wait for a full charge |
| 264 # before starting a run in order to keep the devices online. | 251 # before starting a run in order to keep the devices online. |
| 265 | 252 |
| 266 parser = argparse.ArgumentParser( | 253 parser = argparse.ArgumentParser( |
| 267 description='Provision Android devices with settings required for bots.') | 254 description='Provision Android devices with settings required for bots.') |
| 268 parser.add_argument('-d', '--device', metavar='SERIAL', | 255 parser.add_argument('-d', '--device', metavar='SERIAL', |
| 269 help='the serial number of the device to be provisioned' | 256 help='the serial number of the device to be provisioned' |
| 270 ' (the default is to provision all devices attached)') | 257 ' (the default is to provision all devices attached)') |
| 271 parser.add_argument('--skip-wipe', action='store_true', default=False, | 258 parser.add_argument('--skip-wipe', action='store_true', default=False, |
| 272 help="don't wipe device data during provisioning") | 259 help="don't wipe device data during provisioning") |
| 273 parser.add_argument('--reboot-timeout', metavar='SECS', type=int, | 260 parser.add_argument('--reboot-timeout', metavar='SECS', type=int, |
| 274 help='when wiping the device, max number of seconds to' | 261 help='when wiping the device, max number of seconds to' |
| 275 ' wait after each reboot ' | 262 ' wait after each reboot ' |
| 276 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) | 263 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) |
| 277 parser.add_argument('--wait-for-battery', action='store_true', | 264 parser.add_argument('--min-battery-level', type=int, metavar='NUM', |
| 278 default=is_perf, | 265 help='wait for the device to reach this minimum battery' |
| 279 help='wait for the battery on the devices to charge') | 266 ' level before trying to continue') |
| 280 parser.add_argument('--min-battery-level', default=95, type=int, | |
| 281 metavar='NUM', | |
| 282 help='when waiting for battery, minimum battery level' | |
| 283 ' required to continue (default: %(default)s)') | |
| 284 parser.add_argument('--disable-location', action='store_true', | 267 parser.add_argument('--disable-location', action='store_true', |
| 285 help='disable Google location services on devices') | 268 help='disable Google location services on devices') |
| 286 parser.add_argument('--disable-network', action='store_true', | 269 parser.add_argument('--disable-network', action='store_true', |
| 287 default=is_perf, | |
| 288 help='disable network access on devices') | 270 help='disable network access on devices') |
| 289 parser.add_argument('--disable-java-debug', action='store_false', | 271 parser.add_argument('--disable-java-debug', action='store_false', |
| 290 dest='enable_java_debug', default=not is_perf, | 272 dest='enable_java_debug', default=True, |
| 291 help='disable Java property asserts and JNI checking') | 273 help='disable Java property asserts and JNI checking') |
| 292 parser.add_argument('-t', '--target', default='Debug', | 274 parser.add_argument('-t', '--target', default='Debug', |
| 293 help='the build target (default: %(default)s)') | 275 help='the build target (default: %(default)s)') |
| 294 parser.add_argument('-r', '--auto-reconnect', action='store_true', | 276 parser.add_argument('-r', '--auto-reconnect', action='store_true', |
| 295 help='push binary which will reboot the device on adb' | 277 help='push binary which will reboot the device on adb' |
| 296 ' disconnections') | 278 ' disconnections') |
| 297 args = parser.parse_args() | 279 args = parser.parse_args() |
| 298 constants.SetBuildType(args.target) | 280 constants.SetBuildType(args.target) |
| 299 | 281 |
| 300 return ProvisionDevices(args) | 282 return ProvisionDevices(args) |
| 301 | 283 |
| 302 | 284 |
| 303 if __name__ == '__main__': | 285 if __name__ == '__main__': |
| 304 sys.exit(main()) | 286 sys.exit(main()) |
| OLD | NEW |