aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-04-27 06:09:26 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-04-27 23:47:42 +0800
commit28902f9f425eee83fe3b5699cc132f752e44108a (patch)
treeb51dec4c8ba06cad850759cc1cee16292e10eac2
parent3a93aec7687d435095b12ab87d489ec8a1e78a86 (diff)
downloaddexon-solidity-28902f9f425eee83fe3b5699cc132f752e44108a.tar.gz
dexon-solidity-28902f9f425eee83fe3b5699cc132f752e44108a.tar.zst
dexon-solidity-28902f9f425eee83fe3b5699cc132f752e44108a.zip
Add --standard-json option to solfuzzer
-rw-r--r--test/fuzzer.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp
index dbfec2c1..afa50671 100644
--- a/test/fuzzer.cpp
+++ b/test/fuzzer.cpp
@@ -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;
@@ -83,10 +85,8 @@ void testConstantOptimizer()
}
}
-void testCompiler()
+string readInput()
{
- if (!quiet)
- cout << "Testing compiler." << endl;
string input;
while (!cin.eof())
{
@@ -94,6 +94,41 @@ void testCompiler()
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));
@@ -149,6 +184,12 @@ Allowed 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. "
"Expects a binary string of up to 32 bytes on stdin."
@@ -174,6 +215,8 @@ Allowed options)",
cout << options;
else if (arguments.count("const-opt"))
testConstantOptimizer();
+ else if (arguments.count("standard-json"))
+ testStandardCompiler();
else
testCompiler();