-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d1f88d
commit 5e854dc
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use ufotofu::local_nb::{bulk_pipe, consumer::TestConsumer, pipe, producer::TestProducer}; | ||
|
||
fuzz_target!( | ||
|data: (TestConsumer<u16, u16, u16>, TestProducer<u16, u16, u16>)| { | ||
smol::block_on(async { | ||
let (mut con, mut pro) = data; | ||
let mut control_con = con.clone(); | ||
let mut control_pro = pro.clone(); | ||
|
||
assert_eq!( | ||
bulk_pipe(&mut pro, &mut con).await, | ||
pipe(&mut control_pro, &mut control_con).await, | ||
); | ||
assert_eq!(con, control_con); | ||
assert_eq!(pro, control_pro); | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use ufotofu::local_nb::{consumer::TestConsumer, pipe, producer::TestProducer, PipeError}; | ||
|
||
fuzz_target!( | ||
|data: (TestProducer<u16, u16, u16>, TestConsumer<u16, u16, u16>)| { | ||
smol::block_on(async { | ||
let (mut pro, mut con) = data; | ||
|
||
let items = pro.remaining().to_vec(); | ||
let last = pro.peek_last().unwrap().clone(); | ||
let consumer_err = con.peek_error().unwrap().clone(); | ||
|
||
match pipe(&mut pro, &mut con).await { | ||
Ok(()) => { | ||
assert!(pro.did_already_emit_last()); | ||
assert_eq!(con.consumed(), &items[..]); | ||
assert_eq!(con.final_consumed(), Some(&last.unwrap())); | ||
} | ||
Err(PipeError::Consumer(err)) => { | ||
if pro.peek_last().is_none() && last.is_err() { | ||
panic!(); | ||
} | ||
assert!(con.did_error()); | ||
assert_eq!(err, consumer_err); | ||
assert_eq!(con.consumed(), &items[..con.consumed().len()]); | ||
assert_eq!( | ||
pro.remaining(), | ||
&items[con.consumed().len() | ||
+ if pro.did_already_emit_last() { 0 } else { 1 }..] | ||
); // TODO | ||
} | ||
Err(PipeError::Producer(err)) => { | ||
assert!(pro.did_already_emit_last()); | ||
assert!(!con.did_error()); | ||
assert_eq!(err, last.unwrap_err()); | ||
assert_eq!(con.consumed(), &items[..con.consumed().len()]); | ||
assert_eq!(pro.remaining(), &items[con.consumed().len()..]); | ||
} | ||
} | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use ufotofu::sync::{consumer::TestConsumer, producer::TestProducer, pipe, bulk_pipe}; | ||
|
||
fuzz_target!(|data: (TestConsumer<u16, u16, u16>, TestProducer<u16, u16, u16>)| { | ||
let (mut con, mut pro) = data; | ||
let mut control_con = con.clone(); | ||
let mut control_pro = pro.clone(); | ||
|
||
assert_eq!( | ||
bulk_pipe(&mut pro, &mut con), | ||
pipe(&mut control_pro, &mut control_con), | ||
); | ||
assert_eq!(con, control_con); | ||
assert_eq!(pro, control_pro); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use ufotofu::sync::{consumer::TestConsumer, pipe, producer::TestProducer, PipeError}; | ||
|
||
fuzz_target!( | ||
|data: (TestProducer<u16, u16, u16>, TestConsumer<u16, u16, u16>)| { | ||
let (mut pro, mut con) = data; | ||
|
||
let items = pro.remaining().to_vec(); | ||
let last = pro.peek_last().unwrap().clone(); | ||
let consumer_err = con.peek_error().unwrap().clone(); | ||
|
||
match pipe(&mut pro, &mut con) { | ||
Ok(()) => { | ||
assert!(pro.did_already_emit_last()); | ||
assert_eq!(con.consumed(), &items[..]); | ||
assert_eq!(con.final_consumed(), Some(&last.unwrap())); | ||
} | ||
Err(PipeError::Consumer(err)) => { | ||
if pro.peek_last().is_none() && last.is_err() { | ||
panic!(); | ||
} | ||
assert!(con.did_error()); | ||
assert_eq!(err, consumer_err); | ||
assert_eq!(con.consumed(), &items[..con.consumed().len()]); | ||
assert_eq!(pro.remaining(), &items[con.consumed().len() + if pro.did_already_emit_last() { 0 } else { 1 } ..]); // TODO | ||
} | ||
Err(PipeError::Producer(err)) => { | ||
assert!(pro.did_already_emit_last()); | ||
assert!(!con.did_error()); | ||
assert_eq!(err, last.unwrap_err()); | ||
assert_eq!(con.consumed(), &items[..con.consumed().len()]); | ||
assert_eq!(pro.remaining(), &items[con.consumed().len()..]); | ||
} | ||
} | ||
} | ||
); |