LCOV - code coverage report
Current view: top level - src/test/fuzz - timedata.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 2 13 15.4 %
Date: 2023-10-05 12:38:51 Functions: 2 3 66.7 %
Branches: 2 32 6.2 %

           Branch data     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 <test/fuzz/FuzzedDataProvider.h>
       6                 :            : #include <test/fuzz/fuzz.h>
       7                 :            : #include <test/fuzz/util.h>
       8                 :            : #include <timedata.h>
       9                 :            : 
      10                 :            : #include <cstdint>
      11                 :            : #include <string>
      12                 :            : #include <vector>
      13                 :            : 
      14         [ -  + ]:          4 : FUZZ_TARGET(timedata)
      15                 :            : {
      16                 :          0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      17                 :          0 :     const unsigned int max_size = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1000);
      18                 :            :     // A max_size of 0 implies no limit, so cap the max number of insertions to avoid timeouts
      19                 :          0 :     auto max_to_insert = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 4000);
      20                 :            :     // Divide by 2 to avoid signed integer overflow in .median()
      21                 :          0 :     const int64_t initial_value = fuzzed_data_provider.ConsumeIntegral<int64_t>() / 2;
      22                 :          0 :     CMedianFilter<int64_t> median_filter{max_size, initial_value};
      23   [ #  #  #  #  :          0 :     while (fuzzed_data_provider.remaining_bytes() > 0 && --max_to_insert >= 0) {
                   #  # ]
      24         [ #  # ]:          0 :         (void)median_filter.median();
      25   [ +  -  #  #  :          2 :         assert(median_filter.size() > 0);
                   #  # ]
      26   [ #  #  #  #  :          0 :         assert(static_cast<size_t>(median_filter.size()) == median_filter.sorted().size());
                   #  # ]
      27   [ #  #  #  #  :          0 :         assert(static_cast<unsigned int>(median_filter.size()) <= max_size || max_size == 0);
                   #  # ]
      28                 :            :         // Divide by 2 to avoid signed integer overflow in .median()
      29   [ #  #  #  # ]:          0 :         median_filter.input(fuzzed_data_provider.ConsumeIntegral<int64_t>() / 2);
      30                 :            :     }
      31                 :          0 : }

Generated by: LCOV version 1.14