fix(vm): add doesnt_crash baseline test
This commit is contained in:
parent
0bcf710db3
commit
724531eae9
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -102,6 +102,7 @@ version = "0.0.0"
|
|||
dependencies = [
|
||||
"fogtix-bytecode",
|
||||
"once_cell",
|
||||
"proptest",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
|
|
|
@ -14,3 +14,10 @@ features = ["std"]
|
|||
|
||||
[dependencies.once_cell]
|
||||
version = "1.15"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
[dev-dependencies.proptest]
|
||||
version = "1.0"
|
||||
default-features = false
|
||||
features = ["alloc"]
|
||||
|
|
|
@ -66,6 +66,7 @@ pub struct Process {
|
|||
pub stack: Vec<StackEntValue>,
|
||||
pub callstack: Vec<InstrPtr>,
|
||||
pub instrp: InstrPtr,
|
||||
pub fuel: Option<u64>,
|
||||
}
|
||||
|
||||
impl Process {
|
||||
|
@ -74,6 +75,7 @@ impl Process {
|
|||
stack: Vec::new(),
|
||||
callstack: Vec::new(),
|
||||
instrp,
|
||||
fuel: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,6 +103,13 @@ impl Process {
|
|||
use fogtix_bytecode::consts::MathBinOp;
|
||||
let previptr = self.instrp.pos;
|
||||
tracing::trace!("previptr = {}", previptr);
|
||||
if let Some(ref mut x) = &mut self.fuel {
|
||||
if *x == 0 {
|
||||
tracing::info!("out of fuel");
|
||||
break;
|
||||
}
|
||||
*x -= 1;
|
||||
}
|
||||
let (nxtidelta, nxti) = match next_instr(&self.instrp.m, self.instrp.pos) {
|
||||
None => {
|
||||
tracing::error!(
|
||||
|
@ -358,3 +367,23 @@ impl Process {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
proptest::proptest! {
|
||||
#![proptest_config(proptest::prelude::ProptestConfig::with_cases(4096))]
|
||||
|
||||
#[test]
|
||||
fn doesnt_crash(inp in proptest::collection::vec(0..=u8::MAX, 0..1024)) {
|
||||
let inp: Arc<Vec<u8>> = Arc::new(inp);
|
||||
let module: Module = inp;
|
||||
let mut p = Process::new(InstrPtr {
|
||||
m: module,
|
||||
pos: 0,
|
||||
});
|
||||
p.fuel = Some(1024);
|
||||
p.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue