mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5134 from ethereum/fuzzer-input-file
solfuzzer: adds --input-file=FILENAME command line argument (defaulting to stdin)
This commit is contained in:
commit
5b5a4d0172
@ -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";
|
||||
@ -167,16 +168,25 @@ Allowed options)",
|
||||
"Run the constant optimizer instead of compiling. "
|
||||
"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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user