aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/flat_hash/fuzz/dense_map_fuzz/fuzz.cpp
blob: 3d13482a3dc79d59711bd0bdd28b0ef3e7a8da06 (plain) (blame)
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
60
#include <library/cpp/containers/flat_hash/lib/map.h>
#include <library/cpp/containers/flat_hash/lib/containers.h>
#include <library/cpp/containers/flat_hash/lib/probings.h>
#include <library/cpp/containers/flat_hash/lib/size_fitters.h>
#include <library/cpp/containers/flat_hash/lib/expanders.h>

#include <library/cpp/containers/flat_hash/fuzz/fuzz_common/fuzz_common.h>

#include <util/generic/hash.h>
#include <util/generic/xrange.h>
#include <util/generic/bt_exception.h>

using namespace NFlatHash;

namespace {

template <class Key, class T>
using TDenseModMap = NFlatHash::TMap<Key,
                                     T,
                                     THash<Key>,
                                     std::equal_to<Key>,
                                     TRemovalDenseContainer<std::pair<const Key, T>,
                                                            NMap::TEqValueMarker<Key, T>,
                                                            NMap::TEqValueMarker<Key, T>>,
                                     TDenseProbing,
                                     TAndSizeFitter,
                                     TSimpleExpander>;

NFuzz::EActionType EvalType(ui8 data) {
    return static_cast<NFuzz::EActionType>((data >> 5) & 0b111);
}

ui8 EvalKey(ui8 data) {
    return data & 0b11111;
}

ui8 EvalValue() {
    return RandomNumber<ui8>();
}

}  // namespace

#include <util/datetime/base.h>

extern "C" int LLVMFuzzerTestOneInput(const ui8* const wireData, const size_t wireSize) {
    THashMap<ui8, ui8> etalon;
    // We assume, that markers can't be produced by EvalKey function.
    TDenseModMap<ui8, ui8> testee(8,
                                  (1 << 5), // Deleted marker
                                  (1 << 6)); // Empty marker

    for (auto i : xrange(wireSize)) {
        auto data = wireData[i];

        NFuzz::MakeAction(etalon, testee, EvalKey(data), EvalValue(), EvalType(data));
        NFuzz::CheckInvariants(etalon, testee);
    }

    return 0;
}