Add --mem option to the vm tool
The option is used to override the memoryMib value of the vm config. The
Microdroid tests are modified to use the minimum amount of memory so
that we keep track of the memory requirement.
Bug: 199703022
Bug: 194961381
Test: atest MicrodroidHostTestCases
Change-Id: Id71c756f689e8da50ea19235264cd788ea4c5f70
diff --git a/vm/src/main.rs b/vm/src/main.rs
index fe47d2c..062773b 100644
--- a/vm/src/main.rs
+++ b/vm/src/main.rs
@@ -62,6 +62,11 @@
/// Whether to run VM in debug mode.
#[structopt(short, long)]
debug: bool,
+
+ /// Memory size (in MiB) of the VM. If unspecified, defaults to the value of `memory_mib`
+ /// in the VM config file.
+ #[structopt(short, long)]
+ mem: Option<u32>,
},
/// Run a virtual machine
Run {
@@ -118,7 +123,7 @@
.context("Failed to find VirtualizationService")?;
match opt {
- Opt::RunApp { apk, idsig, instance, config_path, daemonize, log, debug } => {
+ Opt::RunApp { apk, idsig, instance, config_path, daemonize, log, debug, mem } => {
command_run_app(
service,
&apk,
@@ -128,10 +133,11 @@
daemonize,
log.as_deref(),
debug,
+ mem,
)
}
Opt::Run { config, daemonize, log } => {
- command_run(service, &config, daemonize, log.as_deref())
+ command_run(service, &config, daemonize, log.as_deref(), /* mem */ None)
}
Opt::Stop { cid } => command_stop(service, cid),
Opt::List => command_list(service),
diff --git a/vm/src/run.rs b/vm/src/run.rs
index 0d34a97..42da6a3 100644
--- a/vm/src/run.rs
+++ b/vm/src/run.rs
@@ -49,6 +49,7 @@
daemonize: bool,
log_path: Option<&Path>,
debug: bool,
+ mem: Option<u32>,
) -> Result<(), Error> {
let apk_file = File::open(apk).context("Failed to open APK file")?;
let idsig_file = File::create(idsig).context("Failed to create idsig file")?;
@@ -76,8 +77,7 @@
instanceImage: open_parcel_file(instance, true /* writable */)?.into(),
configPath: config_path.to_owned(),
debug,
- // Use the default.
- memoryMib: 0,
+ memoryMib: mem.unwrap_or(0) as i32, // 0 means use the VM default
});
run(service, &config, &format!("{:?}!{:?}", apk, config_path), daemonize, log_path)
}
@@ -88,10 +88,14 @@
config_path: &Path,
daemonize: bool,
log_path: Option<&Path>,
+ mem: Option<u32>,
) -> Result<(), Error> {
let config_file = File::open(config_path).context("Failed to open config file")?;
- let config =
+ let mut config =
VmConfig::load(&config_file).context("Failed to parse config file")?.to_parcelable()?;
+ if let Some(mem) = mem {
+ config.memoryMib = mem as i32;
+ }
run(
service,
&VirtualMachineConfig::RawConfig(config),