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

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

Issue 19774008: Do not reboot emulator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Collapse logic for getting devices and emulators. Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
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
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, emulator=True,
51 offline=False)
51 if not emulators: 52 if not emulators:
52 return 53 return
53 for emu_name in emulators: 54 for emu_name in emulators:
54 cmd_helper.RunCmd(['adb', '-s', emu_name, 'emu', 'kill']) 55 cmd_helper.RunCmd(['adb', '-s', emu_name, 'emu', 'kill'])
55 logging.info('Emulator killing is async; give a few seconds for all to die.') 56 logging.info('Emulator killing is async; give a few seconds for all to die.')
56 for i in range(5): 57 for i in range(5):
57 if not android_commands.GetEmulators(): 58 if not android_commands.GetAttachedDevices(hardware=False, emulator=True,
59 offline=False):
58 return 60 return
59 time.sleep(1) 61 time.sleep(1)
60 62
61 63
62 def DeleteAllTempAVDs(): 64 def DeleteAllTempAVDs():
63 """Delete all temporary AVDs which are created for tests. 65 """Delete all temporary AVDs which are created for tests.
64 66
65 If the test exits abnormally and some temporary AVDs created when testing may 67 If the test exits abnormally and some temporary AVDs created when testing may
66 be left in the system. Clean these AVDs. 68 be left in the system. Clean these AVDs.
67 """ 69 """
(...skipping 23 matching lines...) Expand all
91 Cycling through a port start position helps make us resilient.""" 93 Cycling through a port start position helps make us resilient."""
92 ports = range(cls._port_min, cls._port_max, 2) 94 ports = range(cls._port_min, cls._port_max, 2)
93 n = cls._port_current_index 95 n = cls._port_current_index
94 cls._port_current_index = (n + 1) % len(ports) 96 cls._port_current_index = (n + 1) % len(ports)
95 return ports[n:] + ports[:n] 97 return ports[n:] + ports[:n]
96 98
97 99
98 def _GetAvailablePort(): 100 def _GetAvailablePort():
99 """Returns an available TCP port for the console.""" 101 """Returns an available TCP port for the console."""
100 used_ports = [] 102 used_ports = []
101 emulators = android_commands.GetEmulators() 103 emulators = android_commands.GetAttachedDevices(hardware=False, emulator=True,
104 offline=False)
102 for emulator in emulators: 105 for emulator in emulators:
103 used_ports.append(emulator.split('-')[1]) 106 used_ports.append(emulator.split('-')[1])
104 for port in PortPool.port_range(): 107 for port in PortPool.port_range():
105 if str(port) not in used_ports: 108 if str(port) not in used_ports:
106 return port 109 return port
107 110
108 111
109 def LaunchEmulators(emulator_count, abi, wait_for_boot=True): 112 def LaunchEmulators(emulator_count, abi, wait_for_boot=True):
110 """Launch multiple emulators and wait for them to boot. 113 """Launch multiple emulators and wait for them to boot.
111 114
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 logging.critical('emulator _ShutdownOnSignal') 365 logging.critical('emulator _ShutdownOnSignal')
363 for sig in self._SIGNALS: 366 for sig in self._SIGNALS:
364 signal.signal(sig, signal.SIG_DFL) 367 signal.signal(sig, signal.SIG_DFL)
365 self.Shutdown() 368 self.Shutdown()
366 raise KeyboardInterrupt # print a stack 369 raise KeyboardInterrupt # print a stack
367 370
368 def _InstallKillHandler(self): 371 def _InstallKillHandler(self):
369 """Install a handler to kill the emulator when we exit unexpectedly.""" 372 """Install a handler to kill the emulator when we exit unexpectedly."""
370 for sig in self._SIGNALS: 373 for sig in self._SIGNALS:
371 signal.signal(sig, self._ShutdownOnSignal) 374 signal.signal(sig, self._ShutdownOnSignal)
OLDNEW
« build/android/pylib/android_commands.py ('K') | « build/android/pylib/android_commands.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698