mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Make it possible to check that an implementation is supported at runtime (#1197)
* Make it possible to check that an implementation is supported at runtime. * add CI fuzzing on arm 64 bit This adds fuzzing on drone.io arm64 For some reason, leak detection had to be disabled. If it is enabled, the fuzzer falsely reports a crash at the end of fuzzing. Closes: #1188 * Guarding the implementation accesses. * Better doc. * Updating cxxopts. * Make it possible to check that an implementation is supported at runtime. * Guarding the implementation accesses. * Better doc. * Updating cxxopts. * We need to accomodate cxxopts Co-authored-by: Paul Dreik <github@pauldreik.se>
This commit is contained in:
@@ -67,7 +67,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
// make this dynamic, so it works regardless of how it was compiled
|
||||
// or what hardware it runs on
|
||||
constexpr std::size_t Nimplementations_max=3;
|
||||
const std::size_t Nimplementations=simdjson::available_implementations.size();
|
||||
std::size_t Nimplementations = 0;
|
||||
|
||||
for(auto impl : simdjson::available_implementations) {
|
||||
if(impl->supported_by_runtime_system()) {
|
||||
Nimplementations++;
|
||||
}
|
||||
}
|
||||
if(Nimplementations>Nimplementations_max) {
|
||||
//there is another backend added, please bump Nimplementations_max!
|
||||
std::abort();
|
||||
@@ -78,7 +84,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
{
|
||||
std::size_t i=0;
|
||||
for(auto& e: simdjson::available_implementations) {
|
||||
implementations[i++].impl=e;
|
||||
if(e->supported_by_runtime_system()) {
|
||||
implementations[i++].impl=e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,16 +32,19 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
};
|
||||
|
||||
|
||||
auto first=simdjson::available_implementations.begin();
|
||||
auto last=simdjson::available_implementations.end();
|
||||
auto const first = simdjson::available_implementations.begin();
|
||||
auto const last = simdjson::available_implementations.end();
|
||||
|
||||
//make sure there is an implementation
|
||||
assert(first!=last);
|
||||
|
||||
auto it = first;
|
||||
while((it != last) && (!(*it)->supported_by_runtime_system())) { it++; }
|
||||
assert(it != last);
|
||||
|
||||
const auto reference=minify(*first);
|
||||
|
||||
bool failed=false;
|
||||
for(auto it=first+1;it!=last; ++it) {
|
||||
for(;it != last; ++it) {
|
||||
if(!(*it)->supported_by_runtime_system()) { continue; }
|
||||
const auto current=minify(*it);
|
||||
if(current!=reference) {
|
||||
failed=true;
|
||||
@@ -50,7 +53,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
|
||||
if(failed) {
|
||||
std::cerr<<std::boolalpha<<"Mismatch between implementations of minify() found:\n";
|
||||
for(auto it=first;it!=last; ++it) {
|
||||
for(it = first;it != last; ++it) {
|
||||
if(!(*it)->supported_by_runtime_system()) { continue; }
|
||||
const auto current=minify(*it);
|
||||
std::string tmp(current.begin(),current.end());
|
||||
std::cerr<<(*it)->name()<<" returns "<<tmp<<std::endl;
|
||||
|
||||
+12
-7
@@ -18,16 +18,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
};
|
||||
|
||||
|
||||
auto first=simdjson::available_implementations.begin();
|
||||
auto last=simdjson::available_implementations.end();
|
||||
auto first = simdjson::available_implementations.begin();
|
||||
auto last = simdjson::available_implementations.end();
|
||||
|
||||
//make sure there is an implementation
|
||||
assert(first!=last);
|
||||
|
||||
const bool reference=utf8verify(*first);
|
||||
auto it = first;
|
||||
while((it != last) && (!(*it)->supported_by_runtime_system())) { it++; }
|
||||
assert(it != last);
|
||||
|
||||
|
||||
const bool reference=utf8verify(*it);
|
||||
|
||||
bool failed=false;
|
||||
for(auto it=first+1;it!=last; ++it) {
|
||||
for(; it != last; ++it) {
|
||||
if(!(*it)->supported_by_runtime_system()) { continue; }
|
||||
const bool current=utf8verify(*it);
|
||||
if(current!=reference) {
|
||||
failed=true;
|
||||
@@ -36,7 +40,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
|
||||
if(failed) {
|
||||
std::cerr<<std::boolalpha<<"Mismatch between implementations of validate_utf8() found:\n";
|
||||
for(auto it=first;it!=last; ++it) {
|
||||
for(it = first;it != last; ++it) {
|
||||
if(!(*it)->supported_by_runtime_system()) { continue; }
|
||||
const bool current=utf8verify(*it);
|
||||
std::cerr<<(*it)->name()<<" returns "<<current<<std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user