|
12 | 12 | #include <map>
|
13 | 13 | #include <numeric>
|
14 | 14 |
|
15 |
| -using node::MakeMinisketch32; |
| 15 | +namespace { |
| 16 | + |
| 17 | +Minisketch MakeFuzzMinisketch32(size_t capacity, uint32_t impl) |
| 18 | +{ |
| 19 | + return Assert(Minisketch(32, impl, capacity)); |
| 20 | +} |
| 21 | + |
| 22 | +} // namespace |
16 | 23 |
|
17 | 24 | FUZZ_TARGET(minisketch)
|
18 | 25 | {
|
19 | 26 | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
| 27 | + |
20 | 28 | const auto capacity{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 200)};
|
21 |
| - Minisketch sketch_a{Assert(MakeMinisketch32(capacity))}; |
22 |
| - Minisketch sketch_b{Assert(MakeMinisketch32(capacity))}; |
| 29 | + const uint32_t impl{fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, Minisketch::MaxImplementation())}; |
| 30 | + if (!Minisketch::ImplementationSupported(32, impl)) return; |
| 31 | + |
| 32 | + Minisketch sketch_a{MakeFuzzMinisketch32(capacity, impl)}; |
| 33 | + Minisketch sketch_b{MakeFuzzMinisketch32(capacity, impl)}; |
| 34 | + sketch_a.SetSeed(fuzzed_data_provider.ConsumeIntegral<uint64_t>()); |
| 35 | + sketch_b.SetSeed(fuzzed_data_provider.ConsumeIntegral<uint64_t>()); |
23 | 36 |
|
24 | 37 | // Fill two sets and keep the difference in a map
|
25 | 38 | std::map<uint32_t, bool> diff;
|
@@ -47,8 +60,11 @@ FUZZ_TARGET(minisketch)
|
47 | 60 | }
|
48 | 61 | const auto num_diff{std::accumulate(diff.begin(), diff.end(), size_t{0}, [](auto n, const auto& e) { return n + e.second; })};
|
49 | 62 |
|
50 |
| - Minisketch sketch_ar{MakeMinisketch32(capacity)}; |
51 |
| - Minisketch sketch_br{MakeMinisketch32(capacity)}; |
| 63 | + Minisketch sketch_ar{MakeFuzzMinisketch32(capacity, impl)}; |
| 64 | + Minisketch sketch_br{MakeFuzzMinisketch32(capacity, impl)}; |
| 65 | + sketch_ar.SetSeed(fuzzed_data_provider.ConsumeIntegral<uint64_t>()); |
| 66 | + sketch_br.SetSeed(fuzzed_data_provider.ConsumeIntegral<uint64_t>()); |
| 67 | + |
52 | 68 | sketch_ar.Deserialize(sketch_a.Serialize());
|
53 | 69 | sketch_br.Deserialize(sketch_b.Serialize());
|
54 | 70 |
|
|
0 commit comments