LCOV - code coverage report
Current view: top level - src/test/fuzz - cuckoocache.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 3 22 13.6 %
Date: 2023-09-26 12:08:55 Functions: 3 12 25.0 %

          Line data    Source code
       1             : // Copyright (c) 2020-2021 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <cuckoocache.h>
       6             : #include <script/sigcache.h>
       7             : #include <test/fuzz/FuzzedDataProvider.h>
       8             : #include <test/fuzz/fuzz.h>
       9             : #include <test/fuzz/util.h>
      10             : #include <test/util/setup_common.h>
      11             : 
      12             : #include <cstdint>
      13             : #include <string>
      14             : #include <vector>
      15             : 
      16             : namespace {
      17             : FuzzedDataProvider* fuzzed_data_provider_ptr = nullptr;
      18             : 
      19             : struct RandomHasher {
      20             :     template <uint8_t>
      21           0 :     uint32_t operator()(const bool& /* unused */) const
      22             :     {
      23           0 :         assert(fuzzed_data_provider_ptr != nullptr);
      24           0 :         return fuzzed_data_provider_ptr->ConsumeIntegral<uint32_t>();
      25           2 :     }
      26             : };
      27             : } // namespace
      28             : 
      29           4 : FUZZ_TARGET(cuckoocache)
      30             : {
      31           0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      32           0 :     fuzzed_data_provider_ptr = &fuzzed_data_provider;
      33           0 :     CuckooCache::cache<int, RandomHasher> cuckoo_cache{};
      34           0 :     if (fuzzed_data_provider.ConsumeBool()) {
      35           0 :         const size_t megabytes = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 16);
      36           0 :         cuckoo_cache.setup_bytes(megabytes << 20);
      37           0 :     } else {
      38           0 :         cuckoo_cache.setup(fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, 4096));
      39             :     }
      40           0 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
      41           0 :         if (fuzzed_data_provider.ConsumeBool()) {
      42           0 :             cuckoo_cache.insert(fuzzed_data_provider.ConsumeBool());
      43           0 :         } else {
      44           0 :             cuckoo_cache.contains(fuzzed_data_provider.ConsumeBool(), fuzzed_data_provider.ConsumeBool());
      45             :         }
      46           0 :     }
      47           0 :     fuzzed_data_provider_ptr = nullptr;
      48           0 : }

Generated by: LCOV version 1.14