-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfastpfor_u64.rs
More file actions
59 lines (50 loc) · 1.65 KB
/
Copy pathfastpfor_u64.rs
File metadata and controls
59 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![no_main]
use fastpfor::cpp::{CppFastPFor128, CppFastPFor256};
use fastpfor::{BlockCodec64, FastPFor128, FastPFor256};
use libfuzzer_sys::fuzz_target;
#[derive(arbitrary::Arbitrary, Debug)]
struct Input {
data: Vec<u64>,
use_256: bool,
}
fn check(rust: &mut impl BlockCodec64, cpp: &mut impl BlockCodec64, data: &[u64], name: &str) {
let mut rust_enc = Vec::new();
rust.encode64(data, &mut rust_enc)
.expect("Rust encode64 failed");
let mut cpp_enc = Vec::new();
cpp.encode64(data, &mut cpp_enc)
.expect("C++ encode64 failed");
assert_eq!(
rust_enc, cpp_enc,
"{name}: Rust and C++ encode64 bytes differ"
);
let mut rust_dec = Vec::new();
rust.decode64(&rust_enc, &mut rust_dec)
.expect("Rust decode64 of own output failed");
assert_eq!(rust_dec, data, "{name}: Rust roundtrip mismatch");
let mut cross = Vec::new();
rust.decode64(&cpp_enc, &mut cross)
.expect("Rust decode64 of C++ output failed");
assert_eq!(cross, data, "{name}: Rust could not decode C++ output");
let mut cpp_dec = Vec::new();
cpp.decode64(&rust_enc, &mut cpp_dec)
.expect("C++ decode64 of Rust output failed");
assert_eq!(cpp_dec, data, "{name}: C++ could not decode Rust output");
}
fuzz_target!(|input: Input| {
if input.use_256 {
check(
&mut FastPFor256::default(),
&mut CppFastPFor256::default(),
&input.data,
"FastPFor256",
);
} else {
check(
&mut FastPFor128::default(),
&mut CppFastPFor128::default(),
&input.data,
"FastPFor128",
);
}
});