Skip to content

Commit

Permalink
fuzz: Add option to ignore errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 3, 2020
1 parent cdd3dbd commit 2038c3f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/fuzzer/parser_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "parser.hpp"
#include <cstdlib>
#include <iomanip>
#include <iostream>

Expand Down Expand Up @@ -36,7 +37,14 @@ Stats stats;

void handle_unexpected_errors() noexcept
{
__builtin_trap();
static const bool ignore_errors = [] {
const auto options = std::getenv("OPTIONS");
if (!options)
return false;
return std::string{options}.find("ignore_errors") != std::string::npos;
}();
if (!ignore_errors)
__builtin_trap();
}

constexpr auto wabt_ignored_errors = {
Expand Down Expand Up @@ -99,7 +107,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t data_size) noe
if (ignored)
continue;

std::cerr << "MISSED ERROR: " << err.message << "\n";
std::cerr << " MISSED ERROR: " << err.message << "\n";
has_errors = true;
}

Expand All @@ -112,7 +120,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t data_size) noe
++stats.malformed;
if (expected)
{
std::cerr << "\nMALFORMED: " << err.what() << "\n\n";
std::cerr << " MALFORMED: " << err.what() << "\n";
handle_unexpected_errors();
}
}
Expand All @@ -121,7 +129,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t data_size) noe
++stats.invalid;
if (expected)
{
std::cerr << "\nINVALID: " << err.what() << "\n\n";
std::cerr << " INVALID: " << err.what() << "\n";
handle_unexpected_errors();
}
}
Expand Down

0 comments on commit 2038c3f

Please sign in to comment.