[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 1 | #!/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 | |
| 8 | The script will launch a specified number of Android Virtual Devices (AVD's). |
| 9 | """ |
| 10 | |
| 11 | |
| 12 | import install_emulator_deps |
| 13 | import logging |
| 14 | import optparse |
| 15 | import os |
| 16 | import subprocess |
| 17 | import sys |
| 18 | |
| 19 | from pylib import constants |
| 20 | from pylib.utils import emulator |
| 21 | |
| 22 | |
| 23 | def main(argv): |
| 24 | # ANDROID_SDK_ROOT needs to be set to the location of the SDK used to launch |
| 25 | # the emulator to find the system images upon launch. |
[email protected] | 5844a6d | 2013-10-04 23:01:59 | [diff] [blame] | 26 | emulator_sdk = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk') |
[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 27 | os.environ['ANDROID_SDK_ROOT'] = emulator_sdk |
| 28 | |
| 29 | opt_parser = optparse.OptionParser(description='AVD script.') |
| 30 | opt_parser.add_option('-n', '--num', dest='emulator_count', |
[email protected] | 4dc4aea | 2013-04-10 01:55:31 | [diff] [blame] | 31 | help='Number of emulators to launch (default is 1).', |
[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 32 | type='int', default='1') |
[email protected] | 4dc4aea | 2013-04-10 01:55:31 | [diff] [blame] | 33 | opt_parser.add_option('--abi', default='x86', |
| 34 | help='Platform of emulators to launch (x86 default).') |
[email protected] | d5a6fd25 | 2013-11-20 10:39:48 | [diff] [blame^] | 35 | opt_parser.add_option('--api-level', dest='api_level', |
| 36 | help='API level for the image, e.g. 19 for Android 4.4', |
| 37 | type='int', default=constants.ANDROID_SDK_VERSION) |
[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 38 | |
| 39 | options, _ = opt_parser.parse_args(argv[1:]) |
[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 40 | |
| 41 | logging.basicConfig(level=logging.INFO, |
| 42 | format='# %(asctime)-15s: %(message)s') |
| 43 | logging.root.setLevel(logging.INFO) |
| 44 | |
| 45 | # Check if KVM is enabled for x86 AVD's and check for x86 system images. |
[email protected] | d5a6fd25 | 2013-11-20 10:39:48 | [diff] [blame^] | 46 | # TODO(andrewhayden) Since we can fix all of these with install_emulator_deps |
| 47 | # why don't we just run it? |
[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 48 | if options.abi =='x86': |
| 49 | if not install_emulator_deps.CheckKVM(): |
[email protected] | 4dc4aea | 2013-04-10 01:55:31 | [diff] [blame] | 50 | logging.critical('ERROR: KVM must be enabled in BIOS, and installed. ' |
| 51 | 'Enable KVM in BIOS and run install_emulator_deps.py') |
[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 52 | return 1 |
[email protected] | d5a6fd25 | 2013-11-20 10:39:48 | [diff] [blame^] | 53 | elif not install_emulator_deps.CheckX86Image(options.api_level): |
[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 54 | logging.critical('ERROR: System image for x86 AVD not installed. Run ' |
| 55 | 'install_emulator_deps.py') |
| 56 | return 1 |
| 57 | |
| 58 | if not install_emulator_deps.CheckSDK(): |
| 59 | logging.critical('ERROR: Emulator SDK not installed. Run ' |
| 60 | 'install_emulator_deps.py.') |
| 61 | return 1 |
| 62 | |
[email protected] | d5a6fd25 | 2013-11-20 10:39:48 | [diff] [blame^] | 63 | if not install_emulator_deps.CheckSDKPlatform(options.api_level): |
| 64 | logging.critical('ERROR: Emulator SDK missing required target for API %d. ' |
| 65 | 'Run install_emulator_deps.py.') |
| 66 | return 1 |
| 67 | |
| 68 | emulator.LaunchEmulators(options.emulator_count, options.abi, |
| 69 | options.api_level, True) |
[email protected] | 8afcc5a | 2013-03-28 00:23:22 | [diff] [blame] | 70 | |
| 71 | |
| 72 | if __name__ == '__main__': |
| 73 | sys.exit(main(sys.argv)) |