Go to the documentation of this file.
2 #include <fuzzer/FuzzedDataProvider.h>
15 const std::string what = e.what();
16 const std::vector<std::string> expected_patterns = {
"Blackboard::set",
17 "once declared, the type of a "
18 "port shall not change",
20 "hasn't been initialized",
21 "Missing parent blackboard",
22 "Floating point truncated",
23 "Value outside the max "
25 "Value outside the lovest "
27 "Value is negative and can't be "
28 "converted to unsigned",
29 "Implicit casting to bool is "
32 for(
const auto& pattern : expected_patterns)
34 if(what.find(pattern) != std::string::npos)
52 const std::string key_chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01"
54 size_t length =
fuzz_data_.ConsumeIntegralInRange<
size_t>(1, 32);
56 for(
size_t i = 0; i < length; ++i)
59 key_chars[
fuzz_data_.ConsumeIntegralInRange<
size_t>(0, key_chars.length() - 1)];
74 switch(
fuzz_data_.ConsumeIntegralInRange<
size_t>(0, 6))
77 bb->set(key,
fuzz_data_.ConsumeIntegral<
int>());
80 bb->set(key,
fuzz_data_.ConsumeFloatingPoint<
double>());
83 bb->set(key,
fuzz_data_.ConsumeRandomLengthString());
89 bb->set(key,
fuzz_data_.ConsumeIntegral<uint64_t>());
92 bb->set(key,
fuzz_data_.ConsumeFloatingPoint<
float>());
104 const auto& existing_key =
108 switch(
fuzz_data_.ConsumeIntegralInRange<
size_t>(0, 4))
111 bb->unset(existing_key);
114 bb->getEntry(existing_key);
117 bb->get<
int>(existing_key);
120 bb->get<
double>(existing_key);
123 bb->get<std::string>(existing_key);
138 catch(
const std::exception& e)
158 child->enableAutoRemapping(
true);
172 size_t pos =
fuzz_data_.ConsumeIntegralInRange<
size_t>(0, json_str.length());
173 json_str.insert(pos,
fuzz_data_.ConsumeRandomLengthString());
178 catch(
const std::exception& e)
195 size_t num_operations =
fuzz_data_.ConsumeIntegralInRange<
size_t>(50, 200);
197 for(
size_t i = 0; i < num_operations && !
blackboards_.empty(); ++i)
206 switch(
fuzz_data_.ConsumeIntegralInRange<
size_t>(0, 3))
237 catch(
const std::exception& e)
241 std::cerr <<
"Unexpected exception: " << e.what() << std::endl;
256 FuzzedDataProvider fuzz_data(data,
size);
260 catch(
const std::exception& e)
264 std::cerr <<
"Unexpected top-level exception: " << e.what() << std::endl;
constexpr auto size(const C &c) -> decltype(c.size())
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
BlackboardFuzzer(FuzzedDataProvider &provider)
std::string generateKey()
void ImportBlackboardFromJSON(const nlohmann::json &json, Blackboard &blackboard)
ImportBlackboardFromJSON will append elements to the blackboard, using the values parsed from the JSO...
static bool isExpectedException(const std::exception &e)
namespace for Niels Lohmann
std::vector< BT::Blackboard::Ptr > blackboards_
nlohmann::json ExportBlackboardToJSON(const Blackboard &blackboard)
ExportBlackboardToJSON will create a JSON that contains the current values of the blackboard....
void fuzzJsonOperations(BT::Blackboard::Ptr bb)
std::shared_ptr< Blackboard > Ptr
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
auto child(const lexy::parse_tree< Reader, TokenKind, MemoryResource > &tree, typename lexy::parse_tree< Reader, TokenKind, MemoryResource >::node node, Predicate predicate) -> std::optional< typename lexy::parse_tree< Reader, TokenKind, MemoryResource >::node >
Returns the first child that matches predicate, if there is any.
FuzzedDataProvider & fuzz_data_
void createBlackboardHierarchy()
static Blackboard::Ptr create(Blackboard::Ptr parent={})
std::vector< std::string > generated_keys_
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
void fuzzSingleBB(BT::Blackboard::Ptr bb)