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 |
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 from devil.android import device_errors | 17 from devil.android import device_errors |
18 from devil.android import device_utils | 18 from devil.android import device_utils |
19 from devil.android.sdk import adb_wrapper | 19 from devil.android.sdk import adb_wrapper |
20 from devil.utils import cmd_helper | 20 from devil.utils import cmd_helper |
21 from pylib import constants | 21 from pylib import constants |
22 from pylib import pexpect | 22 from pylib import pexpect |
23 from pylib.utils import time_profile | 23 from pylib.utils import time_profile |
24 | 24 |
25 import errors | |
26 import run_command | |
27 | |
28 # SD card size | 25 # SD card size |
29 SDCARD_SIZE = '512M' | 26 SDCARD_SIZE = '512M' |
30 | 27 |
31 # Template used to generate config.ini files for the emulator | 28 # Template used to generate config.ini files for the emulator |
32 CONFIG_TEMPLATE = """avd.ini.encoding=ISO-8859-1 | 29 CONFIG_TEMPLATE = """avd.ini.encoding=ISO-8859-1 |
33 hw.dPad=no | 30 hw.dPad=no |
34 hw.lcd.density=320 | 31 hw.lcd.density=320 |
35 sdcard.size=512M | 32 sdcard.size=512M |
36 hw.cpu.arch={hw.cpu.arch} | 33 hw.cpu.arch={hw.cpu.arch} |
37 hw.device.hash=-708107041 | 34 hw.device.hash=-708107041 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 If the test exits abnormally and some temporary AVDs created when testing may | 106 If the test exits abnormally and some temporary AVDs created when testing may |
110 be left in the system. Clean these AVDs. | 107 be left in the system. Clean these AVDs. |
111 """ | 108 """ |
112 avds = device_utils.GetAVDs() | 109 avds = device_utils.GetAVDs() |
113 if not avds: | 110 if not avds: |
114 return | 111 return |
115 for avd_name in avds: | 112 for avd_name in avds: |
116 if 'run_tests_avd' in avd_name: | 113 if 'run_tests_avd' in avd_name: |
117 cmd = ['android', '-s', 'delete', 'avd', '--name', avd_name] | 114 cmd = ['android', '-s', 'delete', 'avd', '--name', avd_name] |
118 cmd_helper.RunCmd(cmd) | 115 cmd_helper.RunCmd(cmd) |
119 logging.info('Delete AVD %s' % avd_name) | 116 logging.info('Delete AVD %s', avd_name) |
120 | 117 |
121 | 118 |
122 class PortPool(object): | 119 class PortPool(object): |
123 """Pool for emulator port starting position that changes over time.""" | 120 """Pool for emulator port starting position that changes over time.""" |
124 _port_min = 5554 | 121 _port_min = 5554 |
125 _port_max = 5585 | 122 _port_max = 5585 |
126 _port_current_index = 0 | 123 _port_current_index = 0 |
127 | 124 |
128 @classmethod | 125 @classmethod |
129 def port_range(cls): | 126 def port_range(cls): |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 logging.critical('emulator _ShutdownOnSignal') | 433 logging.critical('emulator _ShutdownOnSignal') |
437 for sig in self._SIGNALS: | 434 for sig in self._SIGNALS: |
438 signal.signal(sig, signal.SIG_DFL) | 435 signal.signal(sig, signal.SIG_DFL) |
439 self.Shutdown() | 436 self.Shutdown() |
440 raise KeyboardInterrupt # print a stack | 437 raise KeyboardInterrupt # print a stack |
441 | 438 |
442 def _InstallKillHandler(self): | 439 def _InstallKillHandler(self): |
443 """Install a handler to kill the emulator when we exit unexpectedly.""" | 440 """Install a handler to kill the emulator when we exit unexpectedly.""" |
444 for sig in self._SIGNALS: | 441 for sig in self._SIGNALS: |
445 signal.signal(sig, self._ShutdownOnSignal) | 442 signal.signal(sig, self._ShutdownOnSignal) |
OLD | NEW |