aboutsummaryrefslogtreecommitdiffstats
path: root/test/fuzzer.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-04-06 22:32:20 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-04-27 23:37:02 +0800
commit99dd28d63ec05e001f05d1e788541bf6cf16f881 (patch)
tree642674741386fde092f73533fdfd3e4f1254ca8e /test/fuzzer.cpp
parent2c8b77006255b15743efd0b54964227bccc07c57 (diff)
downloaddexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.gz
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.bz2
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.lz
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.xz
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.zst
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.zip
Add constant optimizer testing to the fuzz tester.
Diffstat (limited to 'test/fuzzer.cpp')
-rw-r--r--test/fuzzer.cpp87
1 files changed, 85 insertions, 2 deletions
diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp
index 410313c5..59090271 100644
--- a/test/fuzzer.cpp
+++ b/test/fuzzer.cpp
@@ -16,15 +16,22 @@
*/
/**
* Executable for use with AFL <http://lcamtuf.coredump.cx/afl>.
- * Reads a single source from stdin and signals a failure for internal errors.
*/
+#include <libevmasm/Assembly.h>
+#include <libevmasm/ConstantOptimiser.h>
+
#include <json/json.h>
+#include <boost/program_options.hpp>
+
#include <string>
#include <iostream>
using namespace std;
+using namespace dev;
+using namespace dev::eth;
+namespace po = boost::program_options;
extern "C"
{
@@ -39,8 +46,41 @@ string contains(string const& _haystack, vector<string> const& _needles)
return "";
}
-int main()
+void testConstantOptimizer()
+{
+ cout << "Testing constant optimizer" << endl;
+ vector<u256> numbers;
+ while (!cin.eof())
+ {
+ h256 data;
+ cin.read(reinterpret_cast<char*>(data.data()), 32);
+ numbers.push_back(u256(data));
+ }
+ cout << "Got " << numbers.size() << " inputs:" << endl;
+
+ Assembly assembly;
+ for (u256 const& n: numbers)
+ {
+ cout << n << endl;
+ assembly.append(n);
+ }
+ for (bool isCreation: {false, true})
+ {
+ for (unsigned runs: {1, 2, 3, 20, 40, 100, 200, 400, 1000})
+ {
+ ConstantOptimisationMethod::optimiseConstants(
+ isCreation,
+ runs,
+ assembly,
+ const_cast<AssemblyItems&>(assembly.items())
+ );
+ }
+ }
+}
+
+void testCompiler()
{
+ cout << "Testing compiler." << endl;
string input;
while (!cin.eof())
{
@@ -87,5 +127,48 @@ int main()
cout << "Output JSON has neither \"errors\" nor \"contracts\"." << endl;
abort();
}
+}
+
+int main(int argc, char** argv)
+{
+ po::options_description options(
+ R"(solfuzzer, fuzz-testing binary for use with AFL.
+Usage: solfuzzer [Options] < input
+Reads a single source from stdin, compiles it and signals a failure for internal errors.
+
+Allowed options)",
+ po::options_description::m_default_line_length,
+ po::options_description::m_default_line_length - 23);
+ options.add_options()
+ (
+ "help",
+ "Show this help screen."
+ )
+ (
+ "const-opt",
+ "Only run the constant optimizer. "
+ "Expects a binary string of up to 32 bytes on stdin."
+ );
+
+ po::variables_map arguments;
+ try
+ {
+ po::command_line_parser cmdLineParser(argc, argv);
+ cmdLineParser.options(options);
+ po::store(cmdLineParser.run(), arguments);
+ }
+ catch (po::error const& _exception)
+ {
+ cerr << _exception.what() << endl;
+ return false;
+ }
+
+ if (arguments.count("help"))
+ cout << options;
+ else if (arguments.count("const-opt"))
+ testConstantOptimizer();
+ else
+ testCompiler();
+
return 0;
}