From 867fe4033df6b2165136b7fdca93245e77f78903 Mon Sep 17 00:00:00 2001 From: Dimitry Khokhlov Date: Thu, 18 Jun 2015 20:13:49 +0400 Subject: [PATCH] fuzzTests: debug support --- test/fuzzTesting/createRandomTest.cpp | 107 ++++++++++++++++---------- test/libevm/vm.cpp | 6 +- 2 files changed, 69 insertions(+), 44 deletions(-) diff --git a/test/fuzzTesting/createRandomTest.cpp b/test/fuzzTesting/createRandomTest.cpp index e21f22eea..6a3a7f4a0 100644 --- a/test/fuzzTesting/createRandomTest.cpp +++ b/test/fuzzTesting/createRandomTest.cpp @@ -36,8 +36,8 @@ extern std::string const c_testExampleVMTest; extern std::string const c_testExampleBlockchainTest; //Main Test functinos -void fillRandomTest(std::function doTests, std::string const& testString); -int checkRandomTest(std::function doTests, json_spirit::mValue& value); +void fillRandomTest(std::function _doTests, std::string const& _testString, bool _debug = false); +int checkRandomTest(std::function _doTests, json_spirit::mValue& _value, bool _debug = false); //Helper Functions std::vector getTypes(); @@ -48,6 +48,8 @@ int main(int argc, char *argv[]) std::string testSuite; json_spirit::mValue testmValue; bool checktest = false; + bool filldebug = false; + bool debug = false; for (auto i = 0; i < argc; ++i) { auto arg = std::string{argv[i]}; @@ -75,6 +77,12 @@ int main(int argc, char *argv[]) read_string(s, testmValue); checktest = true; } + else + if (arg == "--debug") + debug = true; + else + if (arg == "--filldebug") + filldebug = true; } if (testSuite == "") @@ -83,45 +91,50 @@ int main(int argc, char *argv[]) return 1; } else - if (testSuite == "BlockChainTests") { if (checktest) - return checkRandomTest(dev::test::doBlockchainTests, testmValue); - else - fillRandomTest(dev::test::doBlockchainTests, c_testExampleBlockchainTest); - } - else - if (testSuite == "TransactionTests") - { - if (checktest) - return checkRandomTest(dev::test::doTransactionTests, testmValue); + std::cout << "Testing: " << testSuite.substr(0, testSuite.length() - 1) << std::endl; + + if (testSuite == "BlockChainTests") + { + if (checktest) + return checkRandomTest(dev::test::doBlockchainTests, testmValue, debug); + else + fillRandomTest(dev::test::doBlockchainTests, c_testExampleBlockchainTest, filldebug); + } else - fillRandomTest(dev::test::doTransactionTests, c_testExampleTransactionTest); - } - else - if (testSuite == "StateTests") - { - if (checktest) - return checkRandomTest(dev::test::doStateTests, testmValue); + if (testSuite == "TransactionTests") + { + if (checktest) + return checkRandomTest(dev::test::doTransactionTests, testmValue, debug); + else + fillRandomTest(dev::test::doTransactionTests, c_testExampleTransactionTest, filldebug); + } else - fillRandomTest(dev::test::doStateTests, c_testExampleStateTest); - } - else - if (testSuite == "VMTests") - { - if (checktest) + if (testSuite == "StateTests") { - dev::eth::VMFactory::setKind(dev::eth::VMKind::JIT); - return checkRandomTest(dev::test::doVMTests, testmValue); + if (checktest) + return checkRandomTest(dev::test::doStateTests, testmValue, debug); + else + fillRandomTest(dev::test::doStateTests, c_testExampleStateTest, filldebug); } 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; } -int checkRandomTest(std::function doTests, json_spirit::mValue& value) +int checkRandomTest(std::function _doTests, json_spirit::mValue& _value, bool _debug) { bool ret = 0; try @@ -129,14 +142,20 @@ int checkRandomTest(std::function doTests, jso //redirect all output to the stream std::ostringstream strCout; std::streambuf* oldCoutStreamBuf = std::cout.rdbuf(); - std::cout.rdbuf( strCout.rdbuf() ); - std::cerr.rdbuf( strCout.rdbuf() ); + if (!_debug) + { + std::cout.rdbuf( strCout.rdbuf() ); + std::cerr.rdbuf( strCout.rdbuf() ); + } - doTests(value, false); + _doTests(_value, false); //restroe output - std::cout.rdbuf(oldCoutStreamBuf); - std::cerr.rdbuf(oldCoutStreamBuf); + if (!_debug) + { + std::cout.rdbuf(oldCoutStreamBuf); + std::cerr.rdbuf(oldCoutStreamBuf); + } } catch (dev::Exception const& _e) { @@ -151,21 +170,24 @@ int checkRandomTest(std::function doTests, jso return ret; } -void fillRandomTest(std::function doTests, std::string const& testString) +void fillRandomTest(std::function _doTests, std::string const& _testString, bool _debug) { //redirect all output to the stream std::ostringstream strCout; std::streambuf* oldCoutStreamBuf = std::cout.rdbuf(); - std::cout.rdbuf( strCout.rdbuf() ); - std::cerr.rdbuf( strCout.rdbuf() ); + if (!_debug) + { + std::cout.rdbuf( strCout.rdbuf() ); + std::cerr.rdbuf( strCout.rdbuf() ); + } json_spirit::mValue v; try { - std::string newTest = testString; + std::string newTest = _testString; parseTestWithTypes(newTest); json_spirit::read_string(newTest, v); - doTests(v, true); + _doTests(v, true); } catch(...) { @@ -173,8 +195,11 @@ void fillRandomTest(std::function doTests, std } //restroe output - std::cout.rdbuf(oldCoutStreamBuf); - std::cerr.rdbuf(oldCoutStreamBuf); + if (!_debug) + { + std::cout.rdbuf(oldCoutStreamBuf); + std::cerr.rdbuf(oldCoutStreamBuf); + } std::cout << json_spirit::write_string(v, true); } diff --git a/test/libevm/vm.cpp b/test/libevm/vm.cpp index 25ed8113b..fdfb180fb 100644 --- a/test/libevm/vm.cpp +++ b/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(); 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 - 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")); } @@ -440,7 +440,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) checkLog(fev.sub.logs, test.sub.logs); } else // Exception expected - BOOST_CHECK(vmExceptionOccured); + TBOOST_CHECK(vmExceptionOccured); } } }