LCOV - code coverage report
Current view: top level - src/test/fuzz - autofile.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 2 43 4.7 %
Date: 2023-11-10 23:46:46 Functions: 1 9 11.1 %
Branches: 2 38 5.3 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2020-2022 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 <streams.h>
       6                 :            : #include <test/fuzz/FuzzedDataProvider.h>
       7                 :            : #include <test/fuzz/fuzz.h>
       8                 :            : #include <test/fuzz/util.h>
       9                 :            : 
      10                 :            : #include <array>
      11                 :            : #include <cstdint>
      12                 :            : #include <iostream>
      13                 :            : #include <optional>
      14                 :            : #include <string>
      15                 :            : #include <vector>
      16                 :            : 
      17 [ +  - ][ +  - ]:          6 : FUZZ_TARGET(autofile)
      18                 :            : {
      19                 :          0 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      20                 :          0 :     FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
      21                 :          0 :     AutoFile auto_file{fuzzed_auto_file_provider.open()};
      22 [ #  # ][ #  # ]:          0 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
                 [ #  # ]
      23         [ #  # ]:          0 :         CallOneOf(
      24                 :            :             fuzzed_data_provider,
      25                 :          2 :             [&] {
      26                 :          0 :                 std::array<std::byte, 4096> arr{};
      27                 :            :                 try {
      28         [ #  # ]:          0 :                     auto_file.read({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)});
      29         [ #  # ]:          0 :                 } catch (const std::ios_base::failure&) {
      30                 :          0 :                 }
      31                 :          0 :             },
      32                 :          0 :             [&] {
      33                 :          0 :                 const std::array<std::byte, 4096> arr{};
      34                 :            :                 try {
      35         [ #  # ]:          0 :                     auto_file.write({arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096)});
      36         [ #  # ]:          0 :                 } catch (const std::ios_base::failure&) {
      37                 :          0 :                 }
      38                 :          0 :             },
      39                 :          0 :             [&] {
      40                 :            :                 try {
      41         [ #  # ]:          0 :                     auto_file.ignore(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
      42         [ #  # ]:          0 :                 } catch (const std::ios_base::failure&) {
      43                 :          0 :                 }
      44                 :          0 :             },
      45                 :          0 :             [&] {
      46                 :          0 :                 auto_file.fclose();
      47                 :          0 :             },
      48                 :          0 :             [&] {
      49                 :          0 :                 ReadFromStream(fuzzed_data_provider, auto_file);
      50                 :          0 :             },
      51                 :          0 :             [&] {
      52                 :          0 :                 WriteToStream(fuzzed_data_provider, auto_file);
      53                 :          0 :             });
      54                 :          0 :     }
      55         [ #  # ]:          0 :     (void)auto_file.Get();
      56         [ #  # ]:          0 :     (void)auto_file.IsNull();
      57 [ #  # ][ #  # ]:          0 :     if (fuzzed_data_provider.ConsumeBool()) {
      58         [ #  # ]:          0 :         FILE* f = auto_file.release();
      59         [ #  # ]:          0 :         if (f != nullptr) {
      60         [ #  # ]:          0 :             fclose(f);
      61                 :          0 :         }
      62                 :          0 :     }
      63                 :          0 : }

Generated by: LCOV version 1.14