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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 """Check if KVM is enabled. |
98 | 98 |
99 Returns: | 99 Returns: |
100 True if kvm-ok returns 0 (already enabled) | 100 True if kvm-ok returns 0 (already enabled) |
101 """ | 101 """ |
102 try: | 102 try: |
103 # Note: Running kvm-ok as root is recommended, but not required, to get | |
104 # better information in case of failure. I.e.: | |
105 # | |
106 # If root: | |
107 # - If /dev/kvm is available, returns 0 (success) | |
108 # | |
109 # - Otherwise, print information explaining whether the CPU | |
110 # supports KVM extensions, and whether they're disabled by the | |
111 # BIOS, then return 1 (failure). | |
112 # | |
113 # If _not_ root: | |
114 # - If /dev/kvm is available, returns 0 (success) | |
115 # | |
116 # - Otherwise, print a message asking to run it as root, and | |
117 # return 1 (failure). | |
118 # | |
119 # Here, there is no need to run it as root, but it is done in InstallKVM() | |
120 # below. | |
103 return not cmd_helper.RunCmd(['kvm-ok']) | 121 return not cmd_helper.RunCmd(['kvm-ok']) |
104 except OSError: | 122 except OSError: |
105 logging.info('kvm-ok not installed') | 123 logging.info('kvm-ok not installed') |
106 return False | 124 return False |
107 | 125 |
108 | 126 |
109 def GetSDK(): | 127 def GetSDK(): |
110 """Download the SDK and unzip it into EMULATOR_SDK_ROOT.""" | 128 """Download the SDK and unzip it into EMULATOR_SDK_ROOT.""" |
111 logging.info('Download Android SDK.') | 129 logging.info('Download Android SDK.') |
112 sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP) | 130 sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP) |
(...skipping 18 matching lines...) Expand all Loading... | |
131 if rc: | 149 if rc: |
132 logging.critical('ERROR: Did not install KVM. Make sure hardware ' | 150 logging.critical('ERROR: Did not install KVM. Make sure hardware ' |
133 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' | 151 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' |
134 'AMD SVM).') | 152 'AMD SVM).') |
135 # TODO(navabi): Use modprobe kvm-amd on AMD processors. | 153 # TODO(navabi): Use modprobe kvm-amd on AMD processors. |
136 rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel']) | 154 rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel']) |
137 if rc: | 155 if rc: |
138 logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure ' | 156 logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure ' |
139 'hardware virtualization is enabled in BIOS.') | 157 'hardware virtualization is enabled in BIOS.') |
140 # Now check to ensure KVM acceleration can be used. | 158 # Now check to ensure KVM acceleration can be used. |
141 rc = cmd_helper.RunCmd(['kvm-ok']) | 159 # Run as root to get better diagnostics in case of failure (see note in |
160 # CheckKVM() above). | |
161 rc = cmd_helper.RunCmd(['sudo', 'kvm-ok']) | |
navabi
2013/12/16 19:43:08
Should we just call CheckKVM() here rather than do
digit1
2013/12/17 08:41:43
Actually, it looks like all /usr/sbin binaries sho
navabi
2013/12/17 21:31:04
I like that idea.
| |
142 if rc: | 162 if rc: |
143 logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware ' | 163 logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware ' |
144 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' | 164 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' |
145 'AMD SVM).') | 165 'AMD SVM).') |
146 | 166 |
147 | 167 |
148 def GetX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): | 168 def GetX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): |
149 """Download x86 system image from Intel's website. | 169 """Download x86 system image from Intel's website. |
150 | 170 |
151 Args: | 171 Args: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 | 273 |
254 # Make sure KVM packages are installed and enabled. | 274 # Make sure KVM packages are installed and enabled. |
255 if CheckKVM(): | 275 if CheckKVM(): |
256 logging.info('KVM already installed and enabled.') | 276 logging.info('KVM already installed and enabled.') |
257 else: | 277 else: |
258 InstallKVM() | 278 InstallKVM() |
259 | 279 |
260 | 280 |
261 if __name__ == '__main__': | 281 if __name__ == '__main__': |
262 sys.exit(main(sys.argv)) | 282 sys.exit(main(sys.argv)) |
OLD | NEW |