Skip to content

Commit a015529

Browse files
authored
Merge pull request #321 from Dr-Emann/push-npzxvmvqlorl
Add fuzzing to compare against croaring-rs
2 parents 9496afe + 9ba4f8f commit a015529

File tree

9 files changed

+832
-21
lines changed

9 files changed

+832
-21
lines changed

.github/workflows/test.yml

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
toolchain: ${{ matrix.rust }}
3434
components: rustfmt, clippy
3535

36+
- name: Caching
37+
uses: Swatinem/rust-cache@v2
38+
3639
- name: Check
3740
# clippy will also do a build check
3841
# so we don't need to run `cargo check` or `cargo build`
@@ -68,11 +71,21 @@ jobs:
6871
features: simd
6972
env:
7073
RUSTFLAGS: "-C target-cpu=native -C opt-level=3"
74+
ROARINGRS_BENCH_OFFLINE: "true"
7175

7276
steps:
7377
- name: Checkout roaring-rs
7478
uses: actions/checkout@v4
7579

80+
- name: Checkout benchmark datasets
81+
uses: actions/checkout@v4
82+
with:
83+
repository: "RoaringBitmap/real-roaring-datasets"
84+
path: "benchmarks/real-roaring-datasets"
85+
86+
- name: Caching
87+
uses: Swatinem/rust-cache@v2
88+
7689
- name: Initialize rust toolchain
7790
uses: dtolnay/rust-toolchain@master
7891
with:
@@ -82,6 +95,10 @@ jobs:
8295
if: matrix.features == 'default'
8396
run: cargo test -p roaring --features serde
8497

98+
- name: Test Benches
99+
if: matrix.rust != '1.71.1' && matrix.features == 'default'
100+
run: cargo test -p benchmarks --benches
101+
85102
- name: Test no default features
86103
if: matrix.features == 'no-std'
87104
run: cargo test -p roaring --no-default-features
@@ -107,43 +124,43 @@ jobs:
107124
toolchain: nightly
108125
components: miri
109126

127+
- name: Caching
128+
uses: Swatinem/rust-cache@v2
129+
110130
- name: Setup miri
111131
run: cargo miri setup
112132

113133
- name: Test bit endian
114134
run: cargo miri test --target s390x-unknown-linux-gnu -p roaring --lib -- bitmap::serialization::test::test_from_lsb0_bytes
115135

116-
bench:
136+
fuzz:
117137
runs-on: ubuntu-latest
118138
needs: build
119-
strategy:
120-
matrix:
121-
rust:
122-
- stable
123-
- nightly
124-
features:
125-
- default
126-
include:
127-
- rust: nightly
128-
features: simd
129139
env:
130140
RUSTFLAGS: "-C target-cpu=native -C opt-level=3"
131-
ROARINGRS_BENCH_OFFLINE: "true"
132141

133142
steps:
134143
- name: Checkout roaring-rs
135144
uses: actions/checkout@v4
136145

137-
- name: Checkout benchmark datasets
138-
uses: actions/checkout@v4
139-
with:
140-
repository: "RoaringBitmap/real-roaring-datasets"
141-
path: "benchmarks/real-roaring-datasets"
142-
143146
- name: Initialize rust toolchain
144147
uses: dtolnay/rust-toolchain@master
145148
with:
146-
toolchain: ${{ matrix.rust }}
149+
toolchain: nightly
150+
151+
- name: Caching
152+
uses: Swatinem/rust-cache@v2
153+
154+
- name: Install cargo fuzz
155+
run: cargo install cargo-fuzz
156+
157+
- name: Setup Cache for corpus and artifacts
158+
uses: actions/cache@v4
159+
with:
160+
key: always
161+
path: |
162+
fuzz/artifacts
163+
fuzz/corpus
147164
148-
- name: Bench
149-
run: cargo bench --features "${{ matrix.features }}"
165+
- name: Run Fuzzer vs croaring for 30 minutes
166+
run: cargo fuzz run against_croaring -s none -- -timeout=5 -max_total_time=1800

fuzz/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
corpus
3+
artifacts
4+
coverage

fuzz/Cargo.lock

Lines changed: 196 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzz/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "roaring-fuzz"
3+
version = "0.0.0"
4+
publish = false
5+
edition = "2021"
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
libfuzzer-sys = { version = "0.4.9", features = ["arbitrary-derive"] }
12+
roaring = { path = "../roaring" }
13+
croaring = "2.0"
14+
15+
[[bin]]
16+
name = "against_croaring"
17+
path = "fuzz_targets/against_croaring.rs"
18+
test = false
19+
doc = false
20+
bench = false
21+
22+
[workspace]

fuzz/fuzz_targets/against_croaring.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![no_main]
2+
3+
mod arbitrary_ops;
4+
5+
use libfuzzer_sys::arbitrary::{self, Arbitrary};
6+
use libfuzzer_sys::fuzz_target;
7+
8+
use crate::arbitrary_ops::{check_equal, Operation};
9+
10+
#[derive(Arbitrary, Debug)]
11+
struct FuzzInput<'a> {
12+
ops: Vec<Operation>,
13+
initial_input: &'a [u8],
14+
}
15+
16+
fuzz_target!(|input: FuzzInput| {
17+
let lhs_c = croaring::Bitmap::try_deserialize::<croaring::Portable>(input.initial_input);
18+
let lhs_r = roaring::RoaringBitmap::deserialize_from(input.initial_input).ok();
19+
20+
let (mut lhs_c, mut lhs_r) = match (lhs_c, lhs_r) {
21+
(Some(lhs_c), Some(lhs_r)) => {
22+
check_equal(&lhs_c, &lhs_r);
23+
(lhs_c, lhs_r)
24+
}
25+
(None, None) => Default::default(),
26+
(Some(_), None) => panic!("croaring deserialized, but roaring failed"),
27+
(None, Some(_)) => panic!("roaring deserialized, but croaring failed"),
28+
};
29+
30+
let mut rhs_c = croaring::Bitmap::new();
31+
let mut rhs_r = roaring::RoaringBitmap::new();
32+
33+
for op in input.ops {
34+
op.apply(&mut lhs_c, &mut rhs_c, &mut lhs_r, &mut rhs_r);
35+
}
36+
check_equal(&lhs_c, &lhs_r);
37+
check_equal(&rhs_c, &rhs_r);
38+
});

0 commit comments

Comments
 (0)