From 2222f7a87404078984c7189768a3422deb114302 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 29 Aug 2024 09:48:34 +0200 Subject: [PATCH] test: Rename SeedRand::SEED to FIXED_SEED for clarity --- src/test/util/random.cpp | 2 +- src/test/util/random.h | 12 ++++++++++-- src/test/util/setup_common.cpp | 2 +- src/test/util/setup_common.h | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/test/util/random.cpp b/src/test/util/random.cpp index b568f275a52..32d785e45d9 100644 --- a/src/test/util/random.cpp +++ b/src/test/util/random.cpp @@ -36,7 +36,7 @@ void SeedRandomStateForTest(SeedRand seedtype) return GetRandHash(); }(); - const uint256& seed{seedtype == SeedRand::SEED ? ctx_seed : uint256::ZERO}; + const uint256& seed{seedtype == SeedRand::FIXED_SEED ? ctx_seed : uint256::ZERO}; LogInfo("Setting random seed for current tests to %s=%s\n", RANDOM_CTX_SEED, seed.GetHex()); MakeRandDeterministicDANGEROUS(seed); } diff --git a/src/test/util/random.h b/src/test/util/random.h index c458534d48e..441150e666e 100644 --- a/src/test/util/random.h +++ b/src/test/util/random.h @@ -12,8 +12,16 @@ #include enum class SeedRand { - ZEROS, //!< Seed with a compile time constant of zeros - SEED, //!< Use (and report) random seed from environment, or a (truly) random one. + /** + * Seed with a compile time constant of zeros. + */ + ZEROS, + /** + * Seed with a fixed value that never changes over the lifetime of this + * process. The seed is read from the RANDOM_CTX_SEED environment variable + * if set, otherwise generated randomly once, saved, and reused. + */ + FIXED_SEED, }; /** Seed the global RNG state for testing and log the seed value. This affects all randomness, except GetStrongRandBytes(). */ diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index dcf72cf6272..cffc1273f06 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -154,7 +154,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts) // Use randomly chosen seed for deterministic PRNG, so that (by default) test // data directories use a random name that doesn't overlap with other tests. - SeedRandomForTest(SeedRand::SEED); + SeedRandomForTest(SeedRand::FIXED_SEED); if (!m_node.args->IsArgSet("-testdatadir")) { // By default, the data directory has a random name diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index d995549ca68..a9a890b1a56 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -68,7 +68,7 @@ struct BasicTestingSetup { FastRandomContext m_rng; /** Seed the global RNG state and m_rng for testing and log the seed value. This affects all randomness, except GetStrongRandBytes(). */ - void SeedRandomForTest(SeedRand seed = SeedRand::SEED) + void SeedRandomForTest(SeedRand seed) { SeedRandomStateForTest(seed); m_rng.Reseed(GetRandHash());