LCOV - code coverage report
Current view: top level - src/test/util - random.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 1 13 7.7 %
Date: 2024-01-03 14:57:27 Functions: 0 3 0.0 %
Branches: 0 14 0.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2023 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/util/random.h>
       6                 :            : 
       7                 :            : #include <logging.h>
       8                 :            : #include <random.h>
       9                 :            : #include <uint256.h>
      10                 :            : 
      11                 :            : #include <cstdlib>
      12                 :            : #include <string>
      13                 :            : 
      14                 :          2 : FastRandomContext g_insecure_rand_ctx;
      15                 :            : 
      16                 :            : /** Return the unsigned from the environment var if available, otherwise 0 */
      17                 :          0 : static uint256 GetUintFromEnv(const std::string& env_name)
      18                 :            : {
      19                 :          0 :     const char* num = std::getenv(env_name.c_str());
      20         [ #  # ]:          0 :     if (!num) return {};
      21                 :          0 :     return uint256S(num);
      22                 :          0 : }
      23                 :            : 
      24                 :          0 : void Seed(FastRandomContext& ctx)
      25                 :            : {
      26                 :            :     // Should be enough to get the seed once for the process
      27                 :            :     static uint256 seed{};
      28                 :            :     static const std::string RANDOM_CTX_SEED{"RANDOM_CTX_SEED"};
      29         [ #  # ]:          0 :     if (seed.IsNull()) seed = GetUintFromEnv(RANDOM_CTX_SEED);
      30         [ #  # ]:          0 :     if (seed.IsNull()) seed = GetRandHash();
      31 [ #  # ][ #  # ]:          0 :     LogPrintf("%s: Setting random seed for current tests to %s=%s\n", __func__, RANDOM_CTX_SEED, seed.GetHex());
         [ #  # ][ #  # ]
      32                 :          0 :     ctx = FastRandomContext(seed);
      33                 :          0 : }

Generated by: LCOV version 1.14