OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Launches Android Virtual Devices with a set configuration for testing Chrome. | 6 """Launches Android Virtual Devices with a set configuration for testing Chrome. |
7 | 7 |
8 The script will launch a specified number of Android Virtual Devices (AVD's). | 8 The script will launch a specified number of Android Virtual Devices (AVD's). |
9 """ | 9 """ |
10 | 10 |
11 | 11 |
12 import install_emulator_deps | 12 import install_emulator_deps |
13 import logging | 13 import logging |
14 import optparse | 14 import optparse |
15 import os | 15 import os |
16 import re | 16 import re |
17 import sys | 17 import sys |
18 | 18 |
19 from devil.utils import cmd_helper | 19 from devil.utils import cmd_helper |
20 from pylib import constants | 20 from pylib import constants |
21 from pylib.utils import emulator | 21 from pylib.utils import emulator |
22 | 22 |
23 | |
24 def main(argv): | 23 def main(argv): |
25 # ANDROID_SDK_ROOT needs to be set to the location of the SDK used to launch | 24 # 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. | 25 # the emulator to find the system images upon launch. |
27 emulator_sdk = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk') | 26 emulator_sdk = constants.ANDROID_SDK_ROOT |
28 os.environ['ANDROID_SDK_ROOT'] = emulator_sdk | 27 os.environ['ANDROID_SDK_ROOT'] = emulator_sdk |
29 | 28 |
30 opt_parser = optparse.OptionParser(description='AVD script.') | 29 opt_parser = optparse.OptionParser(description='AVD script.') |
31 opt_parser.add_option('--name', help='Optinaly, name of existing AVD to ' | 30 opt_parser.add_option('--name', help='Optinaly, name of existing AVD to ' |
32 'launch. If not specified, new AVD\'s will be created') | 31 'launch. If not specified, new AVD\'s will be created') |
33 opt_parser.add_option('-n', '--num', dest='emulator_count', | 32 opt_parser.add_option('-n', '--num', dest='emulator_count', |
34 help='Number of emulators to launch (default is 1).', | 33 help='Number of emulators to launch (default is 1).', |
35 type='int', default='1') | 34 type='int', default='1') |
36 opt_parser.add_option('--abi', default='x86', | 35 opt_parser.add_option('--abi', default='x86', |
37 help='Platform of emulators to launch (x86 default).') | 36 help='Platform of emulators to launch (x86 default).') |
38 opt_parser.add_option('--api-level', dest='api_level', | 37 opt_parser.add_option('--api-level', dest='api_level', |
39 help='API level for the image, e.g. 19 for Android 4.4', | 38 help='API level for the image, e.g. 19 for Android 4.4', |
40 type='int', default=constants.ANDROID_SDK_VERSION) | 39 type='int', default=constants.ANDROID_SDK_VERSION) |
41 | 40 |
42 options, _ = opt_parser.parse_args(argv[1:]) | 41 options, _ = opt_parser.parse_args(argv[1:]) |
43 | 42 |
44 logging.basicConfig(level=logging.INFO, | |
45 format='# %(asctime)-15s: %(message)s') | |
46 logging.root.setLevel(logging.INFO) | 43 logging.root.setLevel(logging.INFO) |
47 | 44 |
| 45 # Check if SDK exist in ANDROID_SDK_ROOT |
| 46 if not install_emulator_deps.CheckSDK(): |
| 47 raise Exception('Emulator SDK not installed in %s' |
| 48 % constants.ANDROID_SDK_ROOT) |
| 49 |
48 # Check if KVM is enabled for x86 AVD's and check for x86 system images. | 50 # Check if KVM is enabled for x86 AVD's and check for x86 system images. |
49 # TODO(andrewhayden) Since we can fix all of these with install_emulator_deps | 51 # TODO(andrewhayden) Since we can fix all of these with install_emulator_deps |
50 # why don't we just run it? | 52 # why don't we just run it? |
51 if options.abi == 'x86': | 53 if options.abi == 'x86': |
52 if not install_emulator_deps.CheckKVM(): | 54 if not install_emulator_deps.CheckKVM(): |
53 logging.critical('ERROR: KVM must be enabled in BIOS, and installed. ' | 55 logging.critical('ERROR: KVM must be enabled in BIOS, and installed. ' |
54 'Enable KVM in BIOS and run install_emulator_deps.py') | 56 'Enable KVM in BIOS and run install_emulator_deps.py') |
55 return 1 | 57 return 1 |
56 elif not install_emulator_deps.CheckX86Image(options.api_level): | 58 elif not install_emulator_deps.CheckX86Image(options.api_level): |
57 logging.critical('ERROR: System image for x86 AVD not installed. Run ' | 59 logging.critical('ERROR: System image for x86 AVD not installed. Run ' |
58 'install_emulator_deps.py') | 60 'install_emulator_deps.py') |
59 return 1 | 61 return 1 |
60 | 62 |
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 | |
66 # If AVD is specified, check that the SDK has the required target. If not, | 63 # 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. | 64 # check that the SDK has the desired target for the temporary AVD's. |
68 api_level = options.api_level | 65 api_level = options.api_level |
69 if options.name: | 66 if options.name: |
70 android = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk', 'tools', | 67 android = os.path.join(constants.ANDROID_SDK_ROOT, 'tools', |
71 'android') | 68 'android') |
72 avds_output = cmd_helper.GetCmdOutput([android, 'list', 'avd']) | 69 avds_output = cmd_helper.GetCmdOutput([android, 'list', 'avd']) |
73 names = re.findall(r'Name: (\w+)', avds_output) | 70 names = re.findall(r'Name: (\w+)', avds_output) |
74 api_levels = re.findall(r'API level (\d+)', avds_output) | 71 api_levels = re.findall(r'API level (\d+)', avds_output) |
75 try: | 72 try: |
76 avd_index = names.index(options.name) | 73 avd_index = names.index(options.name) |
77 except ValueError: | 74 except ValueError: |
78 logging.critical('ERROR: Specified AVD %s does not exist.', options.name) | 75 logging.critical('ERROR: Specified AVD %s does not exist.', options.name) |
79 return 1 | 76 return 1 |
80 api_level = int(api_levels[avd_index]) | 77 api_level = int(api_levels[avd_index]) |
81 | 78 |
82 if not install_emulator_deps.CheckSDKPlatform(api_level): | 79 if not install_emulator_deps.CheckSDKPlatform(api_level): |
83 logging.critical('ERROR: Emulator SDK missing required target for API %d. ' | 80 logging.critical('ERROR: Emulator SDK missing required target for API %d. ' |
84 'Run install_emulator_deps.py.') | 81 'Run install_emulator_deps.py.') |
85 return 1 | 82 return 1 |
86 | 83 |
87 if options.name: | 84 if options.name: |
88 emulator.LaunchEmulator(options.name, options.abi) | 85 emulator.LaunchEmulator(options.name, options.abi) |
89 else: | 86 else: |
90 emulator.LaunchTempEmulators(options.emulator_count, options.abi, | 87 emulator.LaunchTempEmulators(options.emulator_count, options.abi, |
91 options.api_level, True) | 88 options.api_level, True) |
92 | 89 |
93 | 90 |
94 | 91 |
95 if __name__ == '__main__': | 92 if __name__ == '__main__': |
96 sys.exit(main(sys.argv)) | 93 sys.exit(main(sys.argv)) |
OLD | NEW |