Skip to content

Commit

Permalink
feat(rarity): detect bugs during concrete execution
Browse files Browse the repository at this point in the history
 - mainly used code from master branch to realise that
  • Loading branch information
ChristianMoesl committed Mar 1, 2021
1 parent 19bc224 commit 01ace2a
Show file tree
Hide file tree
Showing 4 changed files with 442 additions and 290 deletions.
17 changes: 10 additions & 7 deletions src/engine/bug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@ use riscu::Instruction;
use std::fmt;

#[derive(Debug, Clone)]
pub enum Bug {
pub enum Bug<T: fmt::Display + fmt::Debug + Clone> {
DivisionByZero {
info: BasicInfo,
info: T,
},

AccessToUnitializedMemory {
info: BasicInfo,
info: T,
instruction: Instruction,
operands: Vec<Value>,
},

AccessToUnalignedAddress {
info: BasicInfo,
info: T,
address: u64,
},

AccessToOutOfRangeAddress {
info: BasicInfo,
info: T,
},

ExitCodeGreaterZero {
info: BasicInfo,
info: T,
},
}

impl fmt::Display for Bug {
impl<T> fmt::Display for Bug<T>
where
T: fmt::Display + fmt::Debug + Clone,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Bug::DivisionByZero { info } => write!(f, "reason: division by zero\n{}", info),
Expand Down
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ fn main() -> Result<()> {
input, output, megabytes, cycles, rounds
);

rarity::execute(input, output, ByteSize::mb(megabytes), rounds, cycles)
if let Some(bug) =
rarity::execute(input, output, ByteSize::mb(megabytes), rounds, cycles)?
{
info!("bug found:\n{}", bug);
} else {
info!("no bug found in binary");
}

Ok(())
}
_ => unreachable!(),
}
Expand Down
Loading

0 comments on commit 01ace2a

Please sign in to comment.