Chromium Code Reviews| Index: build/android/pylib/utils/emulator.py |
| diff --git a/build/android/pylib/utils/emulator.py b/build/android/pylib/utils/emulator.py |
| index 70afffb2efc2cbe011bb36b21ff3680c6f5c9f6f..1b18d5db82d690891d2aca166bbefb4f4ea381e8 100755 |
| --- a/build/android/pylib/utils/emulator.py |
| +++ b/build/android/pylib/utils/emulator.py |
| @@ -23,14 +23,15 @@ import time_profile |
| # TODO(craigdh): Move these pylib dependencies to pylib/utils/. |
| from pylib import android_commands |
| from pylib import cmd_helper |
| +from pylib import constants |
| -# adb_interface.py is under ../../third_party/android_testrunner/ |
| -sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', |
| - '..', 'third_party', 'android_testrunner')) |
| -import adb_interface |
| import errors |
| import run_command |
| +# Android API level |
| +API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION |
| + |
| + |
| class EmulatorLaunchException(Exception): |
| """Emulator failed to launch.""" |
| pass |
| @@ -101,24 +102,26 @@ def _GetAvailablePort(): |
| return port |
| -def LaunchEmulators(emulator_count, wait_for_boot=True): |
| +def LaunchEmulators(android_sdk_root, emulator_count, abi, wait_for_boot=True): |
| """Launch multiple emulators and wait for them to boot. |
| Args: |
| + android_sdk_root: location of SDK with the system images installed |
| emulator_count: number of emulators to launch. |
| + abi: the emulator target platform |
| + wait_for_boot: whether or not to wait for emulators to boot up |
| Returns: |
| List of emulators. |
| """ |
| emulators = [] |
| + print 'emulator_count: %s' % emulator_count |
|
frankf
2013/03/27 05:16:08
we use logging not print in pylib
navabi
2013/03/27 17:13:36
Done. (removed, debugging artifact).
|
| for n in xrange(emulator_count): |
| t = time_profile.TimeProfile('Emulator launch %d' % n) |
| - avd_name = None |
| - if n > 0: |
| - # Creates a temporary AVD for the extra emulators. |
| - avd_name = 'run_tests_avd_%d' % n |
| + # Creates a temporary AVD. |
| + avd_name = 'run_tests_avd_%d' % n |
| logging.info('Emulator launch %d with avd_name=%s', n, avd_name) |
| - emulator = Emulator(avd_name) |
| + emulator = Emulator(android_sdk_root, avd_name, abi) |
| emulator.Launch(kill_all_emulators=n == 0) |
| t.Stop() |
| emulators.append(emulator) |
| @@ -159,49 +162,40 @@ class Emulator(object): |
| # Time to wait for a "wait for boot complete" (property set on device). |
| _WAITFORBOOT_TIMEOUT = 300 |
| - def __init__(self, new_avd_name): |
| + def __init__(self, android_sdk_root, avd_name, abi='x86'): |
| """Init an Emulator. |
| Args: |
| - nwe_avd_name: If set, will create a new temporary AVD. |
| + android_sdk_root: location of SDK with the system images installed |
| + avd_name: name of the AVD to create |
| + abi: target platform for emulator being created |
| """ |
| - try: |
| - android_sdk_root = os.environ['ANDROID_SDK_ROOT'] |
| - except KeyError: |
| - logging.critical('The ANDROID_SDK_ROOT must be set to run the test on ' |
| - 'emulator.') |
| - raise |
| self.emulator = os.path.join(android_sdk_root, 'tools', 'emulator') |
| self.android = os.path.join(android_sdk_root, 'tools', 'android') |
| self.popen = None |
| self.device = None |
| - self.default_avd = True |
| - self.abi = 'armeabi-v7a' |
| - self.avd = 'avd_armeabi' |
| - if 'x86' in os.environ.get('TARGET_PRODUCT', ''): |
| - self.abi = 'x86' |
| - self.avd = 'avd_x86' |
| - if new_avd_name: |
| - self.default_avd = False |
| - self.avd = self._CreateAVD(new_avd_name) |
| + self.abi = abi |
| + self.avd_name = avd_name |
| + self._CreateAVD() |
| def _DeviceName(self): |
| """Return our device name.""" |
| port = _GetAvailablePort() |
| return ('emulator-%d' % port, port) |
| - def _CreateAVD(self, avd_name): |
| + def _CreateAVD(self): |
| """Creates an AVD with the given name. |
| Return avd_name. |
| """ |
| + print 'self.android: ' + self.android |
|
frankf
2013/03/27 05:16:08
same here. Was this a debugging artifact?
navabi
2013/03/27 17:13:36
Done. (removed, yes it was a debugging artifact).
|
| avd_command = [ |
| self.android, |
| '--silent', |
| 'create', 'avd', |
| - '--name', avd_name, |
| + '--name', self.avd_name, |
| '--abi', self.abi, |
| - '--target', 'android-16', |
| + '--target', API_TARGET, |
| '-c', '128M', |
| '--force', |
| ] |
| @@ -212,7 +206,7 @@ class Emulator(object): |
| avd_process.stdin.write('no\n') |
| avd_process.wait() |
| logging.info('Create AVD command: %s', ' '.join(avd_command)) |
| - return avd_name |
| + return self.avd_name |
| def _DeleteAVD(self): |
| """Delete the AVD of this emulator.""" |
| @@ -246,17 +240,24 @@ class Emulator(object): |
| # The default /data size is 64M. |
| # That's not enough for 8 unit test bundles and their data. |
| '-partition-size', '512', |
| - # Enable GPU by default. |
| - '-gpu', 'on', |
| # Use a familiar name and port. |
| - '-avd', self.avd, |
| - '-port', str(port)] |
| - emulator_command.extend([ |
| - # Wipe the data. We've seen cases where an emulator |
| - # gets 'stuck' if we don't do this (every thousand runs or |
| - # so). |
| + '-avd', self.avd_name, |
| + '-port', str(port), |
| + # Wipe the data. We've seen cases where an emulator gets 'stuck' if we |
| + # don't do this (every thousand runs or so). |
| '-wipe-data', |
| - ]) |
| + # Enable GPU by default. |
| + '-gpu', 'on', |
| + '-qemu', '-m', '1024', |
| + ] |
| + print 'self.abi = %s' % self.abi |
|
frankf
2013/03/27 05:16:08
ditto
navabi
2013/03/27 17:13:36
Done.
|
| + if self.abi == 'x86': |
| + emulator_command.extend([ |
| + # For x86 emulator --enable-kvm will fail early, avoiding accidental |
| + # runs in a slow mode (i.e. without hardware virtualization support). |
| + '--enable-kvm', |
| + ]) |
| + |
| logging.info('Emulator launch command: %s', ' '.join(emulator_command)) |
| self.popen = subprocess.Popen(args=emulator_command, |
| stderr=subprocess.STDOUT) |
| @@ -317,8 +318,7 @@ class Emulator(object): |
| def Shutdown(self): |
| """Shuts down the process started by launch.""" |
| - if not self.default_avd: |
| - self._DeleteAVD() |
| + self._DeleteAVD() |
| if self.popen: |
| self.popen.poll() |
| if self.popen.returncode == None: |