OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 """Provides an interface to start and stop Android emulator. | 7 """Provides an interface to start and stop Android emulator. |
8 | 8 |
9 Assumes system environment ANDROID_NDK_ROOT has been set. | 9 Assumes system environment ANDROID_NDK_ROOT has been set. |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 """Emulator failed to launch.""" | 40 """Emulator failed to launch.""" |
41 pass | 41 pass |
42 | 42 |
43 def _KillAllEmulators(): | 43 def _KillAllEmulators(): |
44 """Kill all running emulators that look like ones we started. | 44 """Kill all running emulators that look like ones we started. |
45 | 45 |
46 There are odd 'sticky' cases where there can be no emulator process | 46 There are odd 'sticky' cases where there can be no emulator process |
47 running but a device slot is taken. A little bot trouble and and | 47 running but a device slot is taken. A little bot trouble and and |
48 we're out of room forever. | 48 we're out of room forever. |
49 """ | 49 """ |
50 emulators = android_commands.GetEmulators() | 50 emulators = android_commands.GetAttachedDevices(hardware=False) |
51 if not emulators: | 51 if not emulators: |
52 return | 52 return |
53 for emu_name in emulators: | 53 for emu_name in emulators: |
54 cmd_helper.RunCmd(['adb', '-s', emu_name, 'emu', 'kill']) | 54 cmd_helper.RunCmd(['adb', '-s', emu_name, 'emu', 'kill']) |
55 logging.info('Emulator killing is async; give a few seconds for all to die.') | 55 logging.info('Emulator killing is async; give a few seconds for all to die.') |
56 for i in range(5): | 56 for i in range(5): |
57 if not android_commands.GetEmulators(): | 57 if not android_commands.GetAttachedDevices(hardware=False): |
58 return | 58 return |
59 time.sleep(1) | 59 time.sleep(1) |
60 | 60 |
61 | 61 |
62 def DeleteAllTempAVDs(): | 62 def DeleteAllTempAVDs(): |
63 """Delete all temporary AVDs which are created for tests. | 63 """Delete all temporary AVDs which are created for tests. |
64 | 64 |
65 If the test exits abnormally and some temporary AVDs created when testing may | 65 If the test exits abnormally and some temporary AVDs created when testing may |
66 be left in the system. Clean these AVDs. | 66 be left in the system. Clean these AVDs. |
67 """ | 67 """ |
(...skipping 23 matching lines...) Expand all Loading... |
91 Cycling through a port start position helps make us resilient.""" | 91 Cycling through a port start position helps make us resilient.""" |
92 ports = range(cls._port_min, cls._port_max, 2) | 92 ports = range(cls._port_min, cls._port_max, 2) |
93 n = cls._port_current_index | 93 n = cls._port_current_index |
94 cls._port_current_index = (n + 1) % len(ports) | 94 cls._port_current_index = (n + 1) % len(ports) |
95 return ports[n:] + ports[:n] | 95 return ports[n:] + ports[:n] |
96 | 96 |
97 | 97 |
98 def _GetAvailablePort(): | 98 def _GetAvailablePort(): |
99 """Returns an available TCP port for the console.""" | 99 """Returns an available TCP port for the console.""" |
100 used_ports = [] | 100 used_ports = [] |
101 emulators = android_commands.GetEmulators() | 101 emulators = android_commands.GetAttachedDevices(hardware=False) |
102 for emulator in emulators: | 102 for emulator in emulators: |
103 used_ports.append(emulator.split('-')[1]) | 103 used_ports.append(emulator.split('-')[1]) |
104 for port in PortPool.port_range(): | 104 for port in PortPool.port_range(): |
105 if str(port) not in used_ports: | 105 if str(port) not in used_ports: |
106 return port | 106 return port |
107 | 107 |
108 | 108 |
109 def LaunchEmulators(emulator_count, abi, wait_for_boot=True): | 109 def LaunchEmulators(emulator_count, abi, wait_for_boot=True): |
110 """Launch multiple emulators and wait for them to boot. | 110 """Launch multiple emulators and wait for them to boot. |
111 | 111 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 logging.critical('emulator _ShutdownOnSignal') | 362 logging.critical('emulator _ShutdownOnSignal') |
363 for sig in self._SIGNALS: | 363 for sig in self._SIGNALS: |
364 signal.signal(sig, signal.SIG_DFL) | 364 signal.signal(sig, signal.SIG_DFL) |
365 self.Shutdown() | 365 self.Shutdown() |
366 raise KeyboardInterrupt # print a stack | 366 raise KeyboardInterrupt # print a stack |
367 | 367 |
368 def _InstallKillHandler(self): | 368 def _InstallKillHandler(self): |
369 """Install a handler to kill the emulator when we exit unexpectedly.""" | 369 """Install a handler to kill the emulator when we exit unexpectedly.""" |
370 for sig in self._SIGNALS: | 370 for sig in self._SIGNALS: |
371 signal.signal(sig, self._ShutdownOnSignal) | 371 signal.signal(sig, self._ShutdownOnSignal) |
OLD | NEW |