Browse Source

fuzzTests: debug support

cl-refactor
Dimitry Khokhlov 10 years ago
parent
commit
867fe4033d
  1. 107
      test/fuzzTesting/createRandomTest.cpp
  2. 6
      test/libevm/vm.cpp

107
test/fuzzTesting/createRandomTest.cpp

@ -36,8 +36,8 @@ extern std::string const c_testExampleVMTest;
extern std::string const c_testExampleBlockchainTest; extern std::string const c_testExampleBlockchainTest;
//Main Test functinos //Main Test functinos
void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, std::string const& testString); void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, std::string const& _testString, bool _debug = false);
int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, json_spirit::mValue& value); int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, json_spirit::mValue& _value, bool _debug = false);
//Helper Functions //Helper Functions
std::vector<std::string> getTypes(); std::vector<std::string> getTypes();
@ -48,6 +48,8 @@ int main(int argc, char *argv[])
std::string testSuite; std::string testSuite;
json_spirit::mValue testmValue; json_spirit::mValue testmValue;
bool checktest = false; bool checktest = false;
bool filldebug = false;
bool debug = false;
for (auto i = 0; i < argc; ++i) for (auto i = 0; i < argc; ++i)
{ {
auto arg = std::string{argv[i]}; auto arg = std::string{argv[i]};
@ -75,6 +77,12 @@ int main(int argc, char *argv[])
read_string(s, testmValue); read_string(s, testmValue);
checktest = true; checktest = true;
} }
else
if (arg == "--debug")
debug = true;
else
if (arg == "--filldebug")
filldebug = true;
} }
if (testSuite == "") if (testSuite == "")
@ -83,45 +91,50 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
else else
if (testSuite == "BlockChainTests")
{ {
if (checktest) if (checktest)
return checkRandomTest(dev::test::doBlockchainTests, testmValue); std::cout << "Testing: " << testSuite.substr(0, testSuite.length() - 1) << std::endl;
else
fillRandomTest(dev::test::doBlockchainTests, c_testExampleBlockchainTest); if (testSuite == "BlockChainTests")
} {
else if (checktest)
if (testSuite == "TransactionTests") return checkRandomTest(dev::test::doBlockchainTests, testmValue, debug);
{ else
if (checktest) fillRandomTest(dev::test::doBlockchainTests, c_testExampleBlockchainTest, filldebug);
return checkRandomTest(dev::test::doTransactionTests, testmValue); }
else else
fillRandomTest(dev::test::doTransactionTests, c_testExampleTransactionTest); if (testSuite == "TransactionTests")
} {
else if (checktest)
if (testSuite == "StateTests") return checkRandomTest(dev::test::doTransactionTests, testmValue, debug);
{ else
if (checktest) fillRandomTest(dev::test::doTransactionTests, c_testExampleTransactionTest, filldebug);
return checkRandomTest(dev::test::doStateTests, testmValue); }
else else
fillRandomTest(dev::test::doStateTests, c_testExampleStateTest); if (testSuite == "StateTests")
}
else
if (testSuite == "VMTests")
{
if (checktest)
{ {
dev::eth::VMFactory::setKind(dev::eth::VMKind::JIT); if (checktest)
return checkRandomTest(dev::test::doVMTests, testmValue); return checkRandomTest(dev::test::doStateTests, testmValue, debug);
else
fillRandomTest(dev::test::doStateTests, c_testExampleStateTest, filldebug);
} }
else else
fillRandomTest(dev::test::doVMTests, c_testExampleVMTest); if (testSuite == "VMTests")
{
if (checktest)
{
dev::eth::VMFactory::setKind(dev::eth::VMKind::JIT);
return checkRandomTest(dev::test::doVMTests, testmValue, debug);
}
else
fillRandomTest(dev::test::doVMTests, c_testExampleVMTest, filldebug);
}
} }
return 0; return 0;
} }
int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, json_spirit::mValue& value) int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, json_spirit::mValue& _value, bool _debug)
{ {
bool ret = 0; bool ret = 0;
try try
@ -129,14 +142,20 @@ int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, jso
//redirect all output to the stream //redirect all output to the stream
std::ostringstream strCout; std::ostringstream strCout;
std::streambuf* oldCoutStreamBuf = std::cout.rdbuf(); std::streambuf* oldCoutStreamBuf = std::cout.rdbuf();
std::cout.rdbuf( strCout.rdbuf() ); if (!_debug)
std::cerr.rdbuf( strCout.rdbuf() ); {
std::cout.rdbuf( strCout.rdbuf() );
std::cerr.rdbuf( strCout.rdbuf() );
}
doTests(value, false); _doTests(_value, false);
//restroe output //restroe output
std::cout.rdbuf(oldCoutStreamBuf); if (!_debug)
std::cerr.rdbuf(oldCoutStreamBuf); {
std::cout.rdbuf(oldCoutStreamBuf);
std::cerr.rdbuf(oldCoutStreamBuf);
}
} }
catch (dev::Exception const& _e) catch (dev::Exception const& _e)
{ {
@ -151,21 +170,24 @@ int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, jso
return ret; return ret;
} }
void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, std::string const& testString) void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, std::string const& _testString, bool _debug)
{ {
//redirect all output to the stream //redirect all output to the stream
std::ostringstream strCout; std::ostringstream strCout;
std::streambuf* oldCoutStreamBuf = std::cout.rdbuf(); std::streambuf* oldCoutStreamBuf = std::cout.rdbuf();
std::cout.rdbuf( strCout.rdbuf() ); if (!_debug)
std::cerr.rdbuf( strCout.rdbuf() ); {
std::cout.rdbuf( strCout.rdbuf() );
std::cerr.rdbuf( strCout.rdbuf() );
}
json_spirit::mValue v; json_spirit::mValue v;
try try
{ {
std::string newTest = testString; std::string newTest = _testString;
parseTestWithTypes(newTest); parseTestWithTypes(newTest);
json_spirit::read_string(newTest, v); json_spirit::read_string(newTest, v);
doTests(v, true); _doTests(v, true);
} }
catch(...) catch(...)
{ {
@ -173,8 +195,11 @@ void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, std
} }
//restroe output //restroe output
std::cout.rdbuf(oldCoutStreamBuf); if (!_debug)
std::cerr.rdbuf(oldCoutStreamBuf); {
std::cout.rdbuf(oldCoutStreamBuf);
std::cerr.rdbuf(oldCoutStreamBuf);
}
std::cout << json_spirit::write_string(v, true); std::cout << json_spirit::write_string(v, true);
} }

6
test/libevm/vm.cpp

@ -395,9 +395,9 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
{ {
std::string warning = "Check State: Error! Unexpected output: " + o["out"].get_str() + " Expected: " + o["expectOut"].get_str(); std::string warning = "Check State: Error! Unexpected output: " + o["out"].get_str() + " Expected: " + o["expectOut"].get_str();
if (Options::get().checkState) if (Options::get().checkState)
BOOST_CHECK_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning); {TBOOST_CHECK_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning);}
else else
BOOST_WARN_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning); TBOOST_WARN_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning);
o.erase(o.find("expectOut")); o.erase(o.find("expectOut"));
} }
@ -440,7 +440,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
checkLog(fev.sub.logs, test.sub.logs); checkLog(fev.sub.logs, test.sub.logs);
} }
else // Exception expected else // Exception expected
BOOST_CHECK(vmExceptionOccured); TBOOST_CHECK(vmExceptionOccured);
} }
} }
} }

Loading…
Cancel
Save