Add SMTCheckerTest for isoltest

This commit is contained in:
Leonardo Alt
2019-12-09 15:32:08 +01:00
parent 3e8584bd21
commit 225041738e
14 changed files with 204 additions and 35 deletions
+2
View File
@@ -91,6 +91,8 @@ set(libsolidity_sources
libsolidity/SMTChecker.cpp
libsolidity/SMTCheckerJSONTest.cpp
libsolidity/SMTCheckerJSONTest.h
libsolidity/SMTCheckerTest.cpp
libsolidity/SMTCheckerTest.h
libsolidity/SolidityCompiler.cpp
libsolidity/SolidityEndToEndTest.cpp
libsolidity/SolidityExecutionFramework.cpp
+3 -2
View File
@@ -23,6 +23,7 @@
#include <test/libsolidity/GasTest.h>
#include <test/libsolidity/SyntaxTest.h>
#include <test/libsolidity/SemanticTest.h>
#include <test/libsolidity/SMTCheckerTest.h>
#include <test/libsolidity/SMTCheckerJSONTest.h>
#include <test/libyul/EWasmTranslationTest.h>
#include <test/libyul/YulOptimizerTest.h>
@@ -65,8 +66,8 @@ Testsuite const g_interactiveTestsuites[] = {
{"Semantic", "libsolidity", "semanticTests", false, true, &SemanticTest::create},
{"JSON AST", "libsolidity", "ASTJSON", false, false, &ASTJSONTest::create},
{"JSON ABI", "libsolidity", "ABIJson", false, false, &ABIJsonTest::create},
{"SMT Checker", "libsolidity", "smtCheckerTests", true, false, &SyntaxTest::create},
{"SMT Checker JSON", "libsolidity", "smtCheckerTestsJSON", true, false, &SMTCheckerTest::create},
{"SMT Checker", "libsolidity", "smtCheckerTests", true, false, &SMTCheckerTest::create},
{"SMT Checker JSON", "libsolidity", "smtCheckerTestsJSON", true, false, &SMTCheckerJSONTest::create},
{"Gas Estimates", "libsolidity", "gasTests", false, false, &GasTest::create}
};
+4 -4
View File
@@ -36,7 +36,7 @@ using namespace dev;
using namespace std;
using namespace boost::unit_test;
SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _evmVersion)
SMTCheckerJSONTest::SMTCheckerJSONTest(string const& _filename, langutil::EVMVersion _evmVersion)
: SyntaxTest(_filename, _evmVersion)
{
if (!boost::algorithm::ends_with(_filename, ".sol"))
@@ -50,7 +50,7 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _ev
BOOST_THROW_EXCEPTION(runtime_error("Invalid JSON file."));
}
TestCase::TestResult SMTCheckerTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
TestCase::TestResult SMTCheckerJSONTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
{
StandardCompiler compiler;
@@ -129,7 +129,7 @@ TestCase::TestResult SMTCheckerTest::run(ostream& _stream, string const& _linePr
return printExpectationAndError(_stream, _linePrefix, _formatted) ? TestResult::Success : TestResult::Failure;
}
vector<string> SMTCheckerTest::hashesFromJson(Json::Value const& _jsonObj, string const& _auxInput, string const& _smtlib)
vector<string> SMTCheckerJSONTest::hashesFromJson(Json::Value const& _jsonObj, string const& _auxInput, string const& _smtlib)
{
vector<string> hashes;
Json::Value const& auxInputs = _jsonObj[_auxInput];
@@ -143,7 +143,7 @@ vector<string> SMTCheckerTest::hashesFromJson(Json::Value const& _jsonObj, strin
return hashes;
}
Json::Value SMTCheckerTest::buildJson(string const& _extra)
Json::Value SMTCheckerJSONTest::buildJson(string const& _extra)
{
string language = "\"language\": \"Solidity\"";
string sources = " \"sources\": { ";
+3 -3
View File
@@ -30,14 +30,14 @@ namespace solidity
namespace test
{
class SMTCheckerTest: public SyntaxTest
class SMTCheckerJSONTest: public SyntaxTest
{
public:
static std::unique_ptr<TestCase> create(Config const& _config)
{
return std::make_unique<SMTCheckerTest>(_config.filename, _config.evmVersion);
return std::make_unique<SMTCheckerJSONTest>(_config.filename, _config.evmVersion);
}
SMTCheckerTest(std::string const& _filename, langutil::EVMVersion _evmVersion);
SMTCheckerJSONTest(std::string const& _filename, langutil::EVMVersion _evmVersion);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
+71
View File
@@ -0,0 +1,71 @@
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
#include <test/libsolidity/SMTCheckerTest.h>
#include <test/Options.h>
#include <libsolidity/formal/ModelChecker.h>
using namespace langutil;
using namespace dev::solidity;
using namespace dev::solidity::test;
using namespace dev;
using namespace std;
SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _evmVersion): SyntaxTest(_filename, _evmVersion)
{
if (m_settings.count("SMTSolvers"))
{
auto const& choice = m_settings.at("SMTSolvers");
if (choice == "any")
m_enabledSolvers = smt::SMTSolverChoice::All();
else if (choice == "z3")
m_enabledSolvers = smt::SMTSolverChoice::Z3();
else if (choice == "cvc4")
m_enabledSolvers = smt::SMTSolverChoice::CVC4();
else if (choice == "none")
m_enabledSolvers = smt::SMTSolverChoice::None();
else
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT solver choice."));
}
else
m_enabledSolvers = smt::SMTSolverChoice::All();
}
TestCase::TestResult SMTCheckerTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
{
setupCompiler();
compiler().setSMTSolverChoice(m_enabledSolvers);
parseAndAnalyze();
filterObtainedErrors();
return printExpectationAndError(_stream, _linePrefix, _formatted) ? TestResult::Success : TestResult::Failure;
}
bool SMTCheckerTest::validateSettings(langutil::EVMVersion _evmVersion)
{
auto available = ModelChecker::availableSolvers();
if (!available.z3)
m_enabledSolvers.z3 = false;
if (!available.cvc4)
m_enabledSolvers.cvc4 = false;
if (m_enabledSolvers.none())
return false;
return SyntaxTest::validateSettings(_evmVersion);
}
+55
View File
@@ -0,0 +1,55 @@
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <test/libsolidity/SyntaxTest.h>
#include <libsolidity/formal/SolverInterface.h>
#include <string>
namespace dev
{
namespace solidity
{
namespace test
{
class SMTCheckerTest: public SyntaxTest
{
public:
static std::unique_ptr<TestCase> create(Config const& _config)
{
return std::make_unique<SMTCheckerTest>(_config.filename, _config.evmVersion);
}
SMTCheckerTest(std::string const& _filename, langutil::EVMVersion _evmVersion);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
bool validateSettings(langutil::EVMVersion _evmVersion) override;
protected:
/// This is set via option SMTSolvers in the test.
/// The possible options are `all`, `z3`, `cvc4`, `none`,
/// where if none is given the default used option is `all`.
smt::SMTSolverChoice m_enabledSolvers;
};
}
}
}
+16 -17
View File
@@ -176,23 +176,22 @@ void SyntaxTest::setupCompiler()
void SyntaxTest::parseAndAnalyze()
{
if (compiler().parse())
if (compiler().analyze())
try
{
if (!compiler().compile())
BOOST_THROW_EXCEPTION(runtime_error("Compilation failed even though analysis was successful."));
}
catch (UnimplementedFeatureError const& _e)
{
m_errorList.emplace_back(SyntaxTestError{
"UnimplementedFeatureError",
errorMessage(_e),
"",
-1,
-1
});
}
if (compiler().parse() && compiler().analyze())
try
{
if (!compiler().compile())
BOOST_THROW_EXCEPTION(runtime_error("Compilation failed even though analysis was successful."));
}
catch (UnimplementedFeatureError const& _e)
{
m_errorList.emplace_back(SyntaxTestError{
"UnimplementedFeatureError",
errorMessage(_e),
"",
-1,
-1
});
}
}
void SyntaxTest::filterObtainedErrors()
+1
View File
@@ -29,6 +29,7 @@ add_executable(isoltest
../ExecutionFramework.cpp
../libsolidity/ABIJsonTest.cpp
../libsolidity/ASTJSONTest.cpp
../libsolidity/SMTCheckerTest.cpp
../libsolidity/SMTCheckerJSONTest.cpp
../libyul/Common.cpp
../libyul/EWasmTranslationTest.cpp