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

Unified Diff: build/android/pylib/utils/emulator.py

Issue 12407004: Add script to download SDK, system images and create and start AVDs for testing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not catch exceptions so that stack trace is revealed. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/constants.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..df77c52e64654731aa735640700ff520382851a4 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,11 +102,13 @@ def _GetAvailablePort():
return port
-def LaunchEmulators(emulator_count, wait_for_boot=True):
+def LaunchEmulators(emulator_count, abi, wait_for_boot=True):
"""Launch multiple emulators and wait for them to boot.
Args:
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.
@@ -113,12 +116,10 @@ def LaunchEmulators(emulator_count, wait_for_boot=True):
emulators = []
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(avd_name, abi)
emulator.Launch(kill_all_emulators=n == 0)
t.Stop()
emulators.append(emulator)
@@ -159,38 +160,29 @@ 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, avd_name, abi='x86'):
"""Init an Emulator.
Args:
- nwe_avd_name: If set, will create a new temporary AVD.
+ 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
+ android_sdk_root = os.path.join(constants.EMULATOR_SDK_ROOT,
+ 'android_tools', 'sdk')
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.
@@ -199,9 +191,9 @@ class Emulator(object):
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 +204,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 +238,23 @@ 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',
+ ]
+ 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 +315,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:
« no previous file with comments | « build/android/pylib/constants.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698