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 """Installs deps for using SDK emulator for testing. | 6 """Installs deps for using SDK emulator for testing. |
7 | 7 |
8 The script will download the SDK and system images, if they are not present, and | 8 The script will download the SDK and system images, if they are not present, and |
9 install and enable KVM, if virtualization has been enabled in the BIOS. | 9 install and enable KVM, if virtualization has been enabled in the BIOS. |
10 """ | 10 """ |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 True if sdk/system-images/android-<api_level>/x86 exists inside | 87 True if sdk/system-images/android-<api_level>/x86 exists inside |
88 EMULATOR_SDK_ROOT. | 88 EMULATOR_SDK_ROOT. |
89 """ | 89 """ |
90 api_target = 'android-%d' % api_level | 90 api_target = 'android-%d' % api_level |
91 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, | 91 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, |
92 'sdk', 'system-images', | 92 'sdk', 'system-images', |
93 api_target, 'x86')) | 93 api_target, 'x86')) |
94 | 94 |
95 | 95 |
96 def CheckKVM(): | 96 def CheckKVM(): |
97 """Check if KVM is enabled. | 97 """Quickly check whether KVM is enabled. |
98 | 98 |
99 Returns: | 99 Returns: |
100 True if kvm-ok returns 0 (already enabled) | 100 True iff /dev/kvm exists (Linux only). |
| 101 """ |
| 102 return os.path.exists('/dev/kvm') |
| 103 |
| 104 |
| 105 def RunKvmOk(): |
| 106 """Run kvm-ok as root to check that KVM is properly enabled after installation |
| 107 of the required packages. |
| 108 |
| 109 Returns: |
| 110 True iff KVM is enabled (/dev/kvm exists). On failure, returns False |
| 111 but also print detailed information explaining why KVM isn't enabled |
| 112 (e.g. CPU doesn't support it, or BIOS disabled it). |
101 """ | 113 """ |
102 try: | 114 try: |
103 return not cmd_helper.RunCmd(['kvm-ok']) | 115 # Note: kvm-ok is in /usr/sbin, so always use 'sudo' to run it. |
| 116 return not cmd_helper.RunCmd(['sudo', 'kvm-ok']) |
104 except OSError: | 117 except OSError: |
105 logging.info('kvm-ok not installed') | 118 logging.info('kvm-ok not installed') |
106 return False | 119 return False |
107 | 120 |
108 | 121 |
109 def GetSDK(): | 122 def GetSDK(): |
110 """Download the SDK and unzip it into EMULATOR_SDK_ROOT.""" | 123 """Download the SDK and unzip it into EMULATOR_SDK_ROOT.""" |
111 logging.info('Download Android SDK.') | 124 logging.info('Download Android SDK.') |
112 sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP) | 125 sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP) |
113 try: | 126 try: |
(...skipping 14 matching lines...) Expand all Loading... |
128 def InstallKVM(): | 141 def InstallKVM(): |
129 """Installs KVM packages.""" | 142 """Installs KVM packages.""" |
130 rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) | 143 rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) |
131 if rc: | 144 if rc: |
132 logging.critical('ERROR: Did not install KVM. Make sure hardware ' | 145 logging.critical('ERROR: Did not install KVM. Make sure hardware ' |
133 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' | 146 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' |
134 'AMD SVM).') | 147 'AMD SVM).') |
135 # TODO(navabi): Use modprobe kvm-amd on AMD processors. | 148 # TODO(navabi): Use modprobe kvm-amd on AMD processors. |
136 rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel']) | 149 rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel']) |
137 if rc: | 150 if rc: |
138 logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure ' | 151 logging.critical('ERROR: Did not add KVM module to Linux Kernel. Make sure ' |
139 'hardware virtualization is enabled in BIOS.') | 152 'hardware virtualization is enabled in BIOS.') |
140 # Now check to ensure KVM acceleration can be used. | 153 # Now check to ensure KVM acceleration can be used. |
141 rc = cmd_helper.RunCmd(['kvm-ok']) | 154 if not RunKvmOk(): |
142 if rc: | |
143 logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware ' | 155 logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware ' |
144 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' | 156 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' |
145 'AMD SVM).') | 157 'AMD SVM).') |
146 | 158 |
147 | 159 |
148 def GetX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): | 160 def GetX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): |
149 """Download x86 system image from Intel's website. | 161 """Download x86 system image from Intel's website. |
150 | 162 |
151 Args: | 163 Args: |
152 api_level: the Android API level to download for. | 164 api_level: the Android API level to download for. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 265 |
254 # Make sure KVM packages are installed and enabled. | 266 # Make sure KVM packages are installed and enabled. |
255 if CheckKVM(): | 267 if CheckKVM(): |
256 logging.info('KVM already installed and enabled.') | 268 logging.info('KVM already installed and enabled.') |
257 else: | 269 else: |
258 InstallKVM() | 270 InstallKVM() |
259 | 271 |
260 | 272 |
261 if __name__ == '__main__': | 273 if __name__ == '__main__': |
262 sys.exit(main(sys.argv)) | 274 sys.exit(main(sys.argv)) |
OLD | NEW |