aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/fuzz.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/fuzz/fuzz.h')
-rw-r--r--src/test/fuzz/fuzz.h25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/test/fuzz/fuzz.h b/src/test/fuzz/fuzz.h
index 3be202b16e..544379c0b0 100644
--- a/src/test/fuzz/fuzz.h
+++ b/src/test/fuzz/fuzz.h
@@ -5,10 +5,29 @@
#ifndef BITCOIN_TEST_FUZZ_FUZZ_H
#define BITCOIN_TEST_FUZZ_FUZZ_H
-#include <stdint.h>
+#include <cstdint>
+#include <functional>
+#include <string_view>
#include <vector>
-void initialize();
-void test_one_input(const std::vector<uint8_t>& buffer);
+using TypeTestOneInput = std::function<void(const std::vector<uint8_t>&)>;
+using TypeInitialize = std::function<void()>;
+
+void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, TypeInitialize init);
+
+void FuzzFrameworkEmptyFun() {}
+
+#define FUZZ_TARGET(name) \
+ FUZZ_TARGET_INIT(name, FuzzFrameworkEmptyFun)
+
+#define FUZZ_TARGET_INIT(name, init_fun) \
+ void name##_fuzz_target(const std::vector<uint8_t>&); \
+ struct name##_Before_Main { \
+ name##_Before_Main() \
+ { \
+ FuzzFrameworkRegisterTarget(#name, name##_fuzz_target, init_fun); \
+ } \
+ } const static g_##name##_before_main; \
+ void name##_fuzz_target(const std::vector<uint8_t>& buffer)
#endif // BITCOIN_TEST_FUZZ_FUZZ_H