From e1c1c711cec11bc774041921bd6856834f84bfcb Mon Sep 17 00:00:00 2001 From: Daman Mulye Date: Fri, 12 Sep 2025 16:23:09 -0700 Subject: [PATCH 1/5] . --- petri/src/vm/mod.rs | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/petri/src/vm/mod.rs b/petri/src/vm/mod.rs index 25ff95163a..88c8a05ae4 100644 --- a/petri/src/vm/mod.rs +++ b/petri/src/vm/mod.rs @@ -228,7 +228,8 @@ impl PetriVmBuilder { /// event (if configured). Does not configure and start pipette. Should /// only be used for testing platforms that pipette does not support. pub async fn run_without_agent(self) -> anyhow::Result> { - self.run_core().await + let (vm, _) = self.run_core(false).await?; + Ok(vm) } /// Build and run the VM, then wait for the VM to emit the expected boot @@ -237,12 +238,14 @@ impl PetriVmBuilder { assert!(self.config.agent_image.is_some()); assert!(self.config.agent_image.as_ref().unwrap().contains_pipette()); - let mut vm = self.run_core().await?; - let client = vm.wait_for_agent().await?; - Ok((vm, client)) + let (vm, agent) = self.run_core(true).await?; + Ok((vm, agent.unwrap())) } - async fn run_core(self) -> anyhow::Result> { + async fn run_core( + self, + with_agent: bool, + ) -> anyhow::Result<(PetriVm, Option)> { let arch = self.config.arch; let expect_reset = self.expect_reset(); @@ -268,9 +271,39 @@ impl PetriVmBuilder { vm.wait_for_reset_core().await?; } + let client = if with_agent { + Some(vm.wait_for_agent().await?) + } else { + None + }; + + match vm.openhcl_diag() { + Ok(diag) => { + if with_agent { + tracing::info!("Waiting for kmsg to come online"); + diag.kmsg().await?; + tracing::info!("Kmsg is online now"); + match client.as_ref() { + Some(client_ref) => { + tracing::info!("Agent is online now"); + let sh = client_ref.unix_shell(); + pipette_client::cmd!(sh, "dmesg -n 3").run().await?; + tracing::info!("Set console_loglevel to 3"); + } + None => { + tracing::warn!("No agent, so cannot set console_loglevel"); + } + } + } + } + Err(e) => { + tracing::warn!("failed to open VTl2 diagnostic channel: {}", e); + } + } + vm.wait_for_expected_boot_event().await?; - Ok(vm) + Ok((vm, client)) } fn expect_reset(&self) -> bool { From 766604ced9bc65389d06ae7054e61aba119b0d88 Mon Sep 17 00:00:00 2001 From: Daman Mulye Date: Mon, 15 Sep 2025 11:58:15 -0700 Subject: [PATCH 2/5] handle reboot --- petri/src/vm/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/petri/src/vm/mod.rs b/petri/src/vm/mod.rs index 88c8a05ae4..c1b2569a6e 100644 --- a/petri/src/vm/mod.rs +++ b/petri/src/vm/mod.rs @@ -708,7 +708,20 @@ impl PetriVm { /// Wait for the VM to reset and pipette to connect. pub async fn wait_for_reset(&mut self) -> anyhow::Result { self.wait_for_reset_no_agent().await?; - self.wait_for_agent().await + let client = self.wait_for_agent().await?; + + match self.openhcl_diag() { + Ok(diag) => { + diag.kmsg().await?; + let sh = client.unix_shell(); + pipette_client::cmd!(sh, "dmesg -n 3").run().await?; + } + Err(e) => { + tracing::warn!("failed to open VTl2 diagnostic channel: {}", e); + } + } + + Ok(client) } async fn wait_for_reset_core(&mut self) -> anyhow::Result<()> { From 0f541ede36709c4ee6418cbe9ad66dae7f7939e5 Mon Sep 17 00:00:00 2001 From: Daman Mulye Date: Mon, 15 Sep 2025 14:10:16 -0700 Subject: [PATCH 3/5] Wrong approach --- petri/src/vm/mod.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/petri/src/vm/mod.rs b/petri/src/vm/mod.rs index c1b2569a6e..a85f68a07f 100644 --- a/petri/src/vm/mod.rs +++ b/petri/src/vm/mod.rs @@ -280,20 +280,8 @@ impl PetriVmBuilder { match vm.openhcl_diag() { Ok(diag) => { if with_agent { - tracing::info!("Waiting for kmsg to come online"); diag.kmsg().await?; - tracing::info!("Kmsg is online now"); - match client.as_ref() { - Some(client_ref) => { - tracing::info!("Agent is online now"); - let sh = client_ref.unix_shell(); - pipette_client::cmd!(sh, "dmesg -n 3").run().await?; - tracing::info!("Set console_loglevel to 3"); - } - None => { - tracing::warn!("No agent, so cannot set console_loglevel"); - } - } + diag.run_vtl2_command("dmesg", &["-n", "3"]).await?; } } Err(e) => { @@ -713,8 +701,7 @@ impl PetriVm { match self.openhcl_diag() { Ok(diag) => { diag.kmsg().await?; - let sh = client.unix_shell(); - pipette_client::cmd!(sh, "dmesg -n 3").run().await?; + diag.run_vtl2_command("dmesg", &["-n", "3"]).await?; } Err(e) => { tracing::warn!("failed to open VTl2 diagnostic channel: {}", e); From 6678431a461837368df3b8339eede1293a5f13cc Mon Sep 17 00:00:00 2001 From: Daman Mulye Date: Thu, 18 Sep 2025 16:35:03 -0700 Subject: [PATCH 4/5] Cleanup --- petri/src/vm/mod.rs | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/petri/src/vm/mod.rs b/petri/src/vm/mod.rs index a85f68a07f..a2d625640d 100644 --- a/petri/src/vm/mod.rs +++ b/petri/src/vm/mod.rs @@ -277,16 +277,8 @@ impl PetriVmBuilder { None }; - match vm.openhcl_diag() { - Ok(diag) => { - if with_agent { - diag.kmsg().await?; - diag.run_vtl2_command("dmesg", &["-n", "3"]).await?; - } - } - Err(e) => { - tracing::warn!("failed to open VTl2 diagnostic channel: {}", e); - } + if with_agent { + vm.set_console_loglevel(3).await?; } vm.wait_for_expected_boot_event().await?; @@ -697,17 +689,7 @@ impl PetriVm { pub async fn wait_for_reset(&mut self) -> anyhow::Result { self.wait_for_reset_no_agent().await?; let client = self.wait_for_agent().await?; - - match self.openhcl_diag() { - Ok(diag) => { - diag.kmsg().await?; - diag.run_vtl2_command("dmesg", &["-n", "3"]).await?; - } - Err(e) => { - tracing::warn!("failed to open VTl2 diagnostic channel: {}", e); - } - } - + self.set_console_loglevel(3).await?; Ok(client) } @@ -899,6 +881,26 @@ impl PetriVm { anyhow::bail!("VM is not configured with OpenHCL") } } + + async fn set_console_loglevel(&self, level: u8) -> anyhow::Result<()> { + match self.openhcl_diag() { + Ok(diag) => { + diag.kmsg().await?; + let res = diag + .run_vtl2_command("dmesg", &["-n", &level.to_string()]) + .await?; + + if !res.exit_status.success() { + anyhow::bail!("failed to set console loglevel: {:?}", res); + } + } + Err(e) => { + anyhow::bail!("failed to open VTl2 diagnostic channel: {}", e); + } + }; + + Ok(()) + } } /// A running VM that tests can interact with. From bce41b48ee8965752155a2996ad95b90a712794b Mon Sep 17 00:00:00 2001 From: Daman Mulye Date: Fri, 19 Sep 2025 09:02:00 -0700 Subject: [PATCH 5/5] Handle vmm_tests that are not configured with openhcl --- petri/src/vm/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/petri/src/vm/mod.rs b/petri/src/vm/mod.rs index a2d625640d..306d45eb6a 100644 --- a/petri/src/vm/mod.rs +++ b/petri/src/vm/mod.rs @@ -278,7 +278,10 @@ impl PetriVmBuilder { }; if with_agent { - vm.set_console_loglevel(3).await?; + let result = vm.set_console_loglevel(3).await; + if result.is_err() { + tracing::warn!("failed to set console loglevel: {}", result.unwrap_err()); + } } vm.wait_for_expected_boot_event().await?; @@ -689,7 +692,10 @@ impl PetriVm { pub async fn wait_for_reset(&mut self) -> anyhow::Result { self.wait_for_reset_no_agent().await?; let client = self.wait_for_agent().await?; - self.set_console_loglevel(3).await?; + let result = self.set_console_loglevel(3).await; + if result.is_err() { + tracing::warn!("failed to set console loglevel: {}", result.unwrap_err()); + } Ok(client) }