Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions src/cpu-template-helper/src/fingerprint/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub enum FingerprintDumpError {
ReadSysfsFile(String, std::io::Error),
/// Failed to get kernel version: {0}
GetKernelVersion(std::io::Error),
/// `{0}` failed: {1}
ShellCommand(String, String),
}

pub fn dump(vmm: Arc<Mutex<Vmm>>) -> Result<Fingerprint, FingerprintDumpError> {
Expand Down Expand Up @@ -61,26 +59,6 @@ fn read_sysfs_file(path: &str) -> Result<String, FingerprintDumpError> {
Ok(s.trim_end_matches('\n').to_string())
}

fn run_shell_command(cmd: &str) -> Result<String, FingerprintDumpError> {
let output = std::process::Command::new("bash")
.args(["-c", cmd])
.output()
.map_err(|err| FingerprintDumpError::ShellCommand(cmd.to_string(), err.to_string()))?;

if !output.status.success() {
return Err(FingerprintDumpError::ShellCommand(
cmd.to_string(),
format!(
"code: {:?}\nstdout: {}\nstderr: {}",
output.status.code(),
std::str::from_utf8(&output.stdout).unwrap(),
std::str::from_utf8(&output.stderr).unwrap(),
),
));
}
Ok(std::str::from_utf8(&output.stdout).unwrap().to_string())
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -105,18 +83,4 @@ mod tests {
panic!("Should fail with `No such file or directory`");
}
}

#[test]
fn test_run_valid_shell_command() {
let valid_cmd = "ls";
run_shell_command(valid_cmd).unwrap();
}

#[test]
fn test_run_invalid_shell_command() {
let invalid_cmd = "unknown_command";
if run_shell_command(invalid_cmd).is_ok() {
panic!("Should fail with `unknown_command: not found`");
}
}
}