Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: build/android/pylib/utils/emulator.py

Issue 1116493003: Revert of [Android] Remove more uses of android_commands from build/android/pylib. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/perf/setup.py ('k') | build/android/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import logging 11 import logging
12 import os 12 import os
13 import signal 13 import signal
14 import subprocess 14 import subprocess
15 import time 15 import time
16 16
17 # TODO(craigdh): Move these pylib dependencies to pylib/utils/. 17 # TODO(craigdh): Move these pylib dependencies to pylib/utils/.
18 from pylib import android_commands
18 from pylib import cmd_helper 19 from pylib import cmd_helper
19 from pylib import constants 20 from pylib import constants
20 from pylib import pexpect 21 from pylib import pexpect
21 from pylib.device import device_errors 22 from pylib.device import device_errors
22 from pylib.device import device_utils 23 from pylib.device import device_utils
23 from pylib.utils import time_profile 24 from pylib.utils import time_profile
24 25
25 import errors 26 import errors
26 import run_command 27 import run_command
27 28
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 """Emulator failed to launch.""" 83 """Emulator failed to launch."""
83 pass 84 pass
84 85
85 def _KillAllEmulators(): 86 def _KillAllEmulators():
86 """Kill all running emulators that look like ones we started. 87 """Kill all running emulators that look like ones we started.
87 88
88 There are odd 'sticky' cases where there can be no emulator process 89 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 90 running but a device slot is taken. A little bot trouble and and
90 we're out of room forever. 91 we're out of room forever.
91 """ 92 """
92 emulators = [d for d in device_utils.HealthyDevices() if d.adb.is_emulator] 93 emulators = android_commands.GetAttachedDevices(hardware=False)
93 if not emulators: 94 if not emulators:
94 return 95 return
95 for e in emulators: 96 for emu_name in emulators:
96 e.adb.Emu(['kill']) 97 cmd_helper.RunCmd(['adb', '-s', emu_name, '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 android_commands.GetAttachedDevices(hardware=False):
100 return 101 return
101 time.sleep(1) 102 time.sleep(1)
102 103
103 104
104 def DeleteAllTempAVDs(): 105 def DeleteAllTempAVDs():
105 """Delete all temporary AVDs which are created for tests. 106 """Delete all temporary AVDs which are created for tests.
106 107
107 If the test exits abnormally and some temporary AVDs created when testing may 108 If the test exits abnormally and some temporary AVDs created when testing may
108 be left in the system. Clean these AVDs. 109 be left in the system. Clean these AVDs.
109 """ 110 """
(...skipping 23 matching lines...) Expand all
133 Cycling through a port start position helps make us resilient.""" 134 Cycling through a port start position helps make us resilient."""
134 ports = range(cls._port_min, cls._port_max, 2) 135 ports = range(cls._port_min, cls._port_max, 2)
135 n = cls._port_current_index 136 n = cls._port_current_index
136 cls._port_current_index = (n + 1) % len(ports) 137 cls._port_current_index = (n + 1) % len(ports)
137 return ports[n:] + ports[:n] 138 return ports[n:] + ports[:n]
138 139
139 140
140 def _GetAvailablePort(): 141 def _GetAvailablePort():
141 """Returns an available TCP port for the console.""" 142 """Returns an available TCP port for the console."""
142 used_ports = [] 143 used_ports = []
143 emulators = [d for d in device_utils.HealthyDevices() if d.adb.is_emulator] 144 emulators = android_commands.GetAttachedDevices(hardware=False)
144 for emulator in emulators: 145 for emulator in emulators:
145 used_ports.append(emulator.adb.GetDeviceSerial().split('-')[1]) 146 used_ports.append(emulator.split('-')[1])
146 for port in PortPool.port_range(): 147 for port in PortPool.port_range():
147 if str(port) not in used_ports: 148 if str(port) not in used_ports:
148 return port 149 return port
149 150
150 151
151 def LaunchTempEmulators(emulator_count, abi, api_level, wait_for_boot=True): 152 def LaunchTempEmulators(emulator_count, abi, api_level, wait_for_boot=True):
152 """Create and launch temporary emulators and wait for them to boot. 153 """Create and launch temporary emulators and wait for them to boot.
153 154
154 Args: 155 Args:
155 emulator_count: number of emulators to launch. 156 emulator_count: number of emulators to launch.
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 logging.critical('emulator _ShutdownOnSignal') 433 logging.critical('emulator _ShutdownOnSignal')
433 for sig in self._SIGNALS: 434 for sig in self._SIGNALS:
434 signal.signal(sig, signal.SIG_DFL) 435 signal.signal(sig, signal.SIG_DFL)
435 self.Shutdown() 436 self.Shutdown()
436 raise KeyboardInterrupt # print a stack 437 raise KeyboardInterrupt # print a stack
437 438
438 def _InstallKillHandler(self): 439 def _InstallKillHandler(self):
439 """Install a handler to kill the emulator when we exit unexpectedly.""" 440 """Install a handler to kill the emulator when we exit unexpectedly."""
440 for sig in self._SIGNALS: 441 for sig in self._SIGNALS:
441 signal.signal(sig, self._ShutdownOnSignal) 442 signal.signal(sig, self._ShutdownOnSignal)
OLDNEW
« no previous file with comments | « build/android/pylib/perf/setup.py ('k') | build/android/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698