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

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

Issue 11801016: [Android] Break GTest emulator launching into a separate function. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: fixed docstring Created 7 years, 11 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/emulator.py ('k') | build/android/run_tests.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 #!/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
11 Emulator: The class provides the methods to launch/shutdown the emulator with 11 Emulator: The class provides the methods to launch/shutdown the emulator with
12 the android virtual device named 'avd_armeabi' . 12 the android virtual device named 'avd_armeabi' .
13 """ 13 """
14 14
15 import logging 15 import logging
16 import os 16 import os
17 import signal 17 import signal
18 import subprocess 18 import subprocess
19 import sys 19 import sys
20 import time 20 import time
21 21
22 from pylib import android_commands 22 from pylib import android_commands
23 from pylib import cmd_helper 23 from pylib import cmd_helper
24 from pylib.utils import time_profile
24 25
25 # adb_interface.py is under ../../third_party/android_testrunner/ 26 # adb_interface.py is under ../../third_party/android_testrunner/
26 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 27 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..',
27 '..', 'third_party', 'android_testrunner')) 28 '..', 'third_party', 'android_testrunner'))
28 import adb_interface 29 import adb_interface
29 import errors 30 import errors
30 import run_command 31 import run_command
31 32
32 class EmulatorLaunchException(Exception): 33 class EmulatorLaunchException(Exception):
33 """Emulator failed to launch.""" 34 """Emulator failed to launch."""
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 """Returns an available TCP port for the console.""" 93 """Returns an available TCP port for the console."""
93 used_ports = [] 94 used_ports = []
94 emulators = android_commands.GetEmulators() 95 emulators = android_commands.GetEmulators()
95 for emulator in emulators: 96 for emulator in emulators:
96 used_ports.append(emulator.split('-')[1]) 97 used_ports.append(emulator.split('-')[1])
97 for port in PortPool.port_range(): 98 for port in PortPool.port_range():
98 if str(port) not in used_ports: 99 if str(port) not in used_ports:
99 return port 100 return port
100 101
101 102
103 def LaunchEmulators(emulator_count, wait_for_boot=True):
104 """Launch multiple emulators and wait for them to boot.
105
106 Args:
107 emulator_count: number of emulators to launch.
108
109 Returns:
110 List of emulators.
111 """
112 emulators = []
113 for n in xrange(emulator_count):
114 t = time_profile.TimeProfile('Emulator launch %d' % n)
115 avd_name = None
116 if n > 0:
117 # Creates a temporary AVD for the extra emulators.
118 avd_name = 'run_tests_avd_%d' % n
119 logging.info('Emulator launch %d with avd_name=%s', n, avd_name)
120 emulator = Emulator(avd_name, False)
craigdh 2013/01/09 01:32:48 The fast_and_loose option will be removed before t
121 emulator.Launch(kill_all_emulators=n == 0)
122 t.Stop()
123 emulators.append(emulator)
124 # Wait for all emulators to boot completed.
125 if wait_for_boot:
126 for emulator in emulators:
127 emulator.ConfirmLaunch(True)
128 return emulators
129
130
102 class Emulator(object): 131 class Emulator(object):
103 """Provides the methods to lanuch/shutdown the emulator. 132 """Provides the methods to launch/shutdown the emulator.
104 133
105 The emulator has the android virtual device named 'avd_armeabi'. 134 The emulator has the android virtual device named 'avd_armeabi'.
106 135
107 The emulator could use any even TCP port between 5554 and 5584 for the 136 The emulator could use any even TCP port between 5554 and 5584 for the
108 console communication, and this port will be part of the device name like 137 console communication, and this port will be part of the device name like
109 'emulator-5554'. Assume it is always True, as the device name is the id of 138 'emulator-5554'. Assume it is always True, as the device name is the id of
110 emulator managed in this class. 139 emulator managed in this class.
111 140
112 Attributes: 141 Attributes:
113 emulator: Path of Android's emulator tool. 142 emulator: Path of Android's emulator tool.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 logging.critical('emulator _ShutdownOnSignal') 334 logging.critical('emulator _ShutdownOnSignal')
306 for sig in self._SIGNALS: 335 for sig in self._SIGNALS:
307 signal.signal(sig, signal.SIG_DFL) 336 signal.signal(sig, signal.SIG_DFL)
308 self.Shutdown() 337 self.Shutdown()
309 raise KeyboardInterrupt # print a stack 338 raise KeyboardInterrupt # print a stack
310 339
311 def _InstallKillHandler(self): 340 def _InstallKillHandler(self):
312 """Install a handler to kill the emulator when we exit unexpectedly.""" 341 """Install a handler to kill the emulator when we exit unexpectedly."""
313 for sig in self._SIGNALS: 342 for sig in self._SIGNALS:
314 signal.signal(sig, self._ShutdownOnSignal) 343 signal.signal(sig, self._ShutdownOnSignal)
315
316 def main(argv):
317 Emulator(None, True).Launch(True)
318
319
320 if __name__ == '__main__':
321 main(sys.argv)
OLDNEW
« no previous file with comments | « build/android/emulator.py ('k') | build/android/run_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698