Chromium Code Reviews| 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>] |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 import time | 18 import time |
| 19 | 19 |
| 20 from pylib import android_commands | 20 from pylib import android_commands |
| 21 from pylib import constants | 21 from pylib import constants |
| 22 from pylib import device_settings | |
| 23 | |
| 22 | 24 |
| 23 def KillHostHeartbeat(): | 25 def KillHostHeartbeat(): |
| 24 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) | 26 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) |
| 25 stdout, _ = ps.communicate() | 27 stdout, _ = ps.communicate() |
| 26 matches = re.findall('\\n.*host_heartbeat.*', stdout) | 28 matches = re.findall('\\n.*host_heartbeat.*', stdout) |
| 27 for match in matches: | 29 for match in matches: |
| 28 print 'An instance of host heart beart running... will kill' | 30 print 'An instance of host heart beart running... will kill' |
| 29 pid = re.findall('(\d+)', match)[1] | 31 pid = re.findall('(\d+)', match)[1] |
| 30 subprocess.call(['kill', str(pid)]) | 32 subprocess.call(['kill', str(pid)]) |
| 31 | 33 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 58 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, | 60 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, |
| 59 'out/%s/adb_reboot' % target) | 61 'out/%s/adb_reboot' % target) |
| 60 android_cmd.PushIfNeeded(adb_reboot, '/data/local/tmp/') | 62 android_cmd.PushIfNeeded(adb_reboot, '/data/local/tmp/') |
| 61 # Launch adb_reboot | 63 # Launch adb_reboot |
| 62 print ' Launching adb_reboot ...' | 64 print ' Launching adb_reboot ...' |
| 63 p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE) | 65 p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE) |
| 64 p.communicate('/data/local/tmp/adb_reboot; exit\n') | 66 p.communicate('/data/local/tmp/adb_reboot; exit\n') |
| 65 LaunchHostHeartbeat() | 67 LaunchHostHeartbeat() |
| 66 | 68 |
| 67 | 69 |
| 70 def _ConfigureLocalProperties(adb): | |
| 71 """Set standard readonly testing device properties prior to reboot.""" | |
| 72 local_props = ['ro.monkey=1', | |
|
bulach
2014/02/26 15:23:59
ultra nit: perhaps:
local_props = [
...,
...,
tonyg
2014/02/26 16:52:58
Done.
| |
| 73 'ro.test_harness=1', | |
| 74 'ro.audio.silent=1', | |
| 75 'ro.setupwizard.mode=DISABLED'] | |
| 76 adb.SetProtectedFileContents(android_commands.LOCAL_PROPERTIES_PATH, | |
| 77 '\n'.join(local_props)) | |
| 78 # Android will not respect the local props file if it is world writable. | |
| 79 adb.RunShellCommandWithSU('chmod 644 %s' % | |
| 80 android_commands.LOCAL_PROPERTIES_PATH) | |
| 81 | |
| 82 | |
| 68 def ProvisionDevices(options): | 83 def ProvisionDevices(options): |
| 69 if options.device is not None: | 84 if options.device is not None: |
| 70 devices = [options.device] | 85 devices = [options.device] |
| 71 else: | 86 else: |
| 72 devices = android_commands.GetAttachedDevices() | 87 devices = android_commands.GetAttachedDevices() |
| 73 for device in devices: | 88 for device in devices: |
| 74 android_cmd = android_commands.AndroidCommands(device) | 89 android_cmd = android_commands.AndroidCommands(device) |
| 90 _ConfigureLocalProperties(android_cmd) | |
| 91 device_settings.ConfigureContentSettingsDict( | |
| 92 android_cmd, device_settings.DETERMINISTIC_DEVICE_SETTINGS) | |
| 93 # TODO(tonyg): We eventually want network on. However, currently radios | |
| 94 # can cause perfbots to drain faster than they charge. | |
| 95 if 'Perf' in os.environ.get('BUILDBOT_BUILDERNAME', ''): | |
|
bulach
2014/02/26 15:23:59
nit: s/Perf/ and use a .lower()
so this would work
tonyg
2014/02/26 16:52:58
Done.
| |
| 96 device_settings.ConfigureContentSettingsDict( | |
| 97 android_cmd, device_settings.NETWORK_DISABLED_SETTINGS) | |
| 75 android_cmd.RunShellCommandWithSU('date -u %f' % time.time()) | 98 android_cmd.RunShellCommandWithSU('date -u %f' % time.time()) |
| 76 if options.auto_reconnect: | 99 if options.auto_reconnect: |
| 77 PushAndLaunchAdbReboot(devices, options.target) | 100 PushAndLaunchAdbReboot(devices, options.target) |
| 78 | 101 |
| 79 | 102 |
| 80 def main(argv): | 103 def main(argv): |
| 81 parser = optparse.OptionParser() | 104 parser = optparse.OptionParser() |
| 82 parser.add_option('-d', '--device', | 105 parser.add_option('-d', '--device', |
| 83 help='The serial number of the device to be provisioned') | 106 help='The serial number of the device to be provisioned') |
| 84 parser.add_option('-t', '--target', default='Debug', help='The build target') | 107 parser.add_option('-t', '--target', default='Debug', help='The build target') |
| 85 parser.add_option( | 108 parser.add_option( |
| 86 '-r', '--auto-reconnect', action='store_true', | 109 '-r', '--auto-reconnect', action='store_true', |
| 87 help='Push binary which will reboot the device on adb disconnections.') | 110 help='Push binary which will reboot the device on adb disconnections.') |
| 88 options, args = parser.parse_args(argv[1:]) | 111 options, args = parser.parse_args(argv[1:]) |
| 89 constants.SetBuildType(options.target) | 112 constants.SetBuildType(options.target) |
| 90 | 113 |
| 91 if args: | 114 if args: |
| 92 print >> sys.stderr, 'Unused args %s' % args | 115 print >> sys.stderr, 'Unused args %s' % args |
| 93 return 1 | 116 return 1 |
| 94 | 117 |
| 95 ProvisionDevices(options) | 118 ProvisionDevices(options) |
| 96 | 119 |
| 97 | 120 |
| 98 if __name__ == '__main__': | 121 if __name__ == '__main__': |
| 99 sys.exit(main(sys.argv)) | 122 sys.exit(main(sys.argv)) |
| OLD | NEW |