| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides an interface to start and stop Android emulator. | 5 """Provides an interface to start and stop Android emulator. |
| 6 | 6 |
| 7 Emulator: The class provides the methods to launch/shutdown the emulator with | 7 Emulator: The class provides the methods to launch/shutdown the emulator with |
| 8 the android virtual device named 'avd_armeabi' . | 8 the android virtual device named 'avd_armeabi' . |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 class EmulatorLaunchException(Exception): | 81 class EmulatorLaunchException(Exception): |
| 82 """Emulator failed to launch.""" | 82 """Emulator failed to launch.""" |
| 83 pass | 83 pass |
| 84 | 84 |
| 85 def _KillAllEmulators(): | 85 def _KillAllEmulators(): |
| 86 """Kill all running emulators that look like ones we started. | 86 """Kill all running emulators that look like ones we started. |
| 87 | 87 |
| 88 There are odd 'sticky' cases where there can be no emulator process | 88 There are odd 'sticky' cases where there can be no emulator process |
| 89 running but a device slot is taken. A little bot trouble and and | 89 running but a device slot is taken. A little bot trouble and we're out of |
| 90 we're out of room forever. | 90 room forever. |
| 91 """ | 91 """ |
| 92 emulators = [d for d in device_utils.HealthyDevices() if d.adb.is_emulator] | 92 emulators = [d for d in device_utils.DeviceUtils.HealthyDevices() |
| 93 if d.adb.is_emulator] |
| 93 if not emulators: | 94 if not emulators: |
| 94 return | 95 return |
| 95 for e in emulators: | 96 for e in emulators: |
| 96 e.adb.Emu(['kill']) | 97 e.adb.Emu(['kill']) |
| 97 logging.info('Emulator killing is async; give a few seconds for all to die.') | 98 logging.info('Emulator killing is async; give a few seconds for all to die.') |
| 98 for _ in range(5): | 99 for _ in range(5): |
| 99 if not any(d.adb.is_emulator for d in device_utils.HealthyDevices()): | 100 if not any(d.adb.is_emulator for d |
| 101 in device_utils.DeviceUtils.HealthyDevices()): |
| 100 return | 102 return |
| 101 time.sleep(1) | 103 time.sleep(1) |
| 102 | 104 |
| 103 | 105 |
| 104 def DeleteAllTempAVDs(): | 106 def DeleteAllTempAVDs(): |
| 105 """Delete all temporary AVDs which are created for tests. | 107 """Delete all temporary AVDs which are created for tests. |
| 106 | 108 |
| 107 If the test exits abnormally and some temporary AVDs created when testing may | 109 If the test exits abnormally and some temporary AVDs created when testing may |
| 108 be left in the system. Clean these AVDs. | 110 be left in the system. Clean these AVDs. |
| 109 """ | 111 """ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 133 Cycling through a port start position helps make us resilient.""" | 135 Cycling through a port start position helps make us resilient.""" |
| 134 ports = range(cls._port_min, cls._port_max, 2) | 136 ports = range(cls._port_min, cls._port_max, 2) |
| 135 n = cls._port_current_index | 137 n = cls._port_current_index |
| 136 cls._port_current_index = (n + 1) % len(ports) | 138 cls._port_current_index = (n + 1) % len(ports) |
| 137 return ports[n:] + ports[:n] | 139 return ports[n:] + ports[:n] |
| 138 | 140 |
| 139 | 141 |
| 140 def _GetAvailablePort(): | 142 def _GetAvailablePort(): |
| 141 """Returns an available TCP port for the console.""" | 143 """Returns an available TCP port for the console.""" |
| 142 used_ports = [] | 144 used_ports = [] |
| 143 emulators = [d for d in device_utils.HealthyDevices() if d.adb.is_emulator] | 145 emulators = [d for d in device_utils.DeviceUtils.HealthyDevices() |
| 146 if d.adb.is_emulator] |
| 144 for emulator in emulators: | 147 for emulator in emulators: |
| 145 used_ports.append(emulator.adb.GetDeviceSerial().split('-')[1]) | 148 used_ports.append(emulator.adb.GetDeviceSerial().split('-')[1]) |
| 146 for port in PortPool.port_range(): | 149 for port in PortPool.port_range(): |
| 147 if str(port) not in used_ports: | 150 if str(port) not in used_ports: |
| 148 return port | 151 return port |
| 149 | 152 |
| 150 | 153 |
| 151 def LaunchTempEmulators(emulator_count, abi, api_level, wait_for_boot=True): | 154 def LaunchTempEmulators(emulator_count, abi, api_level, wait_for_boot=True): |
| 152 """Create and launch temporary emulators and wait for them to boot. | 155 """Create and launch temporary emulators and wait for them to boot. |
| 153 | 156 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 logging.critical('emulator _ShutdownOnSignal') | 435 logging.critical('emulator _ShutdownOnSignal') |
| 433 for sig in self._SIGNALS: | 436 for sig in self._SIGNALS: |
| 434 signal.signal(sig, signal.SIG_DFL) | 437 signal.signal(sig, signal.SIG_DFL) |
| 435 self.Shutdown() | 438 self.Shutdown() |
| 436 raise KeyboardInterrupt # print a stack | 439 raise KeyboardInterrupt # print a stack |
| 437 | 440 |
| 438 def _InstallKillHandler(self): | 441 def _InstallKillHandler(self): |
| 439 """Install a handler to kill the emulator when we exit unexpectedly.""" | 442 """Install a handler to kill the emulator when we exit unexpectedly.""" |
| 440 for sig in self._SIGNALS: | 443 for sig in self._SIGNALS: |
| 441 signal.signal(sig, self._ShutdownOnSignal) | 444 signal.signal(sig, self._ShutdownOnSignal) |
| OLD | NEW |