Merge #20663: fuzz: Hide script_assets_test_minimizer
fac726b1b8doc: Fixup docs in fuzz/script_assets_test_minimizer.cpp (MarcoFalke)fafca47adcfuzz: Hide script_assets_test_minimizer (MarcoFalke) Pull request description: This is not an actual fuzz target. It is a hack to exploit the built-in capability of fuzz engines to measure coverage. ACKs for top commit: practicalswift: cr ACKfac726b1b8: patch looks correct and touches only `src/test/fuzz/` Tree-SHA512: 0652dd8d9e95746b0906be4044467435d8204a34a30366ae9bdb75b9cb0788d429db7cedf2760fd543565d9d4f7ee206873ed10a29dd715a792a26337f65b53c
This commit is contained in:
3 files changed
+24
-19
No files matched your search
@@ -13,15 +13,15 @@
|
|||||||
|
|
||||||
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
||||||
|
|
||||||
std::map<std::string_view, std::tuple<TypeTestOneInput, TypeInitialize>>& FuzzTargets()
|
std::map<std::string_view, std::tuple<TypeTestOneInput, TypeInitialize, TypeHidden>>& FuzzTargets()
|
||||||
{
|
{
|
||||||
static std::map<std::string_view, std::tuple<TypeTestOneInput, TypeInitialize>> g_fuzz_targets;
|
static std::map<std::string_view, std::tuple<TypeTestOneInput, TypeInitialize, TypeHidden>> g_fuzz_targets;
|
||||||
return g_fuzz_targets;
|
return g_fuzz_targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, TypeInitialize init)
|
void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, TypeInitialize init, TypeHidden hidden)
|
||||||
{
|
{
|
||||||
const auto it_ins = FuzzTargets().try_emplace(name, std::move(target), std::move(init));
|
const auto it_ins = FuzzTargets().try_emplace(name, std::move(target), std::move(init), hidden);
|
||||||
Assert(it_ins.second);
|
Assert(it_ins.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ void initialize()
|
|||||||
{
|
{
|
||||||
if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
|
if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
|
||||||
for (const auto& t : FuzzTargets()) {
|
for (const auto& t : FuzzTargets()) {
|
||||||
|
if (std::get<2>(t.second)) continue;
|
||||||
std::cout << t.first << std::endl;
|
std::cout << t.first << std::endl;
|
||||||
}
|
}
|
||||||
Assert(false);
|
Assert(false);
|
||||||
|
|||||||
+15
-11
@@ -15,22 +15,26 @@ using FuzzBufferType = Span<const uint8_t>;
|
|||||||
|
|
||||||
using TypeTestOneInput = std::function<void(FuzzBufferType)>;
|
using TypeTestOneInput = std::function<void(FuzzBufferType)>;
|
||||||
using TypeInitialize = std::function<void()>;
|
using TypeInitialize = std::function<void()>;
|
||||||
|
using TypeHidden = bool;
|
||||||
|
|
||||||
void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, TypeInitialize init);
|
void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, TypeInitialize init, TypeHidden hidden);
|
||||||
|
|
||||||
inline void FuzzFrameworkEmptyFun() {}
|
inline void FuzzFrameworkEmptyInitFun() {}
|
||||||
|
|
||||||
#define FUZZ_TARGET(name) \
|
#define FUZZ_TARGET(name) \
|
||||||
FUZZ_TARGET_INIT(name, FuzzFrameworkEmptyFun)
|
FUZZ_TARGET_INIT(name, FuzzFrameworkEmptyInitFun)
|
||||||
|
|
||||||
#define FUZZ_TARGET_INIT(name, init_fun) \
|
#define FUZZ_TARGET_INIT(name, init_fun) \
|
||||||
void name##_fuzz_target(FuzzBufferType); \
|
FUZZ_TARGET_INIT_HIDDEN(name, init_fun, false)
|
||||||
struct name##_Before_Main { \
|
|
||||||
name##_Before_Main() \
|
#define FUZZ_TARGET_INIT_HIDDEN(name, init_fun, hidden) \
|
||||||
{ \
|
void name##_fuzz_target(FuzzBufferType); \
|
||||||
FuzzFrameworkRegisterTarget(#name, name##_fuzz_target, init_fun); \
|
struct name##_Before_Main { \
|
||||||
} \
|
name##_Before_Main() \
|
||||||
} const static g_##name##_before_main; \
|
{ \
|
||||||
|
FuzzFrameworkRegisterTarget(#name, name##_fuzz_target, init_fun, hidden); \
|
||||||
|
} \
|
||||||
|
} const static g_##name##_before_main; \
|
||||||
void name##_fuzz_target(FuzzBufferType buffer)
|
void name##_fuzz_target(FuzzBufferType buffer)
|
||||||
|
|
||||||
#endif // BITCOIN_TEST_FUZZ_FUZZ_H
|
#endif // BITCOIN_TEST_FUZZ_FUZZ_H
|
||||||
@@ -28,12 +28,12 @@
|
|||||||
//
|
//
|
||||||
// (normal build)
|
// (normal build)
|
||||||
// $ mkdir dump
|
// $ mkdir dump
|
||||||
// $ for N in $(seq 1 10); do TEST_DUMP_DIR=dump test/functional/feature_taproot --dumptests; done
|
// $ for N in $(seq 1 10); do TEST_DUMP_DIR=dump test/functional/feature_taproot.py --dumptests; done
|
||||||
// $ ...
|
// $ ...
|
||||||
//
|
//
|
||||||
// (fuzz test build)
|
// (libFuzzer build)
|
||||||
// $ mkdir dump-min
|
// $ mkdir dump-min
|
||||||
// $ ./src/test/fuzz/script_assets_test_minimizer -merge=1 dump-min/ dump/
|
// $ FUZZ=script_assets_test_minimizer ./src/test/fuzz/fuzz -merge=1 -use_value_profile=1 dump-min/ dump/
|
||||||
// $ (echo -en '[\n'; cat dump-min/* | head -c -2; echo -en '\n]') >script_assets_test.json
|
// $ (echo -en '[\n'; cat dump-min/* | head -c -2; echo -en '\n]') >script_assets_test.json
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -190,7 +190,7 @@ ECCVerifyHandle handle;
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
FUZZ_TARGET(script_assets_test_minimizer)
|
FUZZ_TARGET_INIT_HIDDEN(script_assets_test_minimizer, FuzzFrameworkEmptyInitFun, /* hidden */ true)
|
||||||
{
|
{
|
||||||
if (buffer.size() < 2 || buffer.back() != '\n' || buffer[buffer.size() - 2] != ',') return;
|
if (buffer.size() < 2 || buffer.back() != '\n' || buffer[buffer.size() - 2] != ',') return;
|
||||||
const std::string str((const char*)buffer.data(), buffer.size() - 2);
|
const std::string str((const char*)buffer.data(), buffer.size() - 2);
|
||||||
|
|||||||
Reference in new issue
Block a user