Skip to content

Commit aae111e

Browse files
committed
Better document msg fuzz target behavior and be slightly more strict
1 parent 9206ae7 commit aae111e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

fuzz/src/msg_targets/utils.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ impl Writer for VecWriter {
1313
}
1414
}
1515

16+
// Tests a message that must survive roundtrip exactly, though may not empty the read buffer
17+
// entirely
1618
#[macro_export]
1719
macro_rules! test_msg {
1820
($MsgType: path, $data: ident) => {
@@ -31,6 +33,8 @@ macro_rules! test_msg {
3133
}
3234
}
3335

36+
// Tests a message that may lose data on roundtrip, but shoulnd't lose data compared to our
37+
// re-serialization.
3438
#[macro_export]
3539
macro_rules! test_msg_simple {
3640
($MsgType: path, $data: ident) => {
@@ -40,11 +44,18 @@ macro_rules! test_msg_simple {
4044
if let Ok(msg) = <$MsgType as Readable<::std::io::Cursor<&[u8]>>>::read(&mut r) {
4145
let mut w = VecWriter(Vec::new());
4246
msg.write(&mut w).unwrap();
47+
48+
let msg = <$MsgType as Readable<::std::io::Cursor<&[u8]>>>::read(&mut ::std::io::Cursor::new(&w.0)).unwrap();
49+
let mut w_two = VecWriter(Vec::new());
50+
msg.write(&mut w_two).unwrap();
51+
assert_eq!(&w.0[..], &w_two.0[..]);
4352
}
4453
}
4554
}
4655
}
4756

57+
// Tests a message that must survive roundtrip exactly, and must exactly empty the read buffer and
58+
// split it back out on re-serialization.
4859
#[macro_export]
4960
macro_rules! test_msg_exact {
5061
($MsgType: path, $data: ident) => {
@@ -54,13 +65,14 @@ macro_rules! test_msg_exact {
5465
if let Ok(msg) = <$MsgType as Readable<::std::io::Cursor<&[u8]>>>::read(&mut r) {
5566
let mut w = VecWriter(Vec::new());
5667
msg.write(&mut w).unwrap();
57-
5868
assert_eq!(&r.into_inner()[..], &w.0[..]);
5969
}
6070
}
6171
}
6272
}
6373

74+
// Tests a message that must survive roundtrip exactly, modulo one "hole" which may be set to 0s on
75+
// re-serialization.
6476
#[macro_export]
6577
macro_rules! test_msg_hole {
6678
($MsgType: path, $data: ident, $hole: expr, $hole_len: expr) => {

0 commit comments

Comments
 (0)