embedded_hal_fuzz/
lib.rs

1//! This crate is specifically designed for fuzzing device drivers or full apps.
2//! It provides a best guess for how to fuzz device-drivers/apps.
3//!
4//! # Getting started
5//! If you are not familiar with fuzzing in rust then it is recommended that you
6//! read over the [cargo-fuzz book](https://rust-fuzz.github.io/book/cargo-fuzz.html).
7//!
8//! ## Install cargo-fuzz
9//! To install cargo-fuzz, run:
10//! ```bash
11//! cargo install cargo-fuzz
12//! ```
13//!
14//! ## Initialising cargo fuzz in your project
15//! To set your project up to use cargo fuzz, run:
16//! ```bash
17//! cargo-fuzz init
18//! ```
19//! This will add a set to targets under the 'fuzz' directory.
20//!
21//! ## Adding a new embedded fuzz target
22//! To add a new embedded fuzz target, run:
23//! ```bash
24//! cargo-fuzz add <my_target>
25//! ```
26//! This will add a new binary target 'fuzz/fuzz_targets/my_target.rs'.
27//! by default this your new target will look something like this;
28//! ```no_run
29//! #![no_main]
30//! use libfuzzer_sys::fuzz_target;
31//!
32//! fuzz_target!(|data: &[u8]| {
33//!     // fuzzed code goes here
34//! });
35//! ```
36//!
37//! To use this library simply bundle all the types that you need into
38//! a fuzzing context object e.g.
39//! ```rust,no_run
40//! use libfuzzer_sys::fuzz_target;
41//! use embedded_hal_fuzz::digital::{ArbitraryInputPin, ArbitraryOutputPin};
42//! use embedded_hal_fuzz::spi::ArbitrarySpiBus;
43//! use embedded_hal::spi::SpiBus;
44//! use embedded_hal::digital::{InputPin, OutputPin};
45//! use arbitrary::Arbitrary;
46//!
47//! #[derive(Debug, Arbitrary)]
48//! struct Ctx {
49//!   input_pin: ArbitraryInputPin,
50//!   output_pin: ArbitraryOutputPin,
51//!   spi: ArbitrarySpiBus<u16>,
52//!   other_data: Vec<u8>,
53//! }
54//! fuzz_target!(|ctx: Ctx| {
55//!   let Ctx {input_pin, mut output_pin, mut spi, other_data } = ctx;
56//!   let _ = output_pin.set_high();
57//! });
58//! ```
59//!
60//! Each of these fuzzed peripherals will return arbitrary results including
61//! both Ok/Error types. As these inputs are driven by fuzzed data,
62//! these types are perfect for fuzzing your drivers.
63
64pub mod delay;
65pub mod digital;
66pub mod i2c;
67pub mod pwm;
68pub mod spi;