forked from AbleOS/ableos
Added fuzzy tests
This commit is contained in:
parent
95c979cb83
commit
f2ec9a3034
5
hbvm/fuzz/.gitignore
vendored
Normal file
5
hbvm/fuzz/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
target
|
||||
artifacts
|
||||
corpus
|
||||
coverage
|
||||
Cargo.lock
|
27
hbvm/fuzz/Cargo.toml
Normal file
27
hbvm/fuzz/Cargo.toml
Normal file
|
@ -0,0 +1,27 @@
|
|||
[package]
|
||||
name = "hbvm-fuzz"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition = "2021"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
|
||||
[dependencies.hbvm]
|
||||
path = ".."
|
||||
|
||||
# Prevent this from interfering with workspaces
|
||||
[workspace]
|
||||
members = ["."]
|
||||
|
||||
[profile.release]
|
||||
debug = 1
|
||||
|
||||
[[bin]]
|
||||
name = "vm"
|
||||
path = "fuzz_targets/vm.rs"
|
||||
test = false
|
||||
doc = false
|
29
hbvm/fuzz/fuzz_targets/vm.rs
Normal file
29
hbvm/fuzz/fuzz_targets/vm.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
#![no_main]
|
||||
|
||||
use {
|
||||
hbvm::vm::{
|
||||
mem::{HandlePageFault, Memory, MemoryAccessReason, PageSize},
|
||||
Vm,
|
||||
},
|
||||
libfuzzer_sys::fuzz_target,
|
||||
};
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if let Ok(mut vm) = Vm::<_, 0>::new_validated(data, TestTrapHandler) {
|
||||
let _ = vm.run();
|
||||
}
|
||||
});
|
||||
|
||||
struct TestTrapHandler;
|
||||
impl HandlePageFault for TestTrapHandler {
|
||||
fn page_fault(
|
||||
&mut self,
|
||||
_: MemoryAccessReason,
|
||||
_: &mut Memory,
|
||||
_: u64,
|
||||
_: PageSize,
|
||||
_: *mut u8,
|
||||
) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue