When testing CompOS, write somewhere harmless
The motivation for this is mostly to allow us to run this on real
devices in teamfood without worrying that it will break things. It's
also preparation for extending composd to do more useful things as
well as running tests.
Modify ComposTestCase to always write to /test instead of
/dalvik-cache (both inside & outside the VM).
Improve the support for multiple instances in composd, rename the
force-compile method to make it clear it does test things, and make
sure it uses a test instance of composd (so odsign will ignore it).
Modify composd_cmd to take a parameter telling it what to do.
Plus some gratuitous tweaks / reformats.
Bug: 186126194
Bug: 200020887
Test: atest ComposTestCase
Test: adb shell apex/com.android.compos/bin/composd_cmd forced-compile-test
Change-Id: I7899fe6393b556e04d9e7f8a07671d96e72bb018
diff --git a/compos/composd/aidl/android/system/composd/IIsolatedCompilationService.aidl b/compos/composd/aidl/android/system/composd/IIsolatedCompilationService.aidl
index a1bb92c..3d0ad31 100644
--- a/compos/composd/aidl/android/system/composd/IIsolatedCompilationService.aidl
+++ b/compos/composd/aidl/android/system/composd/IIsolatedCompilationService.aidl
@@ -19,8 +19,13 @@
import com.android.compos.FdAnnotation;
interface IIsolatedCompilationService {
- /** Run "odrefresh --force-compile" in CompOS. */
- void runForcedCompile();
+ /**
+ * Run "odrefresh --dalvik-cache=pending-test --force-compile" in a test instance of CompOS.
+ * This compiles BCP extensions and system server, even if the system artifacts are up to date,
+ * and writes the results to a test directory to avoid disrupting any real artifacts in
+ * existence.
+ */
+ void runForcedCompileForTest();
/**
* Run dex2oat in the currently running instance of the CompOS VM. This is a simple proxy
diff --git a/compos/composd/src/instance_manager.rs b/compos/composd/src/instance_manager.rs
index 6b36ed8..e31296d 100644
--- a/compos/composd/src/instance_manager.rs
+++ b/compos/composd/src/instance_manager.rs
@@ -22,7 +22,7 @@
use anyhow::{bail, Context, Result};
use compos_aidl_interface::aidl::com::android::compos::ICompOsService::ICompOsService;
use compos_aidl_interface::binder::Strong;
-use compos_common::CURRENT_DIR;
+use compos_common::{CURRENT_INSTANCE_DIR, TEST_INSTANCE_DIR};
use std::sync::{Arc, Mutex, Weak};
use virtualizationservice::IVirtualizationService::IVirtualizationService;
@@ -42,13 +42,22 @@
Ok(instance.get_service())
}
+ #[allow(dead_code)] // TODO: Make use of this
pub fn start_current_instance(&self) -> Result<Arc<CompOsInstance>> {
+ self.start_instance(CURRENT_INSTANCE_DIR)
+ }
+
+ pub fn start_test_instance(&self) -> Result<Arc<CompOsInstance>> {
+ self.start_instance(TEST_INSTANCE_DIR)
+ }
+
+ fn start_instance(&self, instance_name: &str) -> Result<Arc<CompOsInstance>> {
let mut state = self.state.lock().unwrap();
state.mark_starting()?;
// Don't hold the lock while we start the instance to avoid blocking other callers.
drop(state);
- let instance = self.try_start_current_instance();
+ let instance = self.try_start_instance(instance_name);
let mut state = self.state.lock().unwrap();
if let Ok(ref instance) = instance {
@@ -59,8 +68,8 @@
instance
}
- fn try_start_current_instance(&self) -> Result<Arc<CompOsInstance>> {
- let instance_starter = InstanceStarter::new(CURRENT_DIR);
+ fn try_start_instance(&self, instance_name: &str) -> Result<Arc<CompOsInstance>> {
+ let instance_starter = InstanceStarter::new(instance_name);
let compos_instance = instance_starter.create_or_start_instance(&*self.service)?;
Ok(Arc::new(compos_instance))
diff --git a/compos/composd/src/odrefresh.rs b/compos/composd/src/odrefresh.rs
index 2d880e2..2dfc3a1 100644
--- a/compos/composd/src/odrefresh.rs
+++ b/compos/composd/src/odrefresh.rs
@@ -37,10 +37,11 @@
CleanupFailed = EX_MAX + 4,
}
-pub fn run_forced_compile() -> Result<ExitCode> {
+pub fn run_forced_compile(target_dir: &str) -> Result<ExitCode> {
// We don`t need to capture stdout/stderr - odrefresh writes to the log
let mut odrefresh = Command::new(ODREFRESH_BIN)
.arg(format!("--use-compilation-os={}", VMADDR_CID_ANY as i32))
+ .arg(format!("--dalvik-cache={}", target_dir))
.arg("--force-compile")
.spawn()
.context("Running odrefresh")?;
diff --git a/compos/composd/src/service.rs b/compos/composd/src/service.rs
index be9c30c..d3b73a1 100644
--- a/compos/composd/src/service.rs
+++ b/compos/composd/src/service.rs
@@ -42,9 +42,9 @@
impl Interface for IsolatedCompilationService {}
impl IIsolatedCompilationService for IsolatedCompilationService {
- fn runForcedCompile(&self) -> binder::Result<()> {
+ fn runForcedCompileForTest(&self) -> binder::Result<()> {
// TODO - check caller is system or shell/root?
- to_binder_result(self.do_run_forced_compile())
+ to_binder_result(self.do_run_forced_compile_for_test())
}
fn compile_cmd(
@@ -70,12 +70,12 @@
}
impl IsolatedCompilationService {
- fn do_run_forced_compile(&self) -> Result<()> {
- info!("runForcedCompile");
+ fn do_run_forced_compile_for_test(&self) -> Result<()> {
+ info!("runForcedCompileForTest");
- let comp_os = self.instance_manager.start_current_instance().context("Starting CompOS")?;
+ let comp_os = self.instance_manager.start_test_instance().context("Starting CompOS")?;
- let exit_code = odrefresh::run_forced_compile()?;
+ let exit_code = odrefresh::run_forced_compile("test-artifacts")?;
if exit_code != odrefresh::ExitCode::CompilationSuccess {
bail!("Unexpected odrefresh result: {:?}", exit_code);