Change prepare_test_result to take reference (#297)

Originally used move to avoid copying, but the copy is cheap in the
normal case (no exceptions) and is more usable this way.
This commit is contained in:
Jason Shirk
2020-11-11 21:48:08 -08:00
committed by GitHub
parent b6be6e30cb
commit 87085bc48a
6 changed files with 21 additions and 13 deletions

View File

@ -42,6 +42,7 @@ use crate::{
},
};
#[derive(Clone)]
pub struct DebuggerResult {
pub exceptions: Vec<Exception>,
pub exit_status: ExitStatus,

View File

@ -21,7 +21,7 @@ use winapi::{
/// An error detected by ASAN.
///
/// These kinds are based on strings output by the lldb ASAN plugin, unrecognized errors should use `UnknownAsanError`.
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub enum AsanError {
UnknownAsanError,
HeapUseAfterFree,

View File

@ -97,6 +97,7 @@ fn generic_exception(exception_record: &EXCEPTION_RECORD) -> Option<ExceptionCod
/// A friendly description of the exception based on the exception code and other
/// parameters available to the debugger when the exception was raised.
#[derive(Clone)]
pub enum ExceptionDescription {
/// A generic exception with no additional details.
GenericException(ExceptionCode),
@ -196,12 +197,14 @@ pub fn new_test_result(
}
/// The file and line number for frame in the calls stack.
#[derive(Clone)]
pub struct FileInfo {
pub file: String,
pub line: u32,
}
/// The location within a function for a call stack entry.
#[derive(Clone)]
pub enum DebugFunctionLocation {
/// If symbol information is available, we use the file/line numbers for stability across builds.
FileInfo(FileInfo),
@ -238,6 +241,7 @@ impl<'a> From<&'a stack::DebugFunctionLocation> for DebugFunctionLocation {
}
/// A stack frame for reporting where an exception or other bug occurs.
#[derive(Clone)]
pub enum DebugStackFrame {
Frame {
/// The name of the function (if available via symbols or exports) or possibly something else like a
@ -281,6 +285,7 @@ impl<'a> From<&'a stack::DebugStackFrame> for DebugStackFrame {
}
/// The details of an exception observed by the execution engine.
#[derive(Clone)]
pub struct Exception {
/// The win32 exception code.
pub exception_code: u32,
@ -316,7 +321,7 @@ impl fmt::Display for Exception {
}
/// How did the program exit - normally (so we have a proper exit code) or was it terminated?
#[derive(Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum ExitStatus {
/// The exit code returned from the process.
Code(i32),
@ -363,6 +368,7 @@ impl fmt::Display for ExitStatus {
}
/// A fuzzer or execution engine sends this message to a back end to report the bugs found for a single input.
#[derive(Clone)]
pub struct TestResult {
/// The input filename that results in the bugs_found.
pub input_file: String,
@ -401,7 +407,7 @@ impl TestResult {
}
/// This is a non-exhaustive list of exceptions that might be raised in a program.
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub enum ExceptionCode {
UnknownExceptionCode,
UnknownApplicationVerifierStop,

View File

@ -18,7 +18,7 @@ use winapi::{
};
/// Errors reported via the VC++ /RTC compiler flag, as defined in vctruntime\inc\rtcapi.h
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub enum VcppRtcError {
UnknownRtcError,
/// _RTC_CORRUPT_STACK (stack memory corrupted)

View File

@ -114,7 +114,7 @@ fn exception_stop_from_u32(code: u32) -> ExceptionStop {
}
/// A bug detected by enabling `handles` in application verifier.
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub enum HandlesStop {
InvalidHandleStop,
InvalidTlsValue,
@ -125,7 +125,7 @@ pub enum HandlesStop {
}
/// A bug detected by enabling `heaps` in application verifier.
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub enum HeapStop {
UnknownError,
AccessViolation,
@ -150,7 +150,7 @@ pub enum HeapStop {
}
/// A bug detected by enabling `leak` in application verifier.
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub enum LeakStop {
Allocation,
Handle,
@ -165,7 +165,7 @@ pub enum LeakStop {
///
/// We don't enable this option normally because it only detects first chance exceptions which are already
/// reported and this option ends up reporting the same issue a second time with a different stack.
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub enum ExceptionStop {
FirstChanceAccessViolationCode,
}
@ -174,6 +174,7 @@ pub enum ExceptionStop {
/// information in understanding the type of bug detected.
///
/// This message encapsulates the most important kinds of bugs detected by application verifier when fuzzing.
#[derive(Copy, Clone)]
pub enum VerifierStop {
/// A bug detected by enabling `heaps` in application verifier.
Heap(HeapStop),

View File

@ -206,7 +206,7 @@ impl Tester {
// and return a collection of results to possibly be reported.
let mut test_results = vec![];
for result in results {
match self.prepare_test_result(result) {
match self.prepare_test_result(&result) {
Ok(Some(result)) => test_results.push(result),
Ok(None) => {}
Err(e) => {
@ -228,7 +228,7 @@ impl Tester {
let summary = Summary::from(&test_result.debugger_result);
let mut results = vec![];
if let Some(result) = self.prepare_test_result(test_result)? {
if let Some(result) = self.prepare_test_result(&test_result)? {
results.push(result);
}
@ -337,10 +337,10 @@ impl Tester {
}
}
pub fn prepare_test_result(&self, result: InputTestResult) -> Result<Option<TestResult>> {
pub fn prepare_test_result(&self, result: &InputTestResult) -> Result<Option<TestResult>> {
if !result.debugger_result.any_crashes_or_timed_out() {
return Ok(Some(new_test_result(
result.debugger_result,
result.debugger_result.clone(),
&result.input_path,
Path::new(""),
)));
@ -396,7 +396,7 @@ impl Tester {
));
self.create_test_failure_artifacts(&logs_dir, &result, &copied_file)?;
Ok(Some(new_test_result(
result.debugger_result,
result.debugger_result.clone(),
&result.input_path,
&logs_dir,
)))