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 | 22 |
23 | 23 def KillHostHeartbeat(): |
24 def LaunchHostHeartbeat(): | |
25 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) | 24 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) |
26 stdout, _ = ps.communicate() | 25 stdout, _ = ps.communicate() |
27 matches = re.findall('\\n.*host_heartbeat.*', stdout) | 26 matches = re.findall('\\n.*host_heartbeat.*', stdout) |
28 for match in matches: | 27 for match in matches: |
29 print 'An instance of host heart beart already running... will kill' | 28 print 'An instance of host heart beart running... will kill' |
30 pid = re.findall('(\d+)', match)[1] | 29 pid = re.findall('(\d+)', match)[1] |
31 subprocess.call(['kill', str(pid)]) | 30 subprocess.call(['kill', str(pid)]) |
| 31 |
| 32 |
| 33 def LaunchHostHeartbeat(): |
| 34 # Kill if existing host_heartbeat |
| 35 KillHostHeartbeat() |
32 # Launch a new host_heartbeat | 36 # Launch a new host_heartbeat |
33 print 'Spawning host heartbeat...' | 37 print 'Spawning host heartbeat...' |
34 subprocess.Popen([os.path.join(constants.DIR_SOURCE_ROOT, | 38 subprocess.Popen([os.path.join(constants.DIR_SOURCE_ROOT, |
35 'build/android/host_heartbeat.py')]) | 39 'build/android/host_heartbeat.py')]) |
36 | 40 |
37 | 41 |
38 def PushAndLaunchAdbReboot(devices, target): | 42 def PushAndLaunchAdbReboot(devices, target): |
39 """Pushes and launches the adb_reboot binary on the device. | 43 """Pushes and launches the adb_reboot binary on the device. |
40 | 44 |
41 Arguments: | 45 Arguments: |
42 devices: The list of serial numbers of the device to which the | 46 devices: The list of serial numbers of the device to which the |
43 adb_reboot binary should be pushed. | 47 adb_reboot binary should be pushed. |
44 target : The build target (example, Debug or Release) which helps in | 48 target : The build target (example, Debug or Release) which helps in |
45 locating the adb_reboot binary. | 49 locating the adb_reboot binary. |
46 """ | 50 """ |
47 for device in devices: | 51 for device in devices: |
48 print 'Will push and launch adb_reboot on %s' % device | 52 print 'Will push and launch adb_reboot on %s' % device |
49 android_cmd = android_commands.AndroidCommands(device) | 53 android_cmd = android_commands.AndroidCommands(device) |
50 # Kill if adb_reboot is already running. | 54 # Kill if adb_reboot is already running. |
51 android_cmd.KillAllBlocking('adb_reboot', 2) | 55 android_cmd.KillAllBlocking('adb_reboot', 2) |
52 # Push adb_reboot | 56 # Push adb_reboot |
53 print ' Pushing adb_reboot ...' | 57 print ' Pushing adb_reboot ...' |
54 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, | 58 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, |
55 'out/%s/adb_reboot' % target) | 59 'out/%s/adb_reboot' % target) |
56 android_cmd.PushIfNeeded(adb_reboot, '/data/local/') | 60 android_cmd.PushIfNeeded(adb_reboot, '/data/local/tmp/') |
57 # Launch adb_reboot | 61 # Launch adb_reboot |
58 print ' Launching adb_reboot ...' | 62 print ' Launching adb_reboot ...' |
59 p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE) | 63 p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE) |
60 p.communicate('/data/local/adb_reboot; exit\n') | 64 p.communicate('/data/local/tmp/adb_reboot; exit\n') |
61 LaunchHostHeartbeat() | 65 LaunchHostHeartbeat() |
62 | 66 |
63 | 67 |
64 def ProvisionDevices(options): | 68 def ProvisionDevices(options): |
65 if options.device is not None: | 69 if options.device is not None: |
66 devices = [options.device] | 70 devices = [options.device] |
67 else: | 71 else: |
68 devices = android_commands.GetAttachedDevices() | 72 devices = android_commands.GetAttachedDevices() |
69 for device in devices: | 73 for device in devices: |
70 android_cmd = android_commands.AndroidCommands(device) | 74 android_cmd = android_commands.AndroidCommands(device) |
(...skipping 14 matching lines...) Expand all Loading... |
85 | 89 |
86 if args: | 90 if args: |
87 print >> sys.stderr, 'Unused args %s' % args | 91 print >> sys.stderr, 'Unused args %s' % args |
88 return 1 | 92 return 1 |
89 | 93 |
90 ProvisionDevices(options) | 94 ProvisionDevices(options) |
91 | 95 |
92 | 96 |
93 if __name__ == '__main__': | 97 if __name__ == '__main__': |
94 sys.exit(main(sys.argv)) | 98 sys.exit(main(sys.argv)) |
OLD | NEW |