blob: 50720ed4016a3c91254854b7ed32183815907d89 [file] [log] [blame]
[email protected]8afcc5a2013-03-28 00:23:221#!/usr/bin/env python
2# Copyright (c) 2013 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Launches Android Virtual Devices with a set configuration for testing Chrome.
7
8The script will launch a specified number of Android Virtual Devices (AVD's).
9"""
10
11
12import install_emulator_deps
13import logging
14import optparse
15import os
[email protected]2ae433d2014-03-11 03:00:3816import re
[email protected]8afcc5a2013-03-28 00:23:2217import sys
18
jbudorick061629442015-09-03 18:00:5719from devil.utils import cmd_helper
[email protected]8afcc5a2013-03-28 00:23:2220from pylib import constants
21from pylib.utils import emulator
22
23
24def main(argv):
25 # ANDROID_SDK_ROOT needs to be set to the location of the SDK used to launch
26 # the emulator to find the system images upon launch.
[email protected]5844a6d2013-10-04 23:01:5927 emulator_sdk = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk')
[email protected]8afcc5a2013-03-28 00:23:2228 os.environ['ANDROID_SDK_ROOT'] = emulator_sdk
29
30 opt_parser = optparse.OptionParser(description='AVD script.')
[email protected]2ae433d2014-03-11 03:00:3831 opt_parser.add_option('--name', help='Optinaly, name of existing AVD to '
32 'launch. If not specified, new AVD\'s will be created')
[email protected]8afcc5a2013-03-28 00:23:2233 opt_parser.add_option('-n', '--num', dest='emulator_count',
[email protected]4dc4aea2013-04-10 01:55:3134 help='Number of emulators to launch (default is 1).',
[email protected]8afcc5a2013-03-28 00:23:2235 type='int', default='1')
[email protected]4dc4aea2013-04-10 01:55:3136 opt_parser.add_option('--abi', default='x86',
37 help='Platform of emulators to launch (x86 default).')
[email protected]d5a6fd252013-11-20 10:39:4838 opt_parser.add_option('--api-level', dest='api_level',
39 help='API level for the image, e.g. 19 for Android 4.4',
40 type='int', default=constants.ANDROID_SDK_VERSION)
[email protected]8afcc5a2013-03-28 00:23:2241
42 options, _ = opt_parser.parse_args(argv[1:])
[email protected]8afcc5a2013-03-28 00:23:2243
44 logging.basicConfig(level=logging.INFO,
45 format='# %(asctime)-15s: %(message)s')
46 logging.root.setLevel(logging.INFO)
47
48 # Check if KVM is enabled for x86 AVD's and check for x86 system images.
[email protected]d5a6fd252013-11-20 10:39:4849 # TODO(andrewhayden) Since we can fix all of these with install_emulator_deps
50 # why don't we just run it?
[email protected]2ae433d2014-03-11 03:00:3851 if options.abi == 'x86':
[email protected]8afcc5a2013-03-28 00:23:2252 if not install_emulator_deps.CheckKVM():
[email protected]4dc4aea2013-04-10 01:55:3153 logging.critical('ERROR: KVM must be enabled in BIOS, and installed. '
54 'Enable KVM in BIOS and run install_emulator_deps.py')
[email protected]8afcc5a2013-03-28 00:23:2255 return 1
[email protected]d5a6fd252013-11-20 10:39:4856 elif not install_emulator_deps.CheckX86Image(options.api_level):
[email protected]8afcc5a2013-03-28 00:23:2257 logging.critical('ERROR: System image for x86 AVD not installed. Run '
58 'install_emulator_deps.py')
59 return 1
60
61 if not install_emulator_deps.CheckSDK():
62 logging.critical('ERROR: Emulator SDK not installed. Run '
63 'install_emulator_deps.py.')
64 return 1
65
[email protected]2ae433d2014-03-11 03:00:3866 # If AVD is specified, check that the SDK has the required target. If not,
67 # check that the SDK has the desired target for the temporary AVD's.
[email protected]58f6bb92014-03-12 10:41:2468 api_level = options.api_level
[email protected]2ae433d2014-03-11 03:00:3869 if options.name:
70 android = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk', 'tools',
71 'android')
72 avds_output = cmd_helper.GetCmdOutput([android, 'list', 'avd'])
jbudorick0f77e962014-11-19 15:41:2973 names = re.findall(r'Name: (\w+)', avds_output)
74 api_levels = re.findall(r'API level (\d+)', avds_output)
[email protected]2ae433d2014-03-11 03:00:3875 try:
76 avd_index = names.index(options.name)
77 except ValueError:
jbudorick58b4d362015-09-08 16:44:5978 logging.critical('ERROR: Specified AVD %s does not exist.', options.name)
[email protected]2ae433d2014-03-11 03:00:3879 return 1
[email protected]00dc3f8952014-03-12 01:58:0580 api_level = int(api_levels[avd_index])
[email protected]2ae433d2014-03-11 03:00:3881
82 if not install_emulator_deps.CheckSDKPlatform(api_level):
[email protected]d5a6fd252013-11-20 10:39:4883 logging.critical('ERROR: Emulator SDK missing required target for API %d. '
84 'Run install_emulator_deps.py.')
85 return 1
86
[email protected]2ae433d2014-03-11 03:00:3887 if options.name:
88 emulator.LaunchEmulator(options.name, options.abi)
89 else:
90 emulator.LaunchTempEmulators(options.emulator_count, options.abi,
91 options.api_level, True)
92
[email protected]8afcc5a2013-03-28 00:23:2293
94
95if __name__ == '__main__':
96 sys.exit(main(sys.argv))