diff options
author | Christian Parpart <christian@parpart.family> | 2018-10-02 18:24:50 +0800 |
---|---|---|
committer | Christian Parpart <christian@ethereum.org> | 2018-10-10 17:13:03 +0800 |
commit | 212a6e146a48e85907907bfa8a111c26e5b52b4b (patch) | |
tree | e7a67a3016214577d468a370df2ee2697f3ad12a | |
parent | f6f0cecc2f64f4fcda3da467bbe306b5859729aa (diff) | |
download | dexon-solidity-212a6e146a48e85907907bfa8a111c26e5b52b4b.tar dexon-solidity-212a6e146a48e85907907bfa8a111c26e5b52b4b.tar.gz dexon-solidity-212a6e146a48e85907907bfa8a111c26e5b52b4b.tar.bz2 dexon-solidity-212a6e146a48e85907907bfa8a111c26e5b52b4b.tar.lz dexon-solidity-212a6e146a48e85907907bfa8a111c26e5b52b4b.tar.xz dexon-solidity-212a6e146a48e85907907bfa8a111c26e5b52b4b.tar.zst dexon-solidity-212a6e146a48e85907907bfa8a111c26e5b52b4b.zip |
adds --input-file=FILENAME to solfuzzer
-rw-r--r-- | test/tools/fuzzer.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/test/tools/fuzzer.cpp b/test/tools/fuzzer.cpp index ce4b721f..509c5975 100644 --- a/test/tools/fuzzer.cpp +++ b/test/tools/fuzzer.cpp @@ -28,6 +28,7 @@ #include <boost/program_options.hpp> #include <string> +#include <sstream> #include <iostream> using namespace std; @@ -48,15 +49,17 @@ string contains(string const& _haystack, vector<string> const& _needles) return ""; } -void testConstantOptimizer() +void testConstantOptimizer(string const& input) { if (!quiet) cout << "Testing constant optimizer" << endl; vector<u256> numbers; - while (!cin.eof()) + stringstream sin(input); + + while (!sin.eof()) { h256 data; - cin.read(reinterpret_cast<char*>(data.data()), 32); + sin.read(reinterpret_cast<char*>(data.data()), 32); numbers.push_back(u256(data)); } if (!quiet) @@ -108,20 +111,18 @@ void runCompiler(string input) } } -void testStandardCompiler() +void testStandardCompiler(string const& input) { if (!quiet) cout << "Testing compiler via JSON interface." << endl; - string input = readStandardInput(); runCompiler(input); } -void testCompiler(bool optimize) +void testCompiler(string const& input, bool optimize) { if (!quiet) cout << "Testing compiler " << (optimize ? "with" : "without") << " optimizer." << endl; - string input = readStandardInput(); Json::Value config = Json::objectValue; config["language"] = "Solidity"; @@ -168,15 +169,24 @@ Allowed options)", "Expects a binary string of up to 32 bytes on stdin." ) ( + "input-file", + po::value<string>(), + "input file" + ) + ( "without-optimizer", "Run without optimizations. Cannot be used together with standard-json." ); + // All positional options should be interpreted as input files + po::positional_options_description filesPositions; + filesPositions.add("input-file", 1); + po::variables_map arguments; try { po::command_line_parser cmdLineParser(argc, argv); - cmdLineParser.options(options); + cmdLineParser.options(options).positional(filesPositions); po::store(cmdLineParser.run(), arguments); } catch (po::error const& _exception) @@ -185,17 +195,23 @@ Allowed options)", return 1; } + string input; + if (arguments.count("input-file")) + input = readFileAsString(arguments["input-file"].as<string>()); + else + input = readStandardInput(); + if (arguments.count("quiet")) quiet = true; if (arguments.count("help")) cout << options; else if (arguments.count("const-opt")) - testConstantOptimizer(); + testConstantOptimizer(input); else if (arguments.count("standard-json")) - testStandardCompiler(); + testStandardCompiler(input); else - testCompiler(!arguments.count("without-optimizer")); + testCompiler(input, !arguments.count("without-optimizer")); return 0; } |