Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Remove unused coverage recorder from input-tester (#2681)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranweiler authored Dec 8, 2022
1 parent aad2929 commit 11923d2
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/agent/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/agent/input-tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ license = "MIT"
[dependencies]
anyhow = "1.0"
atexit = { path = "../atexit" }
coverage = { path = "../coverage" }
debugger = { path = "../debugger" }
fnv = "1.0"
hex = "0.4"
Expand Down
53 changes: 5 additions & 48 deletions src/agent/input-tester/src/crash_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ use std::{
};

use anyhow::Result;
use coverage::{
block::{windows::Recorder as BlockCoverageRecorder, CommandBlockCov},
cache::ModuleCache,
};
use debugger::{BreakpointId, DebugEventHandler, Debugger, ModuleLoadInfo};
use debugger::{DebugEventHandler, Debugger};
use log::{debug, error, trace};
use win_util::{
pipe_handle::{pipe, PipeReaderNonBlocking},
Expand Down Expand Up @@ -48,7 +44,6 @@ pub struct DebuggerResult {
pub stdout: String,
pub stderr: String,
pub debugger_output: String,
pub coverage: Option<CommandBlockCov>,
}

impl DebuggerResult {
Expand All @@ -58,15 +53,13 @@ impl DebuggerResult {
stdout: String,
stderr: String,
debugger_output: String,
coverage: Option<CommandBlockCov>,
) -> Self {
DebuggerResult {
exceptions,
exit_status,
stdout,
stderr,
debugger_output,
coverage,
}
}

Expand Down Expand Up @@ -125,7 +118,7 @@ impl DebuggerResult {
}
}

struct CrashDetectorEventHandler<'a> {
struct CrashDetectorEventHandler {
start_time: Instant,
max_duration: Duration,
ignore_first_chance_exceptions: bool,
Expand All @@ -137,17 +130,15 @@ struct CrashDetectorEventHandler<'a> {
stderr_buffer: Vec<u8>,
debugger_output: String,
exceptions: Vec<Exception>,
coverage: Option<BlockCoverageRecorder<'a>>,
}

impl<'a> CrashDetectorEventHandler<'a> {
impl CrashDetectorEventHandler {
pub fn new(
stdout: PipeReaderNonBlocking,
stderr: PipeReaderNonBlocking,
ignore_first_chance_exceptions: bool,
start_time: Instant,
max_duration: Duration,
coverage: Option<BlockCoverageRecorder<'a>>,
) -> Self {
Self {
start_time,
Expand All @@ -161,7 +152,6 @@ impl<'a> CrashDetectorEventHandler<'a> {
stderr_buffer: vec![],
debugger_output: String::new(),
exceptions: vec![],
coverage,
}
}
}
Expand Down Expand Up @@ -191,7 +181,7 @@ fn is_vcpp_notification(exception: &EXCEPTION_DEBUG_INFO, target_process_handle:
false
}

impl<'a> DebugEventHandler for CrashDetectorEventHandler<'a> {
impl DebugEventHandler for CrashDetectorEventHandler {
fn on_exception(
&mut self,
debugger: &mut Debugger,
Expand Down Expand Up @@ -272,44 +262,16 @@ impl<'a> DebugEventHandler for CrashDetectorEventHandler<'a> {
debugger.quit_debugging();
}
}

fn on_create_process(&mut self, dbg: &mut Debugger, module: &ModuleLoadInfo) {
if let Some(coverage) = &mut self.coverage {
if let Err(err) = coverage.on_create_process(dbg, module) {
error!("error recording coverage on create process: {:?}", err);
dbg.quit_debugging();
}
}
}

fn on_load_dll(&mut self, dbg: &mut Debugger, module: &ModuleLoadInfo) {
if let Some(coverage) = &mut self.coverage {
if let Err(err) = coverage.on_load_dll(dbg, module) {
error!("error recording coverage on load DLL: {:?}", err);
dbg.quit_debugging();
}
}
}

fn on_breakpoint(&mut self, dbg: &mut Debugger, bp: BreakpointId) {
if let Some(coverage) = &mut self.coverage {
if let Err(err) = coverage.on_breakpoint(dbg, bp) {
error!("error recording coverage on breakpoint: {:?}", err);
dbg.quit_debugging();
}
}
}
}

/// This function runs the application under a debugger to detect any crashes in
/// the process or any children processes.
pub fn test_process<'a>(
pub fn test_process(
app_path: impl AsRef<OsStr>,
args: &[impl AsRef<OsStr>],
env: &HashMap<String, String>,
max_duration: Duration,
ignore_first_chance_exceptions: bool,
cache: Option<&'a mut ModuleCache>,
) -> Result<DebuggerResult> {
debug!("Running: {}", logging::command_invocation(&app_path, args));

Expand All @@ -328,16 +290,13 @@ pub fn test_process<'a>(
command.env(k, v);
}

let filter = coverage::code::CmdFilter::default();
let recorder = cache.map(|c| BlockCoverageRecorder::new(c, filter));
let start_time = Instant::now();
let mut event_handler = CrashDetectorEventHandler::new(
stdout_reader,
stderr_reader,
ignore_first_chance_exceptions,
start_time,
max_duration,
recorder,
);
let (mut debugger, mut child) = Debugger::init(command, &mut event_handler)?;
debugger.run(&mut event_handler)?;
Expand Down Expand Up @@ -365,7 +324,6 @@ pub fn test_process<'a>(
String::from_utf8_lossy(&output.stdout).to_string(),
String::from_utf8_lossy(&output.stderr).to_string(),
event_handler.debugger_output,
event_handler.coverage.map(|r| r.into_coverage()),
))
}

Expand Down Expand Up @@ -407,7 +365,6 @@ mod tests {
&HashMap::default(),
$timeout,
/*ignore first chance exceptions*/ true,
None,
)
.unwrap()
}};
Expand Down
1 change: 0 additions & 1 deletion src/agent/input-tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub fn run(
max_run_s,
ignore_first_chance_exceptions,
app_verifier_tests,
coverage::cache::ModuleCache::default(),
)?;

tester.set_appverifier(AppVerifierState::Enabled)?;
Expand Down
12 changes: 1 addition & 11 deletions src/agent/input-tester/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ use std::{
fs,
io::Write,
path::{Path, PathBuf},
sync::{Arc, RwLock},
sync::Arc,
time::Duration,
};

use anyhow::{Context, Result};
use coverage::cache::ModuleCache;
use log::{error, info, trace, warn};
use num_cpus;
use rayon::{prelude::*, ThreadPoolBuilder};
Expand Down Expand Up @@ -71,7 +70,6 @@ pub struct Tester {
ignore_first_chance_exceptions: bool,
appverif_controller: Option<AppVerifierController>,
bugs_found_dir: PathBuf,
module_cache: RwLock<ModuleCache>,
}

impl Tester {
Expand All @@ -83,7 +81,6 @@ impl Tester {
max_run_s: u64,
ignore_first_chance_exceptions: bool,
app_verifier_tests: Option<Vec<String>>,
module_cache: ModuleCache,
) -> Result<Arc<Self>> {
let mut bugs_found_dir = output_dir.to_path_buf();
bugs_found_dir.push("bugs_found");
Expand Down Expand Up @@ -118,26 +115,19 @@ impl Tester {
max_run_s,
ignore_first_chance_exceptions,
bugs_found_dir,
module_cache: RwLock::new(module_cache),
}))
}

/// Run the test file task with the specified input file.
pub fn test_application(&self, input_path: impl AsRef<Path>) -> Result<InputTestResult> {
let app_args = args_with_input_file_applied(&self.driver_args, &input_path)?;

let mut module_cache = self
.module_cache
.write()
.map_err(|err| anyhow::format_err!("{:?}", err))?;

crash_detector::test_process(
&self.driver,
&app_args,
&self.driver_env,
Duration::from_secs(self.max_run_s),
self.ignore_first_chance_exceptions,
Some(&mut *module_cache),
)
.and_then(|result| {
let result = InputTestResult::new(result, PathBuf::from(input_path.as_ref()));
Expand Down
1 change: 0 additions & 1 deletion src/agent/onefuzz/src/input_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ impl<'a> Tester<'a> {
&env,
self.timeout,
IGNORE_FIRST_CHANCE_EXCEPTIONS,
None,
)?;

let crash = if let Some(exception) = report.exceptions.last() {
Expand Down

0 comments on commit 11923d2

Please sign in to comment.