LCOV - code coverage report
Current view: top level - src/test/util - random.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 13 14 92.9 %
Date: 2023-10-05 15:40:34 Functions: 4 4 100.0 %
Branches: 13 20 65.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                 :        173 : FastRandomContext g_insecure_rand_ctx;
      15                 :            : 
      16                 :            : /** Return the unsigned from the environment var if available, otherwise 0 */
      17                 :         71 : static uint256 GetUintFromEnv(const std::string& env_name)
      18                 :            : {
      19                 :         71 :     const char* num = std::getenv(env_name.c_str());
      20         [ +  - ]:         71 :     if (!num) return {};
      21                 :          0 :     return uint256S(num);
      22                 :         71 : }
      23                 :            : 
      24                 :        889 : void Seed(FastRandomContext& ctx)
      25                 :            : {
      26                 :            :     // Should be enough to get the seed once for the process
      27                 :            :     static uint256 seed{};
      28   [ +  +  -  +  :        889 :     static const std::string RANDOM_CTX_SEED{"RANDOM_CTX_SEED"};
                   +  - ]
      29         [ +  + ]:        889 :     if (seed.IsNull()) seed = GetUintFromEnv(RANDOM_CTX_SEED);
      30         [ +  + ]:        889 :     if (seed.IsNull()) seed = GetRandHash();
      31   [ +  -  +  -  :        889 :     LogPrintf("%s: Setting random seed for current tests to %s=%s\n", __func__, RANDOM_CTX_SEED, seed.GetHex());
             +  -  +  - ]
      32                 :        889 :     ctx = FastRandomContext(seed);
      33                 :        889 : }

Generated by: LCOV version 1.14