summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandrewhayden@chromium.org <andrewhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-20 10:39:48 +0000
committerandrewhayden@chromium.org <andrewhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-20 10:39:48 +0000
commitd5a6fd25c970ad33b5c60c530cb68d5a0ae3945c (patch)
treef512f5ea00e9fb2f4896c1b969721e003fa2e4dc
parent605c08b51d236978f9a39e6864712e8385f2b775 (diff)
downloadchromium_src-d5a6fd25c970ad33b5c60c530cb68d5a0ae3945c.zip
chromium_src-d5a6fd25c970ad33b5c60c530cb68d5a0ae3945c.tar.gz
chromium_src-d5a6fd25c970ad33b5c60c530cb68d5a0ae3945c.tar.bz2
Emulator script improvements: config templates, --api-level, and mips support.
BUG= Review URL: https://codereview.chromium.org/72383005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236219 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xbuild/android/avd.py15
-rw-r--r--build/android/avd_configs/AVD_for_Galaxy_Nexus_by_Google_arm.avd/config.ini30
-rw-r--r--build/android/avd_configs/AVD_for_Galaxy_Nexus_by_Google_x86.avd/config.ini29
-rw-r--r--build/android/pylib/utils/emulator.py92
4 files changed, 87 insertions, 79 deletions
diff --git a/build/android/avd.py b/build/android/avd.py
index 43bb3ea..d9cb82c7d 100755
--- a/build/android/avd.py
+++ b/build/android/avd.py
@@ -32,6 +32,9 @@ def main(argv):
type='int', default='1')
opt_parser.add_option('--abi', default='x86',
help='Platform of emulators to launch (x86 default).')
+ opt_parser.add_option('--api-level', dest='api_level',
+ help='API level for the image, e.g. 19 for Android 4.4',
+ type='int', default=constants.ANDROID_SDK_VERSION)
options, _ = opt_parser.parse_args(argv[1:])
@@ -40,12 +43,14 @@ def main(argv):
logging.root.setLevel(logging.INFO)
# Check if KVM is enabled for x86 AVD's and check for x86 system images.
+ # TODO(andrewhayden) Since we can fix all of these with install_emulator_deps
+ # why don't we just run it?
if options.abi =='x86':
if not install_emulator_deps.CheckKVM():
logging.critical('ERROR: KVM must be enabled in BIOS, and installed. '
'Enable KVM in BIOS and run install_emulator_deps.py')
return 1
- elif not install_emulator_deps.CheckX86Image():
+ elif not install_emulator_deps.CheckX86Image(options.api_level):
logging.critical('ERROR: System image for x86 AVD not installed. Run '
'install_emulator_deps.py')
return 1
@@ -55,7 +60,13 @@ def main(argv):
'install_emulator_deps.py.')
return 1
- emulator.LaunchEmulators(options.emulator_count, options.abi, True)
+ if not install_emulator_deps.CheckSDKPlatform(options.api_level):
+ logging.critical('ERROR: Emulator SDK missing required target for API %d. '
+ 'Run install_emulator_deps.py.')
+ return 1
+
+ emulator.LaunchEmulators(options.emulator_count, options.abi,
+ options.api_level, True)
if __name__ == '__main__':
diff --git a/build/android/avd_configs/AVD_for_Galaxy_Nexus_by_Google_arm.avd/config.ini b/build/android/avd_configs/AVD_for_Galaxy_Nexus_by_Google_arm.avd/config.ini
deleted file mode 100644
index 9e0ad80..0000000
--- a/build/android/avd_configs/AVD_for_Galaxy_Nexus_by_Google_arm.avd/config.ini
+++ /dev/null
@@ -1,30 +0,0 @@
-avd.ini.encoding=ISO-8859-1
-hw.dPad=no
-hw.lcd.density=320
-sdcard.size=512M
-hw.cpu.arch=arm
-hw.device.hash=-708107041
-hw.camera.back=none
-disk.dataPartition.size=800M
-hw.gpu.enabled=yes
-skin.dynamic=yes
-skin.path=720x1280
-hw.keyboard=yes
-hw.cpu.model=cortex-a8
-hw.ramSize=1024
-hw.device.manufacturer=Google
-hw.sdCard=yes
-hw.mainKeys=no
-hw.accelerometer=yes
-skin.name=720x1280
-abi.type=armeabi-v7a
-hw.trackBall=no
-hw.device.name=Galaxy Nexus
-hw.battery=yes
-hw.sensors.proximity=yes
-image.sysdir.1=system-images/android-18/armeabi-v7a/
-hw.sensors.orientation=yes
-hw.audioInput=yes
-hw.camera.front=none
-hw.gps=yes
-vm.heapSize=128
diff --git a/build/android/avd_configs/AVD_for_Galaxy_Nexus_by_Google_x86.avd/config.ini b/build/android/avd_configs/AVD_for_Galaxy_Nexus_by_Google_x86.avd/config.ini
deleted file mode 100644
index 26f7bfe..0000000
--- a/build/android/avd_configs/AVD_for_Galaxy_Nexus_by_Google_x86.avd/config.ini
+++ /dev/null
@@ -1,29 +0,0 @@
-avd.ini.encoding=ISO-8859-1
-hw.dPad=no
-hw.lcd.density=320
-sdcard.size=512M
-hw.cpu.arch=x86
-hw.device.hash=-708107041
-hw.camera.back=none
-disk.dataPartition.size=800M
-hw.gpu.enabled=yes
-skin.path=720x1280
-skin.dynamic=yes
-hw.keyboard=yes
-hw.ramSize=1024
-hw.device.manufacturer=Google
-hw.sdCard=yes
-hw.mainKeys=no
-hw.accelerometer=yes
-skin.name=720x1280
-abi.type=x86
-hw.trackBall=no
-hw.device.name=Galaxy Nexus
-hw.battery=yes
-hw.sensors.proximity=yes
-image.sysdir.1=system-images/android-18/x86/
-hw.sensors.orientation=yes
-hw.audioInput=yes
-hw.camera.front=none
-hw.gps=yes
-vm.heapSize=128
diff --git a/build/android/pylib/utils/emulator.py b/build/android/pylib/utils/emulator.py
index 4ff2f03..e2bf1e0 100644
--- a/build/android/pylib/utils/emulator.py
+++ b/build/android/pylib/utils/emulator.py
@@ -28,12 +28,59 @@ from pylib import pexpect
import errors
import run_command
-# Android API level
-API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION
-
# SD card size
SDCARD_SIZE = '512M'
+# Template used to generate config.ini files for the emulator
+CONFIG_TEMPLATE = """avd.ini.encoding=ISO-8859-1
+hw.dPad=no
+hw.lcd.density=320
+sdcard.size=512M
+hw.cpu.arch={hw.cpu.arch}
+hw.device.hash=-708107041
+hw.camera.back=none
+disk.dataPartition.size=800M
+hw.gpu.enabled=yes
+skin.path=720x1280
+skin.dynamic=yes
+hw.keyboard=yes
+hw.ramSize=1024
+hw.device.manufacturer=Google
+hw.sdCard=yes
+hw.mainKeys=no
+hw.accelerometer=yes
+skin.name=720x1280
+abi.type={abi.type}
+hw.trackBall=no
+hw.device.name=Galaxy Nexus
+hw.battery=yes
+hw.sensors.proximity=yes
+image.sysdir.1=system-images/android-{api.level}/{abi.type}/
+hw.sensors.orientation=yes
+hw.audioInput=yes
+hw.camera.front=none
+hw.gps=yes
+vm.heapSize=128
+{extras}"""
+
+CONFIG_REPLACEMENTS = {
+ 'x86': {
+ '{hw.cpu.arch}': 'x86',
+ '{abi.type}': 'x86',
+ '{extras}': ''
+ },
+ 'arm': {
+ '{hw.cpu.arch}': 'arm',
+ '{abi.type}': 'armeabi-v7a',
+ '{extras}': 'hw.cpu.model=cortex-a8\n'
+ },
+ 'mips': {
+ '{hw.cpu.arch}': 'mips',
+ '{abi.type}': 'mips',
+ '{extras}': ''
+ }
+}
+
class EmulatorLaunchException(Exception):
"""Emulator failed to launch."""
pass
@@ -104,12 +151,13 @@ def _GetAvailablePort():
return port
-def LaunchEmulators(emulator_count, abi, wait_for_boot=True):
+def LaunchEmulators(emulator_count, abi, api_level, 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
+ api_level: the api level (e.g., 19 for Android v4.4 - KitKat release)
wait_for_boot: whether or not to wait for emulators to boot up
Returns:
@@ -120,8 +168,9 @@ def LaunchEmulators(emulator_count, abi, wait_for_boot=True):
t = time_profile.TimeProfile('Emulator launch %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, abi)
+ logging.info('Emulator launch %d with avd_name=%s and api=%d',
+ n, avd_name, api_level)
+ emulator = Emulator(avd_name, abi, api_level)
emulator.Launch(kill_all_emulators=n == 0)
t.Stop()
emulators.append(emulator)
@@ -162,12 +211,13 @@ class Emulator(object):
# Time to wait for a "wait for boot complete" (property set on device).
_WAITFORBOOT_TIMEOUT = 300
- def __init__(self, avd_name, abi):
+ def __init__(self, avd_name, abi, api_level):
"""Init an Emulator.
Args:
avd_name: name of the AVD to create
- abi: target platform for emulator being created
+ abi: target platform for emulator being created, defaults to x86
+ api_level: the api level of the image
"""
android_sdk_root = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk')
self.emulator = os.path.join(android_sdk_root, 'tools', 'emulator')
@@ -176,6 +226,7 @@ class Emulator(object):
self.device = None
self.abi = abi
self.avd_name = avd_name
+ self.api_level = api_level
self._CreateAVD()
def _DeviceName(self):
@@ -191,16 +242,20 @@ class Emulator(object):
if self.abi == 'arm':
abi_option = 'armeabi-v7a'
+ elif self.abi == 'mips':
+ abi_option = 'mips'
else:
abi_option = 'x86'
+ api_target = 'android-%s' % self.api_level
+
avd_command = [
self.android,
'--silent',
'create', 'avd',
'--name', self.avd_name,
'--abi', abi_option,
- '--target', API_TARGET,
+ '--target', api_target,
'--sdcard', SDCARD_SIZE,
'--force',
]
@@ -213,13 +268,6 @@ class Emulator(object):
avd_process.sendline('no\n')
avd_process.expect('Created AVD \'%s\'' % self.avd_name)
- # Setup test device as default Galaxy Nexus AVD
- avd_config_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android',
- 'avd_configs')
- avd_config_ini = os.path.join(avd_config_dir,
- 'AVD_for_Galaxy_Nexus_by_Google_%s.avd' %
- self.abi, 'config.ini')
-
# Replace current configuration with default Galaxy Nexus config.
avds_dir = os.path.join(os.path.expanduser('~'), '.android', 'avd')
ini_file = os.path.join(avds_dir, '%s.ini' % self.avd_name)
@@ -233,11 +281,19 @@ class Emulator(object):
# Create new configuration files with Galaxy Nexus by Google settings.
with open(ini_file, 'w') as new_ini:
new_ini.write('avd.ini.encoding=ISO-8859-1\n')
- new_ini.write('target=%s\n' % API_TARGET)
+ new_ini.write('target=%s\n' % api_target)
new_ini.write('path=%s/%s.avd\n' % (avds_dir, self.avd_name))
new_ini.write('path.rel=avd/%s.avd\n' % self.avd_name)
- shutil.copy(avd_config_ini, new_config_ini)
+ custom_config = CONFIG_TEMPLATE
+ replacements = CONFIG_REPLACEMENTS[self.abi]
+ for key in replacements:
+ custom_config = custom_config.replace(key, replacements[key])
+ custom_config = custom_config.replace('{api.level}', str(self.api_level))
+
+ with open(new_config_ini, 'w') as new_config_ini:
+ new_config_ini.write(custom_config)
+
return self.avd_name