Merge pull request #11996 from hawkess/isoltest-validation

Isoltest validation
This commit is contained in:
Kamil Śliwak 2021-09-22 17:43:44 +02:00 committed by GitHub
commit 11fdcc5159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 25 deletions

View File

@ -91,22 +91,27 @@ CommonOptions::CommonOptions(std::string _caption):
po::options_description::m_default_line_length, po::options_description::m_default_line_length,
po::options_description::m_default_line_length - 23 po::options_description::m_default_line_length - 23
) )
{
}
void CommonOptions::addOptions()
{ {
options.add_options() options.add_options()
("evm-version", po::value(&evmVersionString), "which evm version to use") ("evm-version", po::value(&evmVersionString), "which evm version to use")
("testpath", po::value<fs::path>(&this->testPath)->default_value(solidity::test::testPath()), "path to test files") ("testpath", po::value<fs::path>(&this->testPath)->default_value(solidity::test::testPath()), "path to test files")
("vm", po::value<std::vector<fs::path>>(&vmPaths), "path to evmc library, can be supplied multiple times.") ("vm", po::value<std::vector<fs::path>>(&vmPaths), "path to evmc library, can be supplied multiple times.")
("ewasm", po::bool_switch(&ewasm), "tries to automatically find an ewasm vm and enable ewasm test-execution.") ("ewasm", po::bool_switch(&ewasm)->default_value(ewasm), "tries to automatically find an ewasm vm and enable ewasm test-execution.")
("no-semantic-tests", po::bool_switch(&disableSemanticTests), "disable semantic tests") ("no-semantic-tests", po::bool_switch(&disableSemanticTests)->default_value(disableSemanticTests), "disable semantic tests")
("no-smt", po::bool_switch(&disableSMT), "disable SMT checker") ("no-smt", po::bool_switch(&disableSMT)->default_value(disableSMT), "disable SMT checker")
("optimize", po::bool_switch(&optimize), "enables optimization") ("optimize", po::bool_switch(&optimize)->default_value(optimize), "enables optimization")
("enforce-via-yul", po::bool_switch(&enforceViaYul), "Enforce compiling all tests via yul to see if additional tests can be activated.") ("enforce-via-yul", po::value<bool>(&enforceViaYul)->default_value(enforceViaYul)->implicit_value(true), "Enforce compiling all tests via yul to see if additional tests can be activated.")
("enforce-compile-to-ewasm", po::bool_switch(&enforceCompileToEwasm), "Enforce compiling all tests to Ewasm to see if additional tests can be activated.") ("enforce-compile-to-ewasm", po::bool_switch(&enforceCompileToEwasm)->default_value(enforceCompileToEwasm), "Enforce compiling all tests to Ewasm to see if additional tests can be activated.")
("enforce-gas-cost", po::bool_switch(&enforceGasTest), "Enforce checking gas cost in semantic tests.") ("enforce-gas-cost", po::value<bool>(&enforceGasTest)->default_value(enforceGasTest)->implicit_value(true), "Enforce checking gas cost in semantic tests.")
("enforce-gas-cost-min-value", po::value(&enforceGasTestMinValue), "Threshold value to enforce adding gas checks to a test.") ("enforce-gas-cost-min-value", po::value(&enforceGasTestMinValue)->default_value(enforceGasTestMinValue), "Threshold value to enforce adding gas checks to a test.")
("abiencoderv1", po::bool_switch(&useABIEncoderV1), "enables abi encoder v1") ("abiencoderv1", po::bool_switch(&useABIEncoderV1)->default_value(useABIEncoderV1), "enables abi encoder v1")
("show-messages", po::bool_switch(&showMessages), "enables message output") ("show-messages", po::bool_switch(&showMessages)->default_value(showMessages), "enables message output")
("show-metadata", po::bool_switch(&showMetadata), "enables metadata output"); ("show-metadata", po::bool_switch(&showMetadata)->default_value(showMetadata), "enables metadata output");
} }
void CommonOptions::validate() const void CommonOptions::validate() const
@ -139,6 +144,7 @@ void CommonOptions::validate() const
bool CommonOptions::parse(int argc, char const* const* argv) bool CommonOptions::parse(int argc, char const* const* argv)
{ {
po::variables_map arguments; po::variables_map arguments;
addOptions();
po::command_line_parser cmdLineParser(argc, argv); po::command_line_parser cmdLineParser(argc, argv);
cmdLineParser.options(options); cmdLineParser.options(options);

View File

@ -70,6 +70,7 @@ struct CommonOptions
langutil::EVMVersion evmVersion() const; langutil::EVMVersion evmVersion() const;
virtual void addOptions();
virtual bool parse(int argc, char const* const* argv); virtual bool parse(int argc, char const* const* argv);
// Throws a ConfigException on error // Throws a ConfigException on error
virtual void validate() const; virtual void validate() const;

View File

@ -56,14 +56,21 @@ std::string editorPath()
} }
IsolTestOptions::IsolTestOptions(std::string* _editor): IsolTestOptions::IsolTestOptions():
CommonOptions(description) CommonOptions(description)
{ {
enforceViaYul = true;
enforceGasTest = (evmVersion() == langutil::EVMVersion{});
}
void IsolTestOptions::addOptions()
{
CommonOptions::addOptions();
options.add_options() options.add_options()
("editor", po::value<std::string>(_editor)->default_value(editorPath()), "Path to editor for opening test files.") ("editor", po::value<std::string>(&editor)->default_value(editorPath()), "Path to editor for opening test files.")
("help", po::bool_switch(&showHelp), "Show this help screen.") ("help", po::bool_switch(&showHelp)->default_value(showHelp), "Show this help screen.")
("no-color", po::bool_switch(&noColor), "Don't use colors.") ("no-color", po::bool_switch(&noColor)->default_value(noColor), "Don't use colors.")
("accept-updates", po::bool_switch(&acceptUpdates), "Automatically accept expectation updates.") ("accept-updates", po::bool_switch(&acceptUpdates)->default_value(acceptUpdates), "Automatically accept expectation updates.")
("test,t", po::value<std::string>(&testFilter)->default_value("*/*"), "Filters which test units to include."); ("test,t", po::value<std::string>(&testFilter)->default_value("*/*"), "Filters which test units to include.");
} }
@ -76,15 +83,13 @@ bool IsolTestOptions::parse(int _argc, char const* const* _argv)
std::cout << options << std::endl; std::cout << options << std::endl;
return false; return false;
} }
enforceViaYul = true;
enforceGasTest = (evmVersion() == langutil::EVMVersion{});
enforceGasTestMinValue = 100000;
return res; return res;
} }
void IsolTestOptions::validate() const void IsolTestOptions::validate() const
{ {
CommonOptions::validate();
static std::string filterString{"[a-zA-Z0-9_/*]*"}; static std::string filterString{"[a-zA-Z0-9_/*]*"};
static std::regex filterExpression{filterString}; static std::regex filterExpression{filterString};
assertThrow( assertThrow(

View File

@ -33,8 +33,10 @@ struct IsolTestOptions: CommonOptions
bool noColor = false; bool noColor = false;
bool acceptUpdates = false; bool acceptUpdates = false;
std::string testFilter = std::string{}; std::string testFilter = std::string{};
std::string editor = std::string{};
IsolTestOptions(std::string* _editor); explicit IsolTestOptions();
void addOptions() override;
bool parse(int _argc, char const* const* _argv) override; bool parse(int _argc, char const* const* _argv) override;
void validate() const override; void validate() const override;
}; };

View File

@ -121,8 +121,6 @@ public:
fs::path const& _basepath, fs::path const& _basepath,
fs::path const& _path fs::path const& _path
); );
static string editor;
private: private:
enum class Request enum class Request
{ {
@ -145,7 +143,6 @@ private:
static bool m_exitRequested; static bool m_exitRequested;
}; };
string TestTool::editor;
bool TestTool::m_exitRequested = false; bool TestTool::m_exitRequested = false;
TestTool::Result TestTool::process() TestTool::Result TestTool::process()
@ -258,7 +255,7 @@ TestTool::Request TestTool::handleResponse(bool _exception)
} }
case 'e': case 'e':
cout << endl << endl; cout << endl << endl;
if (system((TestTool::editor + " \"" + m_path.string() + "\"").c_str())) if (system((m_options.editor + " \"" + m_path.string() + "\"").c_str()))
cerr << "Error running editor command." << endl << endl; cerr << "Error running editor command." << endl << endl;
return Request::Rerun; return Request::Rerun;
case 'q': case 'q':
@ -425,7 +422,7 @@ int main(int argc, char const *argv[])
setupTerminal(); setupTerminal();
{ {
auto options = std::make_unique<solidity::test::IsolTestOptions>(&TestTool::editor); auto options = std::make_unique<solidity::test::IsolTestOptions>();
if (!options->parse(argc, argv)) if (!options->parse(argc, argv))
return -1; return -1;