Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SmtSolverFactoryTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
12
13#ifdef STORM_HAVE_MATHSAT
15#endif
16#ifdef STORM_HAVE_Z3
18#endif
19
20TEST(SmtSolverFactory, EnvironmentIsSeededFromSettings) {
22
23 // The environment picks up the SMT solver that is selected in the core settings.
27}
28
29// These two need an SMT solver that is available and differs from the compile-time default, so that a
30// solver of that type can only be the result of the selection made in the environment. Both the
31// enumeration value and the concrete type are only defined when that solver is actually compiled in.
32#if defined STORM_HAVE_MATHSAT && !defined STORM_DEFAULT_SMT_SOLVER_MATHSAT
33#define STORM_TEST_ALTERNATIVE_SMT_SOLVER storm::solver::SmtSolverType::Mathsat
34#define STORM_TEST_ALTERNATIVE_SMT_SOLVER_TYPE storm::solver::MathsatSmtSolver
35#elif defined STORM_HAVE_Z3 && !defined STORM_DEFAULT_SMT_SOLVER_Z3
36#define STORM_TEST_ALTERNATIVE_SMT_SOLVER storm::solver::SmtSolverType::Z3
37#define STORM_TEST_ALTERNATIVE_SMT_SOLVER_TYPE storm::solver::Z3SmtSolver
38#endif
39
40#ifdef STORM_TEST_ALTERNATIVE_SMT_SOLVER
41TEST(SmtSolverFactory, EnvironmentOverridesSmtSolver) {
43 std::shared_ptr<storm::expressions::ExpressionManager> manager(new storm::expressions::ExpressionManager());
44
45 env.solver().setSmtSolverType(STORM_TEST_ALTERNATIVE_SMT_SOLVER);
46 EXPECT_EQ(env.solver().getSmtSolverType(), STORM_TEST_ALTERNATIVE_SMT_SOLVER);
47 EXPECT_FALSE(env.solver().isSmtSolverTypeSetFromDefaultValue());
48
49 // An SMT solver that was selected explicitly in the environment takes precedence over the core setting.
50 std::unique_ptr<storm::solver::SmtSolver> solver = storm::utility::solver::getSmtSolver(env, *manager);
51 ASSERT_NE(solver, nullptr);
52 EXPECT_NE(dynamic_cast<STORM_TEST_ALTERNATIVE_SMT_SOLVER_TYPE*>(solver.get()), nullptr);
53}
54
55TEST(SmtSolverFactory, EnvironmentSelectionIsUsedEvenIfSeededFromDefault) {
57 std::shared_ptr<storm::expressions::ExpressionManager> manager(new storm::expressions::ExpressionManager());
58
59 // The environment is the single place where the core setting is turned into a solver selection, so
60 // the solver stored in it is used even if the value was seeded from the default of the setting.
61 env.solver().setSmtSolverType(STORM_TEST_ALTERNATIVE_SMT_SOLVER, true);
62 EXPECT_EQ(env.solver().getSmtSolverType(), STORM_TEST_ALTERNATIVE_SMT_SOLVER);
63 EXPECT_TRUE(env.solver().isSmtSolverTypeSetFromDefaultValue());
64
65 std::unique_ptr<storm::solver::SmtSolver> solver = storm::utility::solver::getSmtSolver(env, *manager);
66 ASSERT_NE(solver, nullptr);
67 EXPECT_NE(dynamic_cast<STORM_TEST_ALTERNATIVE_SMT_SOLVER_TYPE*>(solver.get()), nullptr);
68}
69#endif
70
71#if defined STORM_DEFAULT_SMT_SOLVER_Z3 || defined STORM_DEFAULT_SMT_SOLVER_MATHSAT
72TEST(SmtSolverFactory, WithoutEnvironmentTheCompileTimeDefaultIsUsed) {
73 std::shared_ptr<storm::expressions::ExpressionManager> manager(new storm::expressions::ExpressionManager());
74
75 // Without an environment, there is no setting to consult, so the compile-time default is used.
76 std::unique_ptr<storm::solver::SmtSolver> solver = storm::utility::solver::getSmtSolver(*manager);
77 ASSERT_NE(solver, nullptr);
78#ifdef STORM_DEFAULT_SMT_SOLVER_Z3
79 EXPECT_NE(dynamic_cast<storm::solver::Z3SmtSolver*>(solver.get()), nullptr);
80#else
81 EXPECT_NE(dynamic_cast<storm::solver::MathsatSmtSolver*>(solver.get()), nullptr);
82#endif
83}
84#endif
TEST(SmtSolverFactory, EnvironmentIsSeededFromSettings)
SolverEnvironment & solver()
bool isSmtSolverTypeSetFromDefaultValue() const
storm::solver::SmtSolverType const & getSmtSolverType() const
Retrieves the SMT solver that is currently selected.
void setSmtSolverType(storm::solver::SmtSolverType const &value, bool isSetFromDefault=false)
This class is responsible for managing a set of typed variables and all expressions using these varia...
SettingsType const & getModule()
Get module.
SettingsManager const & manager()
Retrieves the settings manager.
std::unique_ptr< storm::solver::SmtSolver > getSmtSolver(storm::expressions::ExpressionManager &manager)
Definition solver.cpp:215