xref: /aosp_15_r20/external/crosvm/src/crosvm/sys/windows/cmdline.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use argh::CommandInfo;
6 use argh::EarlyExit;
7 use argh::FromArgs;
8 use argh::SubCommand;
9 
10 use crate::crosvm::cmdline::RunCommand;
11 #[derive(Debug, FromArgs)]
12 #[argh(subcommand)]
13 /// Windows Devices
14 pub enum DeviceSubcommand {}
15 
16 #[cfg(feature = "slirp")]
17 #[derive(FromArgs)]
18 #[argh(subcommand, name = "run-slirp")]
19 /// Start a new slirp instance
20 pub struct RunSlirpCommand {
21     #[argh(option, arg_name = "TRANSPORT_TUBE_RD")]
22     /// tube transporter descriptor used to bootstrap the Slirp process.
23     pub bootstrap: usize,
24 }
25 
26 #[derive(FromArgs)]
27 #[argh(subcommand, name = "run-main")]
28 /// Start a new broker instance
29 pub struct RunMainCommand {
30     #[argh(option, arg_name = "TRANSPORT_TUBE_RD")]
31     /// tube transporter descriptor used to bootstrap the main process.
32     pub bootstrap: usize,
33 }
34 
35 #[derive(FromArgs)]
36 #[argh(subcommand, name = "run-metrics")]
37 /// Start a new metrics instance
38 pub struct RunMetricsCommand {
39     #[argh(option, arg_name = "TRANSPORT_TUBE_RD")]
40     #[allow(dead_code)]
41     /// tube transporter descriptor used to bootstrap the metrics process.
42     pub bootstrap: usize,
43 }
44 
45 const RUN_MP_CMD_NAME: &str = "run-mp";
46 
47 /// Start a new mp crosvm instance
48 pub struct RunMPCommand {
49     pub run: RunCommand,
50 }
51 
52 impl FromArgs for RunMPCommand {
from_args(cmd_name: &[&str], args: &[&str]) -> std::result::Result<Self, EarlyExit>53     fn from_args(cmd_name: &[&str], args: &[&str]) -> std::result::Result<Self, EarlyExit> {
54         Ok(Self {
55             run: RunCommand::from_args(cmd_name, args)?,
56         })
57     }
redact_arg_values( cmd_name: &[&str], args: &[&str], ) -> std::result::Result<Vec<String>, EarlyExit>58     fn redact_arg_values(
59         cmd_name: &[&str],
60         args: &[&str],
61     ) -> std::result::Result<Vec<String>, EarlyExit> {
62         RunCommand::redact_arg_values(cmd_name, args)
63     }
64 }
65 
66 impl SubCommand for RunMPCommand {
67     const COMMAND: &'static CommandInfo = &CommandInfo {
68         name: RUN_MP_CMD_NAME,
69         description: "Start a new mp crosvm instance",
70     };
71 }
72 
73 // Suppress complaint about RunMPCommand and RunMetricsCommand having a large size variation.
74 #[allow(clippy::large_enum_variant)]
75 #[derive(FromArgs)]
76 #[argh(subcommand)]
77 /// Windows Devices
78 pub enum Commands {
79     RunMetrics(RunMetricsCommand),
80     RunMP(RunMPCommand),
81     #[cfg(feature = "slirp")]
82     RunSlirp(RunSlirpCommand),
83     RunMain(RunMainCommand),
84 }
85 
86 #[cfg(test)]
87 mod tests {
88 
89     use super::*;
90     use crate::crosvm::cmdline::RunCommand;
91 
get_args() -> Vec<&'static str>92     fn get_args() -> Vec<&'static str> {
93         let mut args = vec![
94             "--bios",
95             "C:\\src\\crosvm\\out\\image\\default\\images\\bios.rom",
96             #[cfg(feature = "crash-report")]
97             "--crash-pipe-name",
98             "\\\\.\\pipe\\crashpad_27812_XGTCCTBYULHHLEJU",
99             "--cpus",
100             "4",
101             "--mem",
102             "8192",
103             "--log-file",
104             "C:\\tmp\\Emulator.log",
105             "--kernel-log-file",
106             "C:\\tmp\\Hypervisor.log",
107             "--logs-directory",
108             "C:\\tmp\\emulator_logs",
109             "--serial",
110             "hardware=serial,num=1,type=file,path=C:\\tmp\\AndroidSerial.log,earlycon=true",
111             "--serial",
112             "hardware=virtio-console,num=1,type=file,path=C:\\tmp\\AndroidSerial.log,console=true",
113             "--rwdisk",
114             "C:\\src\\crosvm\\out\\image\\default\\avd\\aggregate.img",
115             "--rwdisk",
116             "C:\\src\\crosvm\\out\\image\\default\\avd\\metadata.img",
117             "--rwdisk",
118             "C:\\src\\crosvm\\out\\image\\default\\avd\\userdata.img",
119             "--rwdisk",
120             "C:\\src\\crosvm\\out\\image\\default\\avd\\misc.img",
121             "--host-guid",
122             "09205719-879f-4324-8efc-3e362a4096f4",
123             "--cid",
124             "3",
125             "--multi-touch",
126             "nil",
127             "--mouse",
128             "nil",
129             "--product-version",
130             "99.9.9.9",
131             "--product-channel",
132             "Local",
133             "--product-name",
134             "Play Games",
135             "--pstore",
136             "path=C:\\tmp\\pstore,size=1048576",
137             "--pvclock",
138             "--params",
139             "fake args",
140         ];
141 
142         if cfg!(feature = "process-invariants") {
143             args.extend(vec![
144                 "--process-invariants-handle",
145                 "7368",
146                 "--process-invariants-size",
147                 "568",
148             ]);
149         }
150         if cfg!(all(feature = "gpu", feature = "gfxstream")) {
151             args.extend(["--gpu", "angle=true,backend=gfxstream,egl=true,gles=false,glx=false,refresh_rate=60,surfaceless=false,vulkan=true,wsi=vk,display_mode=borderless_full_screen,hidden"]);
152             args.extend([
153                 "--gpu-display",
154                 "mode=borderless_full_screen,hidden,refresh-rate=60",
155             ]);
156         }
157         args.extend([
158             "--service-pipe-name",
159             "service-ipc-8244a83a-ae3f-486f-9c50-3fc47b309d27",
160         ]);
161         args
162     }
163 
164     #[test]
parse_run_mp_test()165     fn parse_run_mp_test() {
166         let _ = RunMPCommand::from_args(&["run-mp"], &get_args()).unwrap();
167     }
168 
169     #[test]
parse_run_test()170     fn parse_run_test() {
171         let _ = RunCommand::from_args(&["run-main"], &get_args()).unwrap();
172     }
173 }
174