2021-01-25 12:23:45 +01:00
|
|
|
// Copyright (c) 2009-2021 The Bitcoin Core developers
|
2019-01-25 18:35:36 -05:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_TEST_FUZZ_FUZZ_H
|
|
|
|
#define BITCOIN_TEST_FUZZ_FUZZ_H
|
|
|
|
|
2021-01-02 19:29:36 +01:00
|
|
|
#include <span.h>
|
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
#include <cstdint>
|
|
|
|
#include <functional>
|
|
|
|
#include <string_view>
|
2019-01-25 18:35:36 -05:00
|
|
|
|
2021-01-02 19:29:36 +01:00
|
|
|
using FuzzBufferType = Span<const uint8_t>;
|
|
|
|
|
|
|
|
using TypeTestOneInput = std::function<void(FuzzBufferType)>;
|
2020-12-03 16:42:49 +01:00
|
|
|
using TypeInitialize = std::function<void()>;
|
2021-02-08 10:13:08 +01:00
|
|
|
using TypeHidden = bool;
|
2020-12-03 16:42:49 +01:00
|
|
|
|
2021-02-08 10:13:08 +01:00
|
|
|
void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, TypeInitialize init, TypeHidden hidden);
|
2020-12-03 16:42:49 +01:00
|
|
|
|
2021-02-08 10:13:08 +01:00
|
|
|
inline void FuzzFrameworkEmptyInitFun() {}
|
2020-12-03 16:42:49 +01:00
|
|
|
|
|
|
|
#define FUZZ_TARGET(name) \
|
2021-02-08 10:13:08 +01:00
|
|
|
FUZZ_TARGET_INIT(name, FuzzFrameworkEmptyInitFun)
|
|
|
|
|
|
|
|
#define FUZZ_TARGET_INIT(name, init_fun) \
|
|
|
|
FUZZ_TARGET_INIT_HIDDEN(name, init_fun, false)
|
|
|
|
|
|
|
|
#define FUZZ_TARGET_INIT_HIDDEN(name, init_fun, hidden) \
|
|
|
|
void name##_fuzz_target(FuzzBufferType); \
|
|
|
|
struct name##_Before_Main { \
|
|
|
|
name##_Before_Main() \
|
|
|
|
{ \
|
|
|
|
FuzzFrameworkRegisterTarget(#name, name##_fuzz_target, init_fun, hidden); \
|
|
|
|
} \
|
|
|
|
} const static g_##name##_before_main; \
|
2021-01-02 19:29:36 +01:00
|
|
|
void name##_fuzz_target(FuzzBufferType buffer)
|
2019-01-25 18:35:36 -05:00
|
|
|
|
|
|
|
#endif // BITCOIN_TEST_FUZZ_FUZZ_H
|