Files
simdjson-simdjson/fuzz/fuzz_utf8.cpp
T
Paul Dreik 8a68163905 simplify fuzzing only dynamically supported implementations (#1201)
This refactors the dynamic check of which implementations are supported at runtime.

It also reduces duplicated effort in the CI fuzzing job, the differential fuzzers don't need to run with different values of SIMDJSON_FORCE_IMPLEMENTATION.

There is also a convenience script to run the fuzzers locally, to quickly check that the fuzzers still build, run and no easy to find bugs are there. It should be handy not only when developing the fuzzers, but also when modifying simdjson.
2020-10-09 05:29:54 +02:00

54 lines
1.5 KiB
C++

/*
* For fuzzing all of the implementations (haswell/fallback/westmere),
* finding any difference between the output of each which would
* indicate inconsistency. Also, it gets the non-default backend
* some fuzzing love.
*
* Copyright Paul Dreik 20200912 for the simdjson project.
*/
#include "simdjson.h"
#include <cstddef>
#include <cstdlib>
#include "supported_implementations.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
// since this check is expensive, only do it once
static const auto supported_implementations=get_runtime_supported_implementations();
auto utf8verify=[Data,Size](const simdjson::implementation* impl) -> bool {
return impl->validate_utf8((const char*)Data,Size);
};
auto first = supported_implementations.begin();
auto last = supported_implementations.end();
const bool reference=utf8verify(*first);
bool failed=false;
for(auto it=first+1; it != last; ++it) {
const bool current=utf8verify(*it);
if(current!=reference) {
failed=true;
}
}
if(failed) {
std::cerr<<std::boolalpha<<"Mismatch between implementations of validate_utf8() found:\n";
for(const auto& e: supported_implementations) {
if(!e->supported_by_runtime_system()) { continue; }
const bool current=utf8verify(e);
std::cerr<<e->name()<<" returns "<<current<<std::endl;
}
std::abort();
}
//all is well
return 0;
}