diff --git a/retesteth/Options.cpp b/retesteth/Options.cpp index 4823dc903..dc797a320 100644 --- a/retesteth/Options.cpp +++ b/retesteth/Options.cpp @@ -44,8 +44,11 @@ void printHelp() cout << "\nAll options below must be followed by `--`\n"; cout << "\nRetesteth options\n"; cout << setw(40) << "-j " << setw(0) << "Run test execution using threads\n"; - cout << setw(40) << "--clients ``" << setw(0) - << "Use following configurations from the testpath/Retesteth\n"; + cout << setw(40) << "--clients `client1, client2`" << setw(0) + << "Use following configurations from datadir path (default: ~/.retesteth)\n"; + cout << setw(40) << "--datadir" << setw(0) << "Path to configs (default: ~/.retesteth)\n"; + cout << setw(40) << "--nodes" << setw(0) << "List of client tcp ports (\"addr:ip, addr:ip\")\n"; + cout << setw(42) << " " << setw(0) << "Overrides the config file \"socketAddress\" section \n"; cout << setw(40) << "--help" << setw(25) << "Display list of command arguments\n"; cout << setw(40) << "--version" << setw(25) << "Display build information\n"; cout << setw(40) << "--list" << setw(25) << "Display available test suites\n"; @@ -53,7 +56,9 @@ void printHelp() cout << "\nSetting test suite and test\n"; cout << setw(40) << "--testpath " << setw(25) << "Set path to the test repo\n"; cout << setw(40) << "--testfile " << setw(0) << "Run tests from a file. Requires -t \n"; - cout << setw(40) << "--singletest /" << setw(0) << "Run on a single test (Testname is filename without Filler.json, Subtest is a test name inside the file)\n"; + cout << setw(40) << "--singletest " << setw(0) + << "Run on a single test. `Testname` is filename without Filler.json\n"; + cout << setw(40) << "--singletest /" << setw(0) << "`Subtest` is a test name inside the file\n"; cout << "\nDebugging\n"; cout << setw(30) << "-d " << setw(25) << "Set the transaction data array index when running GeneralStateTests\n"; @@ -77,6 +82,7 @@ void printHelp() cout << setw(30) << "--showhash" << setw(25) << "Show filler hash debug information\n"; cout << setw(30) << "--poststate" << setw(25) << "Show post state hash or fullstate\n"; cout << setw(30) << "--fullstate" << setw(25) << "Do not compress large states to hash\n"; + // cout << setw(30) << "--randomcode " << setw(25) << "Generate smart random EVM //code\n"; cout << setw(30) << "--createRandomTest" << setw(25) << "Create random test and //output it to the console\n"; cout << setw(30) << "--createRandomTest " << @@ -243,7 +249,18 @@ Options::Options(int argc, const char** argv) if (logVerbosity > (size_t)g_logVerbosity) g_logVerbosity = logVerbosity; } - else if (arg == "--options") + else if (arg == "--datadir") + { + throwIfNoArgumentFollows(); + datadir = fs::path(std::string{argv[++i]}); + } + else if (arg == "--nodes") + { + throwIfNoArgumentFollows(); + for (auto const& el : explode(std::string{argv[++i]}, ',')) + nodesoverride.addArrayObject(el); + } + else if (arg == "--options") { throwIfNoArgumentFollows(); boost::filesystem::path file(std::string{argv[++i]}); @@ -392,6 +409,8 @@ void displayTestSuites() cout << setw(40) << "-t BlockchainTests/ValidBlocks" << setw(0) << "Subset of correct blocks\n"; cout << setw(40) << "-t BlockchainTests/InvalidBlocks" << setw(0) << "Subset of malicious blocks\n"; cout << setw(40) << "-t BlockchainTests/TransitionTests" << setw(0) << "Subset of fork transition tests\n"; + cout << setw(40) << "-t BlockchainTests/ValidBlocks/VMTests" << setw(0) + << "VMTests converted\n"; cout << "(Use --filltests to generate the tests, --fillchain to generate BCGeneralStateTests)\n"; cout << "\nLegacy test suites (Frontier .. ConstantinopleFix):\n"; diff --git a/retesteth/Options.h b/retesteth/Options.h index 82917bf8f..d6b8a91d1 100644 --- a/retesteth/Options.h +++ b/retesteth/Options.h @@ -41,7 +41,9 @@ class Options bool stats = false; ///< Execution time and stats for state tests bool poststate = false; std::string statsOutFile; ///< Stats output file. "out" for standard output - bool exectimelog = false; ///< Print execution time for each test suite + fs::path datadir; ///< Path to datadir (~/.retesteth) + DataObject nodesoverride; ///< ["IP:port", ""IP:port""] array + bool exectimelog = false; ///< Print execution time for each test suite std::string rCurrentTestSuite; ///< Remember test suite before boost overwrite (for random tests) bool statediff = false; ///< Fill full post state in General tests bool fullstate = false; ///< Replace large state output to it's hash diff --git a/retesteth/RPCSession.cpp b/retesteth/RPCSession.cpp index 356a7d681..4af963fd0 100644 --- a/retesteth/RPCSession.cpp +++ b/retesteth/RPCSession.cpp @@ -107,8 +107,12 @@ void RPCSession::runNewInstanceOfAClient(string const& _threadID, ClientConfig c { std::lock_guard lock(g_socketMapMutex); // function must be called from lock + DataObject const& ports = (Options::get().nodesoverride.getSubObjects().size() > 0 ? + Options::get().nodesoverride : + _config.getAddressObject()); + // Create sessionInfo for a tcp address that is still not present in socketMap - for (auto const& addr : _config.getAddressObject().getSubObjects()) + for (auto const& addr : ports.getSubObjects()) { bool unused = true; for (auto const& socket : socketMap) diff --git a/retesteth/TestHelper.cpp b/retesteth/TestHelper.cpp index 0672d7bee..075a636d6 100644 --- a/retesteth/TestHelper.cpp +++ b/retesteth/TestHelper.cpp @@ -417,6 +417,17 @@ string replaceCode(string const& _code) return compiledCode; } +/// Explode string into array of strings by `delim` +std::vector explode(std::string const& s, char delim) +{ + std::vector result; + std::istringstream iss(s); + for (std::string token; std::getline(iss, token, delim);) + result.push_back(std::move(token)); + return result; +} + + #include #define READ 0 #define WRITE 1 diff --git a/retesteth/TestHelper.h b/retesteth/TestHelper.h index 772c72e06..cc432d0b1 100644 --- a/retesteth/TestHelper.h +++ b/retesteth/TestHelper.h @@ -77,6 +77,8 @@ bool inArray(std::vector const& _array, const T& _val) return false; } +/// Explode string into array of strings by `delim` +std::vector explode(std::string const& s, char delim); /// popen with pid at return enum popenOutput diff --git a/retesteth/configs/Options.cpp b/retesteth/configs/Options.cpp index 2c3c8f4f0..9034d5412 100644 --- a/retesteth/configs/Options.cpp +++ b/retesteth/configs/Options.cpp @@ -9,9 +9,23 @@ using namespace std; using namespace test; namespace fs = boost::filesystem; +namespace +{ +fs::path getRetestethDataDir() +{ + fs::path const& dir = Options::get().datadir; + bool optionsEmpty = dir.empty(); + if (!optionsEmpty && !fs::exists(dir)) + ETH_LOG( + "Options path `" + dir.string() + "` doesn't exist, attempt to create a new directory", + 3); + return optionsEmpty ? getDataDir("retesteth") : dir; +} +} // namespace + void deployFirstRunConfigs() { - fs::path homeDir = getDataDir("retesteth"); + fs::path homeDir = getRetestethDataDir(); if (fs::exists(homeDir)) { @@ -105,7 +119,7 @@ std::vector const& Options::DynamicOptions::getClientConfigs() for (auto const& clientName : cfgs) { - fs::path configDirectory = getDataDir("retesteth"); // getTestPath(); + fs::path configDirectory = getRetestethDataDir(); ETH_FAIL_REQUIRE_MESSAGE(fs::exists(configDirectory), "Could not locate provided testpath: " + string(configDirectory.c_str())); fs::path configPath = configDirectory / clientName; diff --git a/retesteth/main.cpp b/retesteth/main.cpp index 12358b520..6b79fb26b 100644 --- a/retesteth/main.cpp +++ b/retesteth/main.cpp @@ -4,14 +4,15 @@ #include #include #include +#include #include +#include +#include #include #include #include #include #include -#include -#include using namespace boost::unit_test; static std::ostringstream strCout; @@ -103,15 +104,6 @@ void setDefaultOrCLocale() #endif } -std::vector explode(std::string const& s, char delim) -{ - std::vector result; - std::istringstream iss(s); - for (std::string token; std::getline(iss, token, delim);) - result.push_back(std::move(token)); - return result; -} - // Custom Boost Unit Test Main int main(int argc, const char* argv[]) {