aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/fuzz.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/fuzz/fuzz.cpp')
-rw-r--r--src/test/fuzz/fuzz.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp
index c1c9945a04..bba2dd8e3a 100644
--- a/src/test/fuzz/fuzz.cpp
+++ b/src/test/fuzz/fuzz.cpp
@@ -6,6 +6,7 @@
#include <netaddress.h>
#include <netbase.h>
+#include <test/util/random.h>
#include <test/util/setup_common.h>
#include <util/check.h>
#include <util/fs.h>
@@ -48,7 +49,7 @@ static std::vector<const char*> g_args;
static void SetArgs(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
// Only take into account arguments that start with `--`. The others are for the fuzz engine:
- // `fuzz -runs=1 fuzz_seed_corpus/address_deserialize_v2 --checkaddrman=5`
+ // `fuzz -runs=1 fuzz_corpora/address_deserialize_v2 --checkaddrman=5`
if (strlen(argv[i]) > 2 && argv[i][0] == '-' && argv[i][1] == '-') {
g_args.push_back(argv[i]);
}
@@ -72,8 +73,8 @@ auto& FuzzTargets()
void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, FuzzTargetOptions opts)
{
- const auto it_ins{FuzzTargets().try_emplace(name, FuzzTarget /* temporary can be dropped after clang-16 */ {std::move(target), std::move(opts)})};
- Assert(it_ins.second);
+ const auto [it, ins]{FuzzTargets().try_emplace(name, FuzzTarget /* temporary can be dropped after Apple-Clang-16 ? */ {std::move(target), std::move(opts)})};
+ Assert(ins);
}
static std::string_view g_fuzz_target;
@@ -101,6 +102,12 @@ void ResetCoverageCounters() {}
void initialize()
{
+ // By default, make the RNG deterministic with a fixed seed. This will affect all
+ // randomness during the fuzz test, except:
+ // - GetStrongRandBytes(), which is used for the creation of private key material.
+ // - Creating a BasicTestingSetup or derived class will switch to a random seed.
+ SeedRandomStateForTest(SeedRand::ZEROS);
+
// Terminate immediately if a fuzzing harness ever tries to create a socket.
// Individual tests can override this by pointing CreateSock to a mocked alternative.
CreateSock = [](int, int, int) -> std::unique_ptr<Sock> { std::terminate(); };