#ifndef CHROME_TEST_FUZZING_IN_PROCESS_PROTO_FUZZER_H_
#define CHROME_TEST_FUZZING_IN_PROCESS_PROTO_FUZZER_H_
#include "chrome/test/fuzzing/in_process_fuzzer.h"
#include "testing/libfuzzer/proto/lpm_interface.h"
#define DEFINE_PROTO_FUZZER_IN_PROCESS_IMPL(use_binary, arg) \
static void TestOneProtoInput(arg); \
using FuzzerProtoType = \
protobuf_mutator::libfuzzer::macro_internal::GetFirstParam< \
decltype(&TestOneProtoInput)>::type; \
DEFINE_CUSTOM_PROTO_MUTATOR_IMPL(use_binary, FuzzerProtoType) \
DEFINE_CUSTOM_PROTO_CROSSOVER_IMPL(use_binary, FuzzerProtoType) \
DEFINE_POST_PROCESS_PROTO_MUTATION_IMPL(FuzzerProtoType)
#define REGISTER_TEXT_PROTO_IN_PROCESS_FUZZER(arg) \
REGISTER_IN_PROCESS_FUZZER(arg) \
DEFINE_PROTO_FUZZER_IN_PROCESS_IMPL(false, arg::FuzzCase testcase)
#define REGISTER_BINARY_PROTO_IN_PROCESS_FUZZER(arg) \
REGISTER_IN_PROCESS_FUZZER(arg) \
DEFINE_PROTO_FUZZER_IN_PROCESS_IMPL(true, arg::FuzzCase testcase)
template <typename Proto>
class InProcessTextProtoFuzzer : public InProcessFuzzer {
public:
using FuzzCase = Proto;
InProcessTextProtoFuzzer(InProcessFuzzerOptions options = {})
: InProcessFuzzer(options) {}
protected:
int Fuzz(const uint8_t* data, size_t size) override {
using protobuf_mutator::libfuzzer::LoadProtoInput;
FuzzCase fuzz_case;
if (!LoadProtoInput(false, data, size, &fuzz_case)) {
return -1;
}
return Fuzz(fuzz_case);
}
virtual int Fuzz(const FuzzCase& fuzz_case) = 0;
};
template <typename Proto>
class InProcessBinaryProtoFuzzer : public InProcessFuzzer {
public:
using FuzzCase = Proto;
InProcessBinaryProtoFuzzer(InProcessFuzzerOptions options = {})
: InProcessFuzzer(options) {}
protected:
int Fuzz(const uint8_t* data, size_t size) override {
using protobuf_mutator::libfuzzer::LoadProtoInput;
FuzzCase fuzz_case;
if (!LoadProtoInput(true, data, size, &fuzz_case)) {
return -1;
}
return Fuzz(fuzz_case);
}
virtual int Fuzz(const FuzzCase& fuzz_case) = 0;
};
#endif