@@ -54,20 +54,25 @@ const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS =
54
54
return g_args;
55
55
};
56
56
57
- std::map<std::string_view, std::tuple<TypeTestOneInput, TypeInitialize, TypeHidden>>& FuzzTargets ()
57
+ struct FuzzTarget {
58
+ const TypeTestOneInput test_one_input;
59
+ const FuzzTargetOptions opts;
60
+ };
61
+
62
+ auto & FuzzTargets ()
58
63
{
59
- static std::map<std::string_view, std::tuple<TypeTestOneInput, TypeInitialize, TypeHidden> > g_fuzz_targets;
64
+ static std::map<std::string_view, FuzzTarget > g_fuzz_targets;
60
65
return g_fuzz_targets;
61
66
}
62
67
63
- void FuzzFrameworkRegisterTarget (std::string_view name, TypeTestOneInput target, TypeInitialize init, TypeHidden hidden )
68
+ void FuzzFrameworkRegisterTarget (std::string_view name, TypeTestOneInput target, FuzzTargetOptions opts )
64
69
{
65
- const auto it_ins = FuzzTargets ().try_emplace (name, std::move (target), std::move (init), hidden) ;
70
+ const auto it_ins{ FuzzTargets ().try_emplace (name, FuzzTarget /* temporary can be dropped in C++20 */ { std::move (target), std::move (opts)})} ;
66
71
Assert (it_ins.second );
67
72
}
68
73
69
74
static std::string_view g_fuzz_target;
70
- static TypeTestOneInput* g_test_one_input{nullptr };
75
+ static const TypeTestOneInput* g_test_one_input{nullptr };
71
76
72
77
void initialize ()
73
78
{
@@ -84,22 +89,22 @@ void initialize()
84
89
85
90
bool should_exit{false };
86
91
if (std::getenv (" PRINT_ALL_FUZZ_TARGETS_AND_ABORT" )) {
87
- for (const auto & t : FuzzTargets ()) {
88
- if (std::get< 2 >(t. second ) ) continue ;
89
- std::cout << t. first << std::endl;
92
+ for (const auto & [name, t] : FuzzTargets ()) {
93
+ if (t. opts . hidden ) continue ;
94
+ std::cout << name << std::endl;
90
95
}
91
96
should_exit = true ;
92
97
}
93
98
if (const char * out_path = std::getenv (" WRITE_ALL_FUZZ_TARGETS_AND_ABORT" )) {
94
99
std::cout << " Writing all fuzz target names to '" << out_path << " '." << std::endl;
95
100
std::ofstream out_stream{out_path, std::ios::binary};
96
- for (const auto & t : FuzzTargets ()) {
97
- if (std::get< 2 >(t. second ) ) continue ;
98
- out_stream << t. first << std::endl;
101
+ for (const auto & [name, t] : FuzzTargets ()) {
102
+ if (t. opts . hidden ) continue ;
103
+ out_stream << name << std::endl;
99
104
}
100
- should_exit= true ;
105
+ should_exit = true ;
101
106
}
102
- if (should_exit){
107
+ if (should_exit) {
103
108
std::exit (EXIT_SUCCESS);
104
109
}
105
110
if (const auto * env_fuzz{std::getenv (" FUZZ" )}) {
@@ -117,8 +122,8 @@ void initialize()
117
122
std::exit (EXIT_FAILURE);
118
123
}
119
124
Assert (!g_test_one_input);
120
- g_test_one_input = &std::get< 0 >( it->second ) ;
121
- std::get< 1 >( it->second ) ();
125
+ g_test_one_input = &it->second . test_one_input ;
126
+ it->second . opts . init ();
122
127
}
123
128
124
129
#if defined(PROVIDE_FUZZ_MAIN_FUNCTION)
0 commit comments