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

Side by Side Diff: build/android/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: Moved LaunchEmulators to emulator.py 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 | « no previous file | 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, fast_and_loose=False):
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, fast_and_loose)
121 emulator.Launch(kill_all_emulators=n == 0)
122 t.Stop()
123 emulators.append(emulator)
124 # Wait for all emulators to boot completed.
125 for emulator in emulators:
126 emulator.ConfirmLaunch(True)
127 return emulators
128
129
102 class Emulator(object): 130 class Emulator(object):
103 """Provides the methods to lanuch/shutdown the emulator. 131 """Provides the methods to lanuch/shutdown the emulator.
104 132
105 The emulator has the android virtual device named 'avd_armeabi'. 133 The emulator has the android virtual device named 'avd_armeabi'.
106 134
107 The emulator could use any even TCP port between 5554 and 5584 for the 135 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 136 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 137 'emulator-5554'. Assume it is always True, as the device name is the id of
110 emulator managed in this class. 138 emulator managed in this class.
111 139
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 signal.signal(sig, signal.SIG_DFL) 335 signal.signal(sig, signal.SIG_DFL)
308 self.Shutdown() 336 self.Shutdown()
309 raise KeyboardInterrupt # print a stack 337 raise KeyboardInterrupt # print a stack
310 338
311 def _InstallKillHandler(self): 339 def _InstallKillHandler(self):
312 """Install a handler to kill the emulator when we exit unexpectedly.""" 340 """Install a handler to kill the emulator when we exit unexpectedly."""
313 for sig in self._SIGNALS: 341 for sig in self._SIGNALS:
314 signal.signal(sig, self._ShutdownOnSignal) 342 signal.signal(sig, self._ShutdownOnSignal)
315 343
316 def main(argv): 344 def main(argv):
317 Emulator(None, True).Launch(True) 345 Emulator(None, True).Launch(True)
frankf 2013/01/08 22:14:27 Can we move emulator.py into pylib/utils. Does it
318 346
319 347
320 if __name__ == '__main__': 348 if __name__ == '__main__':
321 main(sys.argv) 349 main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | build/android/run_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698