mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-12 01:58:18 +00:00
Use a custom Output
type when recording coverage (#2723)
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) Microsoft Corporation.
|
// Copyright (c) Microsoft Corporation.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
use std::process::{Command, Output, Stdio};
|
use std::process::{Command, ExitStatus, Stdio};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ impl CoverageRecorder {
|
|||||||
let (mut dbg, child) = Debugger::init(self.cmd, &mut recorder)?;
|
let (mut dbg, child) = Debugger::init(self.cmd, &mut recorder)?;
|
||||||
dbg.run(&mut recorder)?;
|
dbg.run(&mut recorder)?;
|
||||||
|
|
||||||
let output = child.wait_with_output()?;
|
let output = child.wait_with_output()?.into();
|
||||||
let coverage = recorder.coverage;
|
let coverage = recorder.coverage;
|
||||||
|
|
||||||
Ok(Recorded { coverage, output })
|
Ok(Recorded { coverage, output })
|
||||||
@ -98,3 +98,24 @@ pub struct Recorded {
|
|||||||
pub coverage: BinaryCoverage,
|
pub coverage: BinaryCoverage,
|
||||||
pub output: Output,
|
pub output: Output,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct Output {
|
||||||
|
pub status: Option<ExitStatus>,
|
||||||
|
pub stderr: String,
|
||||||
|
pub stdout: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<std::process::Output> for Output {
|
||||||
|
fn from(output: std::process::Output) -> Self {
|
||||||
|
let status = Some(output.status);
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout).into_owned();
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
status,
|
||||||
|
stdout,
|
||||||
|
stderr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::process::{Command, Output};
|
use std::io::Read;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Result};
|
use anyhow::{bail, format_err, Result};
|
||||||
use debuggable_module::path::FilePath;
|
use debuggable_module::path::FilePath;
|
||||||
@ -10,6 +11,8 @@ use debuggable_module::Address;
|
|||||||
use pete::{Ptracer, Restart, Signal, Stop, Tracee};
|
use pete::{Ptracer, Restart, Signal, Stop, Tracee};
|
||||||
use procfs::process::{MMapPath, MemoryMap, Process};
|
use procfs::process::{MMapPath, MemoryMap, Process};
|
||||||
|
|
||||||
|
use crate::record::Output;
|
||||||
|
|
||||||
pub trait DebugEventHandler {
|
pub trait DebugEventHandler {
|
||||||
fn on_breakpoint(&mut self, dbg: &mut DebuggerContext, tracee: &mut Tracee) -> Result<()>;
|
fn on_breakpoint(&mut self, dbg: &mut DebuggerContext, tracee: &mut Tracee) -> Result<()>;
|
||||||
|
|
||||||
@ -46,7 +49,30 @@ impl<'eh> Debugger<'eh> {
|
|||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = child.wait_with_output()?;
|
// Currently unavailable on Linux.
|
||||||
|
let status = None;
|
||||||
|
|
||||||
|
let stdout = if let Some(mut pipe) = child.stdout {
|
||||||
|
let mut stdout = Vec::new();
|
||||||
|
pipe.read_to_end(&mut stdout)?;
|
||||||
|
String::from_utf8_lossy(&stdout).into_owned()
|
||||||
|
} else {
|
||||||
|
"".into()
|
||||||
|
};
|
||||||
|
|
||||||
|
let stderr = if let Some(mut pipe) = child.stderr {
|
||||||
|
let mut stderr = Vec::new();
|
||||||
|
pipe.read_to_end(&mut stderr)?;
|
||||||
|
String::from_utf8_lossy(&stderr).into_owned()
|
||||||
|
} else {
|
||||||
|
"".into()
|
||||||
|
};
|
||||||
|
|
||||||
|
let output = Output {
|
||||||
|
status,
|
||||||
|
stderr,
|
||||||
|
stdout,
|
||||||
|
};
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user