Skip to content

Commit

Permalink
Add --standard-json option to solfuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 27, 2017
1 parent 3a93aec commit 28902f9
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions test/fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace po = boost::program_options;
extern "C"
{
extern char const* compileJSON(char const* _input, bool _optimize);
typedef void (*CStyleReadFileCallback)(char const* _path, char** o_contents, char** o_error);
extern char const* compileStandard(char const* _input, CStyleReadFileCallback _readCallback);
}

bool quiet = false;
Expand Down Expand Up @@ -83,17 +85,50 @@ void testConstantOptimizer()
}
}

void testCompiler()
string readInput()
{
if (!quiet)
cout << "Testing compiler." << endl;
string input;
while (!cin.eof())
{
string s;
getline(cin, s);
input += s + '\n';
}
return input;
}

void testStandardCompiler()
{
if (!quiet)
cout << "Testing compiler via JSON interface." << endl;
string input = readInput();
string outputString(compileStandard(input.c_str(), NULL));
Json::Value output;
if (!Json::Reader().parse(outputString, output))
{
cout << "Compiler produced invalid JSON output." << endl;
abort();
}
if (output.isMember("errors"))
for (auto const& error: output["errors"])
{
string invalid = contains(error["type"].asString(), vector<string>{
"Exception",
"InternalCompilerError"
});
if (!invalid.empty())
{
cout << "Invalid error: \"" << error["type"].asString() << "\"" << endl;
abort();
}
}
}

void testCompiler()
{
if (!quiet)
cout << "Testing compiler." << endl;
string input = readInput();

bool optimize = true;
string outputString(compileJSON(input.c_str(), optimize));
Expand Down Expand Up @@ -148,6 +183,12 @@ Allowed options)",
options.add_options()
("help", "Show this help screen.")
("quiet", "Only output errors.")
(
"standard-json",
"Test via the standard-json interface, i.e. "
"input is expected to be JSON-encoded instead of "
"plain source file."
)
(
"const-opt",
"Run the constant optimizer instead of compiling. "
Expand All @@ -174,6 +215,8 @@ Allowed options)",
cout << options;
else if (arguments.count("const-opt"))
testConstantOptimizer();
else if (arguments.count("standard-json"))
testStandardCompiler();
else
testCompiler();

Expand Down

0 comments on commit 28902f9

Please sign in to comment.