Skip to content

Commit 2038c3f

Browse files
committed
fuzz: Add option to ignore errors
1 parent cdd3dbd commit 2038c3f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

test/fuzzer/parser_fuzzer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#include "parser.hpp"
6+
#include <cstdlib>
67
#include <iomanip>
78
#include <iostream>
89

@@ -36,7 +37,14 @@ Stats stats;
3637

3738
void handle_unexpected_errors() noexcept
3839
{
39-
__builtin_trap();
40+
static const bool ignore_errors = [] {
41+
const auto options = std::getenv("OPTIONS");
42+
if (!options)
43+
return false;
44+
return std::string{options}.find("ignore_errors") != std::string::npos;
45+
}();
46+
if (!ignore_errors)
47+
__builtin_trap();
4048
}
4149

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

102-
std::cerr << "MISSED ERROR: " << err.message << "\n";
110+
std::cerr << " MISSED ERROR: " << err.message << "\n";
103111
has_errors = true;
104112
}
105113

@@ -112,7 +120,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t data_size) noe
112120
++stats.malformed;
113121
if (expected)
114122
{
115-
std::cerr << "\nMALFORMED: " << err.what() << "\n\n";
123+
std::cerr << " MALFORMED: " << err.what() << "\n";
116124
handle_unexpected_errors();
117125
}
118126
}
@@ -121,7 +129,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t data_size) noe
121129
++stats.invalid;
122130
if (expected)
123131
{
124-
std::cerr << "\nINVALID: " << err.what() << "\n\n";
132+
std::cerr << " INVALID: " << err.what() << "\n";
125133
handle_unexpected_errors();
126134
}
127135
}

0 commit comments

Comments
 (0)