Skip to content

Commit

Permalink
Merge pull request #59 from worm-blossom/slice_helpers
Browse files Browse the repository at this point in the history
Add slice helpers, start cleaning up some bits and pieces
  • Loading branch information
AljoschaMeyer authored Jul 19, 2024
2 parents 9600e03 + 3a57466 commit 61927fd
Show file tree
Hide file tree
Showing 58 changed files with 5,428 additions and 3,720 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,35 @@ exclude = [
]

[features]

default = ["std"]

# Provide functionality that relies on the std library. Enabled by default.
std = []
std = ["alloc"]

# Provide functionality that relies on dynamic memory allocation.
alloc = []

# Provide implementations for scramblers which are used for fuzz testing.
dev = []
# Provide implementations for development helpers.
dev = ["dep:arbitrary"]

[dependencies]
arbitrary = { version = "1.0.2", features = ["derive"]}
arbitrary = { version = "1.0.2", features = ["derive"], optional = true}
either = "1.10.0"
ufotofu_queues = "0.4.0"

# The `thiserror` crate does not currently support no_std so we're using
# a fork until it does. Depending on `thiserror-core` in this way means
# that the dependeny can easily be replaced in the future.
thiserror = { version = "1.0.50", package = "thiserror-core", default-features = false }

trait-variant = "0.1.1"
ufotofu_queues = "0.1.0"
wrapper = "0.1.1"

[dev-dependencies]
smol = "2.0.0"

# docs.rs-specific configuration
[package.metadata.docs.rs]
# document all features
all-features = true
3 changes: 3 additions & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ libfuzzer-sys = { version = "0.4.0", features = ["arbitrary-derive"] }
smol = "2.0.0"
ufotofu = { path = "..", features = ["dev"] }
wrapper = "0.1.1"
either = "1.10.0"

[[bin]]
name = "slices"
Expand Down Expand Up @@ -82,3 +83,66 @@ path = "fuzz_targets/local_nb/scramble_producer.rs"
test = false
doc = false
bench = false

[[bin]]
name = "sync_pipe_into_slice"
path = "fuzz_targets/sync/pipe_into_slice.rs"
test = false
doc = false
bench = false

[[bin]]
name = "sync_bulk_pipe_into_slice"
path = "fuzz_targets/sync/bulk_pipe_into_slice.rs"
test = false
doc = false
bench = false

[[bin]]
name = "sync_pipe_into_slice_uninit"
path = "fuzz_targets/sync/pipe_into_slice_uninit.rs"
test = false
doc = false
bench = false

[[bin]]
name = "sync_bulk_pipe_into_slice_uninit"
path = "fuzz_targets/sync/bulk_pipe_into_slice_uninit.rs"
test = false
doc = false
bench = false

[[bin]]
name = "sync_pipe_from_slice"
path = "fuzz_targets/sync/pipe_from_slice.rs"
test = false
doc = false
bench = false

[[bin]]
name = "local_nb_pipe_into_slice"
path = "fuzz_targets/local_nb/pipe_into_slice.rs"
test = false
doc = false
bench = false

[[bin]]
name = "local_nb_bulk_pipe_into_slice"
path = "fuzz_targets/local_nb/bulk_pipe_into_slice.rs"
test = false
doc = false
bench = false

[[bin]]
name = "local_nb_pipe_into_slice_uninit"
path = "fuzz_targets/local_nb/pipe_into_slice_uninit.rs"
test = false
doc = false
bench = false

[[bin]]
name = "local_nb_bulk_pipe_into_slice_uninit"
path = "fuzz_targets/local_nb/bulk_pipe_into_slice_uninit.rs"
test = false
doc = false
bench = false
41 changes: 41 additions & 0 deletions fuzz/fuzz_targets/local_nb/bulk_pipe_into_slice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#![no_main]

use either::{Left, Right};
use libfuzzer_sys::fuzz_target;
use ufotofu::local_nb::producer::{bulk_pipe_into_slice, TestProducer};

fuzz_target!(|data: (TestProducer<u16, u8, u8>, usize)| {
let (mut producer, length) = data;

let clamped_length = length.clamp(0, 512);

let mut v: Vec<u16> = vec![0; clamped_length];

let producer_data = producer.peek_slice().to_vec();

// peek termination here.

async {
match bulk_pipe_into_slice(&mut v[0..clamped_length], &mut producer).await {
Ok(_) => {
// Were the bytes successfully piped?

// refactor as assert_eq
if producer_data[0..clamped_length] != v[0..clamped_length] {
panic!("Bytes piped into slice did not match!")
}
}
Err(err) => {
// let producer_data = producer.peek_slice();

// If the filled property is not equal to the inner slice, panic.
// assertion macro
if err.filled != producer_data {
panic!("Filled was not the same as the producer slice.")
}

// Do we need to check if the error produced was the right kind? e.g. by inspecting the producer's termination field?
}
}
};
});
43 changes: 43 additions & 0 deletions fuzz/fuzz_targets/local_nb/bulk_pipe_into_slice_uninit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#![no_main]

use core::mem::MaybeUninit;
use either::{Left, Right};
use libfuzzer_sys::fuzz_target;
use ufotofu::local_nb::producer::{bulk_pipe_into_slice_uninit, TestProducer};

fuzz_target!(|data: (TestProducer<u16, u8, u8>, usize)| {
let (mut producer, length) = data;

let clamped_length = length.clamp(0, 512);

let mut v: Vec<u16> = vec![0; clamped_length];

let producer_data = producer.peek_slice().to_vec();

let producer_data_maybe_uninit =
unsafe { &mut *(&mut v[0..clamped_length] as *mut [u16] as *mut [MaybeUninit<u16>]) };

async {
match bulk_pipe_into_slice_uninit(producer_data_maybe_uninit, &mut producer).await {
Ok(_) => {
// Were the bytes successfully piped?

// refactor as assert_eq
if producer_data[0..clamped_length] != v[0..clamped_length] {
panic!("Bytes piped into slice did not match!")
}
}
Err(err) => {
// let producer_data = producer.peek_slice();

// If the filled property is not equal to the inner slice, panic.
// assertion macro
if err.filled != producer_data {
panic!("Filled was not the same as the producer slice.")
}

// Do we need to check if the error produced was the right kind? e.g. by inspecting the producer's termination field?
}
}
};
});
41 changes: 41 additions & 0 deletions fuzz/fuzz_targets/local_nb/pipe_into_slice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#![no_main]

use either::{Left, Right};
use libfuzzer_sys::fuzz_target;
use ufotofu::local_nb::producer::{pipe_into_slice, TestProducer};

fuzz_target!(|data: (TestProducer<u16, u8, u8>, usize)| {
let (mut producer, length) = data;

let clamped_length = length.clamp(0, 512);

let mut v: Vec<u16> = vec![0; clamped_length];

let producer_data = producer.peek_slice().to_vec();

// peek termination here.

async {
match pipe_into_slice(&mut v[0..clamped_length], &mut producer).await {
Ok(_) => {
// Were the bytes successfully piped?

// refactor as assert_eq
if producer_data[0..clamped_length] != v[0..clamped_length] {
panic!("Bytes piped into slice did not match!")
}
}
Err(err) => {
// let producer_data = producer.peek_slice();

// If the filled property is not equal to the inner slice, panic.
// assertion macro
if err.filled != producer_data {
panic!("Filled was not the same as the producer slice.")
}

// Do we need to check if the error produced was the right kind? e.g. by inspecting the producer's termination field?
}
}
};
});
43 changes: 43 additions & 0 deletions fuzz/fuzz_targets/local_nb/pipe_into_slice_uninit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#![no_main]

use core::mem::MaybeUninit;
use either::{Left, Right};
use libfuzzer_sys::fuzz_target;
use ufotofu::local_nb::producer::{pipe_into_slice_uninit, TestProducer};

fuzz_target!(|data: (TestProducer<u16, u8, u8>, usize)| {
let (mut producer, length) = data;

let clamped_length = length.clamp(0, 512);

let mut v: Vec<u16> = vec![0; clamped_length];

let producer_data = producer.peek_slice().to_vec();

let producer_data_maybe_uninit =
unsafe { &mut *(&mut v[0..clamped_length] as *mut [u16] as *mut [MaybeUninit<u16>]) };

async {
match pipe_into_slice_uninit(producer_data_maybe_uninit, &mut producer).await {
Ok(_) => {
// Were the bytes successfully piped?

// refactor as assert_eq
if producer_data[0..clamped_length] != v[0..clamped_length] {
panic!("Bytes piped into slice did not match!")
}
}
Err(err) => {
// let producer_data = producer.peek_slice();

// If the filled property is not equal to the inner slice, panic.
// assertion macro
if err.filled != producer_data {
panic!("Filled was not the same as the producer slice.")
}

// Do we need to check if the error produced was the right kind? e.g. by inspecting the producer's termination field?
}
}
};
});
39 changes: 39 additions & 0 deletions fuzz/fuzz_targets/sync/bulk_pipe_into_slice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#![no_main]

use either::{Left, Right};
use libfuzzer_sys::fuzz_target;
use ufotofu::sync::producer::{bulk_pipe_into_slice, TestProducer};

fuzz_target!(|data: (TestProducer<u16, u8, u8>, usize)| {
let (mut producer, length) = data;

let clamped_length = length.clamp(0, 512);

let mut v: Vec<u16> = vec![0; clamped_length];

let producer_data = producer.peek_slice().to_vec();

// peek termination here.

match bulk_pipe_into_slice(&mut v[0..clamped_length], &mut producer) {
Ok(_) => {
// Were the bytes successfully piped?

// refactor as assert_eq
if producer_data[0..clamped_length] != v[0..clamped_length] {
panic!("Bytes piped into slice did not match!")
}
}
Err(err) => {
// let producer_data = producer.peek_slice();

// If the filled property is not equal to the inner slice, panic.
// assertion macro
if err.filled != producer_data {
panic!("Filled was not the same as the producer slice.")
}

// Do we need to check if the error produced was the right kind? e.g. by inspecting the producer's termination field?
}
}
});
41 changes: 41 additions & 0 deletions fuzz/fuzz_targets/sync/bulk_pipe_into_slice_uninit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#![no_main]

use core::mem::MaybeUninit;
use either::{Left, Right};
use libfuzzer_sys::fuzz_target;
use ufotofu::sync::producer::{bulk_pipe_into_slice_uninit, TestProducer};

fuzz_target!(|data: (TestProducer<u16, u8, u8>, usize)| {
let (mut producer, length) = data;

let clamped_length = length.clamp(0, 512);

let mut v: Vec<u16> = vec![0; clamped_length];

let producer_data = producer.peek_slice().to_vec();

let producer_data_maybe_uninit =
unsafe { &mut *(&mut v[0..clamped_length] as *mut [u16] as *mut [MaybeUninit<u16>]) };

match bulk_pipe_into_slice_uninit(producer_data_maybe_uninit, &mut producer) {
Ok(_) => {
// Were the bytes successfully piped?

// refactor as assert_eq
if producer_data[0..clamped_length] != v[0..clamped_length] {
panic!("Bytes piped into slice did not match!")
}
}
Err(err) => {
// let producer_data = producer.peek_slice();

// If the filled property is not equal to the inner slice, panic.
// assertion macro
if err.filled != producer_data {
panic!("Filled was not the same as the producer slice.")
}

// Do we need to check if the error produced was the right kind? e.g. by inspecting the producer's termination field?
}
}
});
Loading

0 comments on commit 61927fd

Please sign in to comment.