mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-25 06:55:32 +01:00
tests: Add fuzzing harness for functions/classes in random.h
This commit is contained in:
31
src/test/fuzz/random.cpp
Normal file
31
src/test/fuzz/random.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <random.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
FastRandomContext fast_random_context{ConsumeUInt256(fuzzed_data_provider)};
|
||||
(void)fast_random_context.rand64();
|
||||
(void)fast_random_context.randbits(fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 64));
|
||||
(void)fast_random_context.randrange(fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(FastRandomContext::min() + 1, FastRandomContext::max()));
|
||||
(void)fast_random_context.randbytes(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 1024));
|
||||
(void)fast_random_context.rand32();
|
||||
(void)fast_random_context.rand256();
|
||||
(void)fast_random_context.randbool();
|
||||
(void)fast_random_context();
|
||||
|
||||
std::vector<int64_t> integrals = ConsumeRandomLengthIntegralVector<int64_t>(fuzzed_data_provider);
|
||||
Shuffle(integrals.begin(), integrals.end(), fast_random_context);
|
||||
std::shuffle(integrals.begin(), integrals.end(), fast_random_context);
|
||||
}
|
||||
Reference in New Issue
Block a user