solidity/test/libsolidity/SMTCheckerTest.cpp

93 lines
2.8 KiB
C++
Raw Normal View History

2019-12-03 15:50:28 +00:00
/*
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/>.
*/
// SPDX-License-Identifier: GPL-3.0
2019-12-03 15:50:28 +00:00
#include <test/libsolidity/SMTCheckerTest.h>
#include <test/Common.h>
2019-12-03 15:50:28 +00:00
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
using namespace solidity::frontend;
using namespace solidity::frontend::test;
2019-12-03 15:50:28 +00:00
2020-07-10 09:22:57 +00:00
SMTCheckerTest::SMTCheckerTest(string const& _filename): SyntaxTest(_filename, EVMVersion{})
2019-12-03 15:50:28 +00:00
{
2020-03-06 00:22:51 +00:00
auto const& choice = m_reader.stringSetting("SMTSolvers", "any");
if (choice == "any")
2020-05-19 12:14:46 +00:00
m_enabledSolvers = smtutil::SMTSolverChoice::All();
2020-03-06 00:22:51 +00:00
else if (choice == "z3")
2020-05-19 12:14:46 +00:00
m_enabledSolvers = smtutil::SMTSolverChoice::Z3();
2020-03-06 00:22:51 +00:00
else if (choice == "cvc4")
2020-05-19 12:14:46 +00:00
m_enabledSolvers = smtutil::SMTSolverChoice::CVC4();
2020-03-06 00:22:51 +00:00
else if (choice == "none")
2020-05-19 12:14:46 +00:00
m_enabledSolvers = smtutil::SMTSolverChoice::None();
2020-03-06 00:22:51 +00:00
else
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT solver choice."));
2020-02-18 16:13:13 +00:00
auto available = ModelChecker::availableSolvers();
if (!available.z3)
m_enabledSolvers.z3 = false;
if (!available.cvc4)
m_enabledSolvers.cvc4 = false;
auto engine = ModelCheckerEngine::fromString(m_reader.stringSetting("SMTEngine", "all"));
if (engine)
m_modelCheckerSettings.engine = *engine;
else
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT engine choice."));
if (m_enabledSolvers.none() || m_modelCheckerSettings.engine.none())
2020-02-18 16:13:13 +00:00
m_shouldRun = false;
auto const& ignoreCex = m_reader.stringSetting("SMTIgnoreCex", "no");
if (ignoreCex == "no")
m_ignoreCex = false;
else if (ignoreCex == "yes")
m_ignoreCex = true;
else
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT counterexample choice."));
2019-12-03 15:50:28 +00:00
}
TestCase::TestResult SMTCheckerTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
{
setupCompiler();
compiler().setSMTSolverChoice(m_enabledSolvers);
compiler().setModelCheckerSettings(m_modelCheckerSettings);
2019-12-03 15:50:28 +00:00
parseAndAnalyze();
filterObtainedErrors();
return conclude(_stream, _linePrefix, _formatted);
2019-12-03 15:50:28 +00:00
}
void SMTCheckerTest::filterObtainedErrors()
{
SyntaxTest::filterObtainedErrors();
static auto removeCex = [](vector<SyntaxTestError>& errors) {
for (auto& e: errors)
if (
auto cexPos = e.message.find("\\nCounterexample");
cexPos != string::npos
)
e.message = e.message.substr(0, cexPos);
};
if (m_ignoreCex)
removeCex(m_errorList);
}