Andrew Walbran | ea9fa48 | 2021-03-04 16:11:12 +0000 | [diff] [blame] | 1 | // Copyright 2021, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //! Android VM control tool. |
| 16 | |
Jooyung Han | c221c05 | 2022-02-22 05:20:15 +0900 | [diff] [blame] | 17 | mod create_idsig; |
Jiyong Park | 48b354d | 2021-07-15 15:04:38 +0900 | [diff] [blame] | 18 | mod create_partition; |
Andrew Walbran | f395b82 | 2021-05-05 10:38:59 +0000 | [diff] [blame] | 19 | mod run; |
Andrew Walbran | ea9fa48 | 2021-03-04 16:11:12 +0000 | [diff] [blame] | 20 | |
Jiyong Park | c2a49cc | 2021-10-15 00:02:12 +0900 | [diff] [blame] | 21 | use android_system_virtualizationservice::aidl::android::system::virtualizationservice::{ |
David Brazdil | 7d1e5ec | 2023-02-06 17:56:29 +0000 | [diff] [blame] | 22 | CpuTopology::CpuTopology, IVirtualizationService::IVirtualizationService, |
| 23 | PartitionType::PartitionType, VirtualMachineAppConfig::DebugLevel::DebugLevel, |
Jiyong Park | c2a49cc | 2021-10-15 00:02:12 +0900 | [diff] [blame] | 24 | }; |
David Brazdil | 20412d9 | 2021-03-18 10:53:06 +0000 | [diff] [blame] | 25 | use anyhow::{Context, Error}; |
Alan Stokes | c4d5def | 2023-02-14 17:01:59 +0000 | [diff] [blame] | 26 | use binder::{ProcessState, Strong}; |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 27 | use clap::{Args, Parser}; |
Jooyung Han | c221c05 | 2022-02-22 05:20:15 +0900 | [diff] [blame] | 28 | use create_idsig::command_create_idsig; |
Jiyong Park | 48b354d | 2021-07-15 15:04:38 +0900 | [diff] [blame] | 29 | use create_partition::command_create_partition; |
Inseob Kim | 7a1fc8f | 2023-11-22 18:45:28 +0900 | [diff] [blame^] | 30 | use glob::glob; |
Nikita Ioffe | b0b6756 | 2022-11-22 15:48:06 +0000 | [diff] [blame] | 31 | use run::{command_run, command_run_app, command_run_microdroid}; |
Nikita Ioffe | 5776f08 | 2023-02-10 21:38:26 +0000 | [diff] [blame] | 32 | use std::num::NonZeroU16; |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 33 | use std::path::{Path, PathBuf}; |
Andrew Walbran | ea9fa48 | 2021-03-04 16:11:12 +0000 | [diff] [blame] | 34 | |
Inseob Kim | a5a262f | 2021-11-17 19:41:03 +0900 | [diff] [blame] | 35 | #[derive(Debug)] |
| 36 | struct Idsigs(Vec<PathBuf>); |
| 37 | |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 38 | #[derive(Args)] |
| 39 | /// Collection of flags that are at VM level and therefore applicable to all subcommands |
| 40 | pub struct CommonConfig { |
| 41 | /// Name of VM |
| 42 | #[arg(long)] |
| 43 | name: Option<String>, |
| 44 | |
| 45 | /// Run VM with vCPU topology matching that of the host. If unspecified, defaults to 1 vCPU. |
| 46 | #[arg(long, default_value = "one_cpu", value_parser = parse_cpu_topology)] |
| 47 | cpu_topology: CpuTopology, |
| 48 | |
| 49 | /// Comma separated list of task profile names to apply to the VM |
| 50 | #[arg(long)] |
| 51 | task_profiles: Vec<String>, |
| 52 | |
| 53 | /// Memory size (in MiB) of the VM. If unspecified, defaults to the value of `memory_mib` |
| 54 | /// in the VM config file. |
| 55 | #[arg(short, long)] |
| 56 | mem: Option<u32>, |
| 57 | |
| 58 | /// Run VM in protected mode. |
| 59 | #[arg(short, long)] |
| 60 | protected: bool, |
| 61 | } |
| 62 | |
| 63 | #[derive(Args)] |
| 64 | /// Collection of flags for debugging |
| 65 | pub struct DebugConfig { |
| 66 | /// Debug level of the VM. Supported values: "full" (default), and "none". |
| 67 | #[arg(long, default_value = "full", value_parser = parse_debug_level)] |
| 68 | debug: DebugLevel, |
| 69 | |
| 70 | /// Path to file for VM console output. |
| 71 | #[arg(long)] |
| 72 | console: Option<PathBuf>, |
| 73 | |
| 74 | /// Path to file for VM console input. |
| 75 | #[arg(long)] |
| 76 | console_in: Option<PathBuf>, |
| 77 | |
| 78 | /// Path to file for VM log output. |
| 79 | #[arg(long)] |
| 80 | log: Option<PathBuf>, |
| 81 | |
| 82 | /// Port at which crosvm will start a gdb server to debug guest kernel. |
| 83 | /// Note: this is only supported on Android kernels android14-5.15 and higher. |
| 84 | #[arg(long)] |
| 85 | gdb: Option<NonZeroU16>, |
| 86 | } |
| 87 | |
| 88 | #[derive(Args)] |
| 89 | /// Collection of flags that are Microdroid specific |
| 90 | pub struct MicrodroidConfig { |
| 91 | /// Path to the file backing the storage. |
| 92 | /// Created if the option is used but the path does not exist in the device. |
| 93 | #[arg(long)] |
| 94 | storage: Option<PathBuf>, |
| 95 | |
| 96 | /// Size of the storage. Used only if --storage is supplied but path does not exist |
| 97 | /// Default size is 10*1024*1024 |
| 98 | #[arg(long)] |
| 99 | storage_size: Option<u64>, |
| 100 | |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 101 | /// Path to disk image containing vendor-specific modules. |
Nikita Ioffe | 631717e | 2023-09-05 13:38:07 +0100 | [diff] [blame] | 102 | #[cfg(vendor_modules)] |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 103 | #[arg(long)] |
| 104 | vendor: Option<PathBuf>, |
| 105 | |
| 106 | /// SysFS nodes of devices to assign to VM |
Nikita Ioffe | 94a8a18 | 2023-11-16 16:37:48 +0000 | [diff] [blame] | 107 | #[cfg(device_assignment)] |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 108 | #[arg(long)] |
| 109 | devices: Vec<PathBuf>, |
Inseob Kim | 172f9eb | 2023-11-06 17:02:08 +0900 | [diff] [blame] | 110 | |
Inseob Kim | 7a1fc8f | 2023-11-22 18:45:28 +0900 | [diff] [blame^] | 111 | /// Version of GKI to use. If set, use instead of microdroid kernel |
Inseob Kim | 172f9eb | 2023-11-06 17:02:08 +0900 | [diff] [blame] | 112 | #[cfg(vendor_modules)] |
| 113 | #[arg(long)] |
Inseob Kim | 7a1fc8f | 2023-11-22 18:45:28 +0900 | [diff] [blame^] | 114 | gki: Option<String>, |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 115 | } |
| 116 | |
Nikita Ioffe | 631717e | 2023-09-05 13:38:07 +0100 | [diff] [blame] | 117 | impl MicrodroidConfig { |
| 118 | #[cfg(vendor_modules)] |
Nikita Ioffe | 631717e | 2023-09-05 13:38:07 +0100 | [diff] [blame] | 119 | fn vendor(&self) -> &Option<PathBuf> { |
| 120 | &self.vendor |
| 121 | } |
| 122 | |
| 123 | #[cfg(not(vendor_modules))] |
Nikita Ioffe | 631717e | 2023-09-05 13:38:07 +0100 | [diff] [blame] | 124 | fn vendor(&self) -> Option<PathBuf> { |
| 125 | None |
| 126 | } |
Nikita Ioffe | 94a8a18 | 2023-11-16 16:37:48 +0000 | [diff] [blame] | 127 | |
Inseob Kim | 172f9eb | 2023-11-06 17:02:08 +0900 | [diff] [blame] | 128 | #[cfg(vendor_modules)] |
Inseob Kim | 7a1fc8f | 2023-11-22 18:45:28 +0900 | [diff] [blame^] | 129 | fn gki(&self) -> Option<&str> { |
| 130 | self.gki.as_deref() |
Inseob Kim | 172f9eb | 2023-11-06 17:02:08 +0900 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | #[cfg(not(vendor_modules))] |
Inseob Kim | 7a1fc8f | 2023-11-22 18:45:28 +0900 | [diff] [blame^] | 134 | fn gki(&self) -> Option<&str> { |
| 135 | None |
Inseob Kim | 172f9eb | 2023-11-06 17:02:08 +0900 | [diff] [blame] | 136 | } |
| 137 | |
Nikita Ioffe | 94a8a18 | 2023-11-16 16:37:48 +0000 | [diff] [blame] | 138 | #[cfg(device_assignment)] |
| 139 | fn devices(&self) -> &Vec<PathBuf> { |
| 140 | &self.devices |
| 141 | } |
| 142 | |
| 143 | #[cfg(not(device_assignment))] |
| 144 | fn devices(&self) -> Vec<PathBuf> { |
| 145 | Vec::new() |
| 146 | } |
Nikita Ioffe | 631717e | 2023-09-05 13:38:07 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 149 | #[derive(Args)] |
| 150 | /// Flags for the run_app subcommand |
| 151 | pub struct RunAppConfig { |
| 152 | #[command(flatten)] |
| 153 | common: CommonConfig, |
| 154 | |
| 155 | #[command(flatten)] |
| 156 | debug: DebugConfig, |
| 157 | |
| 158 | #[command(flatten)] |
| 159 | microdroid: MicrodroidConfig, |
| 160 | |
| 161 | /// Path to VM Payload APK |
| 162 | apk: PathBuf, |
| 163 | |
| 164 | /// Path to idsig of the APK |
| 165 | idsig: PathBuf, |
| 166 | |
| 167 | /// Path to the instance image. Created if not exists. |
| 168 | instance: PathBuf, |
| 169 | |
| 170 | /// Path to VM config JSON within APK (e.g. assets/vm_config.json) |
| 171 | #[arg(long)] |
| 172 | config_path: Option<String>, |
| 173 | |
| 174 | /// Name of VM payload binary within APK (e.g. MicrodroidTestNativeLib.so) |
| 175 | #[arg(long)] |
| 176 | #[arg(alias = "payload_path")] |
| 177 | payload_binary_name: Option<String>, |
| 178 | |
| 179 | /// Paths to extra idsig files. |
| 180 | #[arg(long = "extra-idsig")] |
| 181 | extra_idsigs: Vec<PathBuf>, |
| 182 | } |
| 183 | |
| 184 | #[derive(Args)] |
| 185 | /// Flags for the run_microdroid subcommand |
| 186 | pub struct RunMicrodroidConfig { |
| 187 | #[command(flatten)] |
| 188 | common: CommonConfig, |
| 189 | |
| 190 | #[command(flatten)] |
| 191 | debug: DebugConfig, |
| 192 | |
| 193 | #[command(flatten)] |
| 194 | microdroid: MicrodroidConfig, |
| 195 | |
| 196 | /// Path to the directory where VM-related files (e.g. instance.img, apk.idsig, etc.) will |
| 197 | /// be stored. If not specified a random directory under /data/local/tmp/microdroid will be |
| 198 | /// created and used. |
| 199 | #[arg(long)] |
| 200 | work_dir: Option<PathBuf>, |
| 201 | } |
| 202 | |
| 203 | #[derive(Args)] |
| 204 | /// Flags for the run subcommand |
| 205 | pub struct RunCustomVmConfig { |
| 206 | #[command(flatten)] |
| 207 | common: CommonConfig, |
| 208 | |
| 209 | #[command(flatten)] |
| 210 | debug: DebugConfig, |
| 211 | |
| 212 | /// Path to VM config JSON |
| 213 | config: PathBuf, |
| 214 | } |
| 215 | |
Victor Hsieh | b5bcfab | 2022-09-12 13:06:26 -0700 | [diff] [blame] | 216 | #[derive(Parser)] |
David Brazdil | 20412d9 | 2021-03-18 10:53:06 +0000 | [diff] [blame] | 217 | enum Opt { |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 218 | /// Run a virtual machine with a config in APK |
| 219 | RunApp { |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 220 | #[command(flatten)] |
| 221 | config: RunAppConfig, |
Jooyung Han | 21e9b92 | 2021-06-26 04:14:16 +0900 | [diff] [blame] | 222 | }, |
Nikita Ioffe | b0b6756 | 2022-11-22 15:48:06 +0000 | [diff] [blame] | 223 | /// Run a virtual machine with Microdroid inside |
| 224 | RunMicrodroid { |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 225 | #[command(flatten)] |
| 226 | config: RunMicrodroidConfig, |
Nikita Ioffe | b0b6756 | 2022-11-22 15:48:06 +0000 | [diff] [blame] | 227 | }, |
David Brazdil | 20412d9 | 2021-03-18 10:53:06 +0000 | [diff] [blame] | 228 | /// Run a virtual machine |
| 229 | Run { |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 230 | #[command(flatten)] |
| 231 | config: RunCustomVmConfig, |
David Brazdil | 3c2ddef | 2021-03-18 13:09:57 +0000 | [diff] [blame] | 232 | }, |
David Brazdil | 20412d9 | 2021-03-18 10:53:06 +0000 | [diff] [blame] | 233 | /// List running virtual machines |
| 234 | List, |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 235 | /// Print information about virtual machine support |
| 236 | Info, |
Andrew Walbran | dff3b94 | 2021-06-09 15:20:36 +0000 | [diff] [blame] | 237 | /// Create a new empty partition to be used as a writable partition for a VM |
| 238 | CreatePartition { |
| 239 | /// Path at which to create the image file |
Andrew Walbran | dff3b94 | 2021-06-09 15:20:36 +0000 | [diff] [blame] | 240 | path: PathBuf, |
| 241 | |
| 242 | /// The desired size of the partition, in bytes. |
| 243 | size: u64, |
Jiyong Park | 9dd389e | 2021-08-23 20:42:59 +0900 | [diff] [blame] | 244 | |
| 245 | /// Type of the partition |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 246 | #[arg(short = 't', long = "type", default_value = "raw", |
Victor Hsieh | b5bcfab | 2022-09-12 13:06:26 -0700 | [diff] [blame] | 247 | value_parser = parse_partition_type)] |
Jiyong Park | 9dd389e | 2021-08-23 20:42:59 +0900 | [diff] [blame] | 248 | partition_type: PartitionType, |
Andrew Walbran | dff3b94 | 2021-06-09 15:20:36 +0000 | [diff] [blame] | 249 | }, |
Jooyung Han | c221c05 | 2022-02-22 05:20:15 +0900 | [diff] [blame] | 250 | /// Creates or update the idsig file by digesting the input APK file. |
| 251 | CreateIdsig { |
| 252 | /// Path to VM Payload APK |
Jooyung Han | c221c05 | 2022-02-22 05:20:15 +0900 | [diff] [blame] | 253 | apk: PathBuf, |
Victor Hsieh | b5bcfab | 2022-09-12 13:06:26 -0700 | [diff] [blame] | 254 | |
Jooyung Han | c221c05 | 2022-02-22 05:20:15 +0900 | [diff] [blame] | 255 | /// Path to idsig of the APK |
Jooyung Han | c221c05 | 2022-02-22 05:20:15 +0900 | [diff] [blame] | 256 | path: PathBuf, |
| 257 | }, |
David Brazdil | 20412d9 | 2021-03-18 10:53:06 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Jiyong Park | c2a49cc | 2021-10-15 00:02:12 +0900 | [diff] [blame] | 260 | fn parse_debug_level(s: &str) -> Result<DebugLevel, String> { |
| 261 | match s { |
| 262 | "none" => Ok(DebugLevel::NONE), |
Jiyong Park | c2a49cc | 2021-10-15 00:02:12 +0900 | [diff] [blame] | 263 | "full" => Ok(DebugLevel::FULL), |
| 264 | _ => Err(format!("Invalid debug level {}", s)), |
| 265 | } |
| 266 | } |
| 267 | |
Jiyong Park | 9dd389e | 2021-08-23 20:42:59 +0900 | [diff] [blame] | 268 | fn parse_partition_type(s: &str) -> Result<PartitionType, String> { |
| 269 | match s { |
| 270 | "raw" => Ok(PartitionType::RAW), |
| 271 | "instance" => Ok(PartitionType::ANDROID_VM_INSTANCE), |
| 272 | _ => Err(format!("Invalid partition type {}", s)), |
| 273 | } |
| 274 | } |
| 275 | |
David Brazdil | 7d1e5ec | 2023-02-06 17:56:29 +0000 | [diff] [blame] | 276 | fn parse_cpu_topology(s: &str) -> Result<CpuTopology, String> { |
| 277 | match s { |
| 278 | "one_cpu" => Ok(CpuTopology::ONE_CPU), |
| 279 | "match_host" => Ok(CpuTopology::MATCH_HOST), |
| 280 | _ => Err(format!("Invalid cpu topology {}", s)), |
| 281 | } |
| 282 | } |
| 283 | |
Alan Stokes | c4d5def | 2023-02-14 17:01:59 +0000 | [diff] [blame] | 284 | fn get_service() -> Result<Strong<dyn IVirtualizationService>, Error> { |
| 285 | let virtmgr = |
| 286 | vmclient::VirtualizationService::new().context("Failed to spawn VirtualizationService")?; |
| 287 | virtmgr.connect().context("Failed to connect to VirtualizationService") |
| 288 | } |
| 289 | |
Andrew Walbran | ea9fa48 | 2021-03-04 16:11:12 +0000 | [diff] [blame] | 290 | fn main() -> Result<(), Error> { |
| 291 | env_logger::init(); |
Victor Hsieh | b5bcfab | 2022-09-12 13:06:26 -0700 | [diff] [blame] | 292 | let opt = Opt::parse(); |
Andrew Walbran | ea9fa48 | 2021-03-04 16:11:12 +0000 | [diff] [blame] | 293 | |
| 294 | // We need to start the thread pool for Binder to work properly, especially link_to_death. |
| 295 | ProcessState::start_thread_pool(); |
| 296 | |
David Brazdil | 20412d9 | 2021-03-18 10:53:06 +0000 | [diff] [blame] | 297 | match opt { |
Jiyong Park | b1935ef | 2023-08-10 17:22:39 +0900 | [diff] [blame] | 298 | Opt::RunApp { config } => command_run_app(config), |
| 299 | Opt::RunMicrodroid { config } => command_run_microdroid(config), |
| 300 | Opt::Run { config } => command_run(config), |
Alan Stokes | c4d5def | 2023-02-14 17:01:59 +0000 | [diff] [blame] | 301 | Opt::List => command_list(get_service()?.as_ref()), |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 302 | Opt::Info => command_info(), |
Jiyong Park | 9dd389e | 2021-08-23 20:42:59 +0900 | [diff] [blame] | 303 | Opt::CreatePartition { path, size, partition_type } => { |
Alan Stokes | c4d5def | 2023-02-14 17:01:59 +0000 | [diff] [blame] | 304 | command_create_partition(get_service()?.as_ref(), &path, size, partition_type) |
Jiyong Park | 9dd389e | 2021-08-23 20:42:59 +0900 | [diff] [blame] | 305 | } |
Alan Stokes | c4d5def | 2023-02-14 17:01:59 +0000 | [diff] [blame] | 306 | Opt::CreateIdsig { apk, path } => { |
| 307 | command_create_idsig(get_service()?.as_ref(), &apk, &path) |
| 308 | } |
Andrew Walbran | ea9fa48 | 2021-03-04 16:11:12 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
Andrew Walbran | 320b560 | 2021-03-04 16:11:12 +0000 | [diff] [blame] | 312 | /// List the VMs currently running. |
Andrew Walbran | 616d13f | 2022-05-12 18:35:55 +0000 | [diff] [blame] | 313 | fn command_list(service: &dyn IVirtualizationService) -> Result<(), Error> { |
Andrew Walbran | 17de24f | 2021-05-27 13:27:30 +0000 | [diff] [blame] | 314 | let vms = service.debugListVms().context("Failed to get list of VMs")?; |
Andrew Walbran | 320b560 | 2021-03-04 16:11:12 +0000 | [diff] [blame] | 315 | println!("Running VMs: {:#?}", vms); |
| 316 | Ok(()) |
| 317 | } |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 318 | |
Inseob Kim | 7a1fc8f | 2023-11-22 18:45:28 +0900 | [diff] [blame^] | 319 | fn extract_gki_version(gki_config: &Path) -> Option<&str> { |
| 320 | let name = gki_config.file_name()?; |
| 321 | let name_str = name.to_str()?; |
| 322 | name_str.strip_prefix("microdroid_gki-")?.strip_suffix(".json") |
| 323 | } |
| 324 | |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 325 | /// Print information about supported VM types. |
| 326 | fn command_info() -> Result<(), Error> { |
Alan Stokes | c4d5def | 2023-02-14 17:01:59 +0000 | [diff] [blame] | 327 | let non_protected_vm_supported = hypervisor_props::is_vm_supported()?; |
| 328 | let protected_vm_supported = hypervisor_props::is_protected_vm_supported()?; |
Alan Stokes | 8d39a9b | 2023-01-10 15:01:00 +0000 | [diff] [blame] | 329 | match (non_protected_vm_supported, protected_vm_supported) { |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 330 | (false, false) => println!("VMs are not supported."), |
| 331 | (false, true) => println!("Only protected VMs are supported."), |
Alan Stokes | 8d39a9b | 2023-01-10 15:01:00 +0000 | [diff] [blame] | 332 | (true, false) => println!("Only non-protected VMs are supported."), |
| 333 | (true, true) => println!("Both protected and non-protected VMs are supported."), |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Alan Stokes | c4d5def | 2023-02-14 17:01:59 +0000 | [diff] [blame] | 336 | if let Some(version) = hypervisor_props::version()? { |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 337 | println!("Hypervisor version: {}", version); |
| 338 | } else { |
| 339 | println!("Hypervisor version not set."); |
| 340 | } |
| 341 | |
| 342 | if Path::new("/dev/kvm").exists() { |
| 343 | println!("/dev/kvm exists."); |
| 344 | } else { |
| 345 | println!("/dev/kvm does not exist."); |
| 346 | } |
| 347 | |
Inseob Kim | 6ef8097 | 2023-07-20 17:23:36 +0900 | [diff] [blame] | 348 | if Path::new("/dev/vfio/vfio").exists() { |
| 349 | println!("/dev/vfio/vfio exists."); |
| 350 | } else { |
| 351 | println!("/dev/vfio/vfio does not exist."); |
| 352 | } |
| 353 | |
| 354 | if Path::new("/sys/bus/platform/drivers/vfio-platform").exists() { |
| 355 | println!("VFIO-platform is supported."); |
| 356 | } else { |
| 357 | println!("VFIO-platform is not supported."); |
| 358 | } |
| 359 | |
Inseob Kim | 75460b3 | 2023-08-09 13:41:31 +0900 | [diff] [blame] | 360 | let devices = get_service()?.getAssignableDevices()?; |
| 361 | let devices = devices.into_iter().map(|x| x.node).collect::<Vec<_>>(); |
| 362 | println!("Assignable devices: {}", serde_json::to_string(&devices)?); |
| 363 | |
Inseob Kim | 7a1fc8f | 2023-11-22 18:45:28 +0900 | [diff] [blame^] | 364 | let gki_configs = |
| 365 | glob("/apex/com.android.virt/etc/microdroid_gki-*.json")?.collect::<Result<Vec<_>, _>>()?; |
| 366 | let gki_versions = |
| 367 | gki_configs.iter().filter_map(|x| extract_gki_version(x)).collect::<Vec<_>>(); |
| 368 | println!("Available gki versions: {}", serde_json::to_string(&gki_versions)?); |
| 369 | |
Andrew Walbran | c4b1bde | 2022-02-03 15:26:02 +0000 | [diff] [blame] | 370 | Ok(()) |
| 371 | } |
Andrew Walbran | 1f810b6 | 2022-08-10 13:33:57 +0000 | [diff] [blame] | 372 | |
| 373 | #[cfg(test)] |
| 374 | mod tests { |
| 375 | use super::*; |
Andrew Walbran | aa1efc4 | 2022-08-10 13:33:57 +0000 | [diff] [blame] | 376 | use clap::CommandFactory; |
Andrew Walbran | 1f810b6 | 2022-08-10 13:33:57 +0000 | [diff] [blame] | 377 | |
| 378 | #[test] |
| 379 | fn verify_app() { |
Andrew Walbran | aa1efc4 | 2022-08-10 13:33:57 +0000 | [diff] [blame] | 380 | // Check that the command parsing has been configured in a valid way. |
| 381 | Opt::command().debug_assert(); |
Andrew Walbran | 1f810b6 | 2022-08-10 13:33:57 +0000 | [diff] [blame] | 382 | } |
| 383 | } |