Skip to content

Commit

Permalink
fix: update embedded-hal-fuzz and fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <elpiel93@gmail.com>
  • Loading branch information
elpiel committed Jan 24, 2024
1 parent cc365a9 commit 434e784
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
embedded-hal-fuzz = "0.1.2"
embedded-hal = "0.2.7"
embedded-hal-fuzz = "1.0"
embedded-hal = "1.0"

[dependencies.bno055]
path = ".."
Expand Down
15 changes: 6 additions & 9 deletions fuzz/fuzz_targets/calibrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@
use libfuzzer_sys::fuzz_target;

use embedded_hal::blocking::delay::DelayMs;
use embedded_hal_fuzz as hal_fuzz;
use embedded_hal::{delay::DelayNs, i2c::SevenBitAddress};
use embedded_hal_fuzz::i2c::ArbitraryI2c;

use bno055::{BNO055OperationMode, Bno055};

struct Delay {}

impl Delay { pub fn new() -> Self { Delay{ } }}

impl DelayMs<u16> for Delay {
fn delay_ms(&mut self, _ms: u16) {
impl DelayNs for Delay {
fn delay_ns(&mut self, _ns: u32) {
// no-op, go as fast as possible for fuzzing
}
}

type I2cError = ();

fuzz_target!(|data: &[u8]| {
use hal_fuzz::shared_data::FuzzData;
let data = FuzzData::new(data);
let i2c: hal_fuzz::i2c::I2cFuzz<'_, I2cError> = hal_fuzz::i2c::I2cFuzz::new(data);
fuzz_target!(|i2c: ArbitraryI2c<SevenBitAddress>| {
let mut delay = Delay::new();

let mut imu = Bno055::new(i2c).with_alternative_address();
Expand Down
25 changes: 12 additions & 13 deletions fuzz/fuzz_targets/init.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#![no_main]
use libfuzzer_sys::fuzz_target;

use embedded_hal::blocking::delay::DelayMs;
use embedded_hal_fuzz as hal_fuzz;
use embedded_hal::{delay::DelayNs, i2c::SevenBitAddress};
use embedded_hal_fuzz::i2c::ArbitraryI2c;

struct Delay {}

impl Delay { pub fn new() -> Self { Delay{ } }}

impl DelayMs<u16> for Delay {
fn delay_ms(&mut self, _ms: u16) {
// no-op, go as fast as possible for fuzzing
}
impl Delay {
pub fn new() -> Self {
Delay {}
}
}

type I2cError = ();
impl DelayNs for Delay {
fn delay_ns(&mut self, _ns: u32) {
// no-op, go as fast as possible for fuzzing
}
}

fuzz_target!(|data: &[u8]| {
use hal_fuzz::shared_data::FuzzData;
let data = FuzzData::new(data);
let i2c: hal_fuzz::i2c::I2cFuzz<'_, I2cError> = hal_fuzz::i2c::I2cFuzz::new(data);
fuzz_target!(|i2c: ArbitraryI2c<SevenBitAddress>| {
let mut delay = Delay::new();

// Init BNO055 IMU
Expand Down

0 comments on commit 434e784

Please sign in to comment.