mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-18 10:35:23 +00:00
test_infra, tests: Introduce exec_host_command_output() function
This new function allows for better readability of the code by factorizing a few of lines of code into a single one. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
8091c28dd5
commit
1e2aa769e5
@ -11,7 +11,7 @@ use std::net::TcpListener;
|
||||
use std::net::TcpStream;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::path::Path;
|
||||
use std::process::ExitStatus;
|
||||
use std::process::{ExitStatus, Output};
|
||||
use std::str::FromStr;
|
||||
use std::thread;
|
||||
use vmm_sys_util::tempdir::TempDir;
|
||||
@ -597,3 +597,10 @@ pub fn exec_host_command_status(command: &str) -> ExitStatus {
|
||||
.status()
|
||||
.expect(&format!("Expected '{}' to run", command))
|
||||
}
|
||||
|
||||
pub fn exec_host_command_output(command: &str) -> Output {
|
||||
std::process::Command::new("bash")
|
||||
.args(&["-c", command])
|
||||
.output()
|
||||
.expect(&format!("Expected '{}' to run", command))
|
||||
}
|
||||
|
@ -964,20 +964,14 @@ mod tests {
|
||||
guest.wait_vm_boot(None).unwrap();
|
||||
|
||||
if let Some(tap_name) = tap {
|
||||
let tap_count = std::process::Command::new("bash")
|
||||
.arg("-c")
|
||||
.arg(format!("ip link | grep -c {}", tap_name))
|
||||
.output()
|
||||
.expect("Expected checking of tap count to succeed");
|
||||
let tap_count =
|
||||
exec_host_command_output(&format!("ip link | grep -c {}", tap_name));
|
||||
assert_eq!(String::from_utf8_lossy(&tap_count.stdout).trim(), "1");
|
||||
}
|
||||
|
||||
if let Some(host_mac) = tap {
|
||||
let mac_count = std::process::Command::new("bash")
|
||||
.arg("-c")
|
||||
.arg(format!("ip link | grep -c {}", host_mac))
|
||||
.output()
|
||||
.expect("Expected checking of host mac to succeed");
|
||||
let mac_count =
|
||||
exec_host_command_output(&format!("ip link | grep -c {}", host_mac));
|
||||
assert_eq!(String::from_utf8_lossy(&mac_count.stdout).trim(), "1");
|
||||
}
|
||||
|
||||
@ -2740,11 +2734,7 @@ mod tests {
|
||||
let r = std::panic::catch_unwind(|| {
|
||||
guest.wait_vm_boot(None).unwrap();
|
||||
|
||||
let tap_count = std::process::Command::new("bash")
|
||||
.arg("-c")
|
||||
.arg("ip link | grep -c mytap1")
|
||||
.output()
|
||||
.expect("Expected checking of tap count to succeed");
|
||||
let tap_count = exec_host_command_output("ip link | grep -c mytap1");
|
||||
assert_eq!(String::from_utf8_lossy(&tap_count.stdout).trim(), "1");
|
||||
|
||||
// 3 network interfaces + default localhost ==> 4 interfaces
|
||||
|
Loading…
x
Reference in New Issue
Block a user