From c8bfac66f4449c8f04b631fb3970bbf0b8bd5f57 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Wed, 1 Apr 2026 19:15:54 -0700 Subject: [PATCH] test_infra: Move remote_command to test_infra Move remote_command() and remote_command_w_output() from tests/common/utils.rs into test_infra/src/lib.rs to allow reuse across crates. The cloud-hypervisor integration tests already use 'use test_infra::*', so the functions are available without any caller changes. Signed-off-by: Muminul Islam --- cloud-hypervisor/tests/common/utils.rs | 35 ------------------------- test_infra/src/lib.rs | 36 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/cloud-hypervisor/tests/common/utils.rs b/cloud-hypervisor/tests/common/utils.rs index aff1e94ef..5064e1970 100644 --- a/cloud-hypervisor/tests/common/utils.rs +++ b/cloud-hypervisor/tests/common/utils.rs @@ -255,41 +255,6 @@ pub(crate) fn prepare_swtpm_daemon(tmp_dir: &TempDir) -> (std::process::Command, (swtpm_command, swtpm_socket_path) } -pub(crate) fn remote_command(api_socket: &str, command: &str, arg: Option<&str>) -> bool { - let mut cmd = Command::new(clh_command("ch-remote")); - cmd.args([&format!("--api-socket={api_socket}"), command]); - - if let Some(arg) = arg { - cmd.arg(arg); - } - let output = cmd.output().unwrap(); - if output.status.success() { - true - } else { - eprintln!("Error running ch-remote command: {:?}", &cmd); - let stderr = String::from_utf8_lossy(&output.stderr); - eprintln!("stderr: {stderr}"); - false - } -} - -pub(crate) fn remote_command_w_output( - api_socket: &str, - command: &str, - arg: Option<&str>, -) -> (bool, Vec) { - let mut cmd = Command::new(clh_command("ch-remote")); - cmd.args([&format!("--api-socket={api_socket}"), command]); - - if let Some(arg) = arg { - cmd.arg(arg); - } - - let output = cmd.output().expect("Failed to launch ch-remote"); - - (output.status.success(), output.stdout) -} - pub(crate) fn resize_command( api_socket: &str, desired_vcpus: Option, diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index a299b2c49..248e4efa3 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -1776,6 +1776,42 @@ pub fn clh_command(cmd: &str) -> String { String::from(full_path.to_str().unwrap()) } +pub fn remote_command(api_socket: &str, command: &str, arg: Option<&str>) -> bool { + let mut cmd = Command::new(clh_command("ch-remote")); + cmd.args([&format!("--api-socket={api_socket}"), command]); + + if let Some(arg) = arg { + cmd.arg(arg); + } + + let output = cmd.output().unwrap(); + if output.status.success() { + true + } else { + eprintln!("Error running ch-remote command: {:?}", &cmd); + let stderr = String::from_utf8_lossy(&output.stderr); + eprintln!("stderr: {stderr}"); + false + } +} + +pub fn remote_command_w_output( + api_socket: &str, + command: &str, + arg: Option<&str>, +) -> (bool, Vec) { + let mut cmd = Command::new(clh_command("ch-remote")); + cmd.args([&format!("--api-socket={api_socket}"), command]); + + if let Some(arg) = arg { + cmd.arg(arg); + } + + let output = cmd.output().expect("Failed to launch ch-remote"); + + (output.status.success(), output.stdout) +} + pub fn parse_iperf3_output(output: &[u8], sender: bool, bandwidth: bool) -> Result { std::panic::catch_unwind(|| { let s = String::from_utf8_lossy(output);