GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/test_smt.h Lines: 39 68 57.4 %
Date: 2021-09-17 Branches: 29 149 19.5 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Aina Niemetz, Andrew Reynolds, Haniel Barbosa
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Common header for unit tests that need an SmtEngine.
14
 */
15
16
#ifndef CVC5__TEST__UNIT__TEST_SMT_H
17
#define CVC5__TEST__UNIT__TEST_SMT_H
18
19
#include "expr/dtype_cons.h"
20
#include "expr/node.h"
21
#include "expr/node_manager.h"
22
#include "expr/skolem_manager.h"
23
#include "proof/proof_checker.h"
24
#include "smt/smt_engine.h"
25
#include "smt/smt_engine_scope.h"
26
#include "test.h"
27
#include "theory/output_channel.h"
28
#include "theory/rewriter.h"
29
#include "theory/theory.h"
30
#include "theory/theory_state.h"
31
#include "theory/valuation.h"
32
#include "util/resource_manager.h"
33
#include "util/unsafe_interrupt_exception.h"
34
35
namespace cvc5 {
36
namespace test {
37
38
/* -------------------------------------------------------------------------- */
39
/* Test fixtures.                                                             */
40
/* -------------------------------------------------------------------------- */
41
42
648
class TestSmt : public TestInternal
43
{
44
 protected:
45
324
  void SetUp() override
46
  {
47
324
    d_nodeManager.reset(new NodeManager());
48
324
    d_skolemManager = d_nodeManager->getSkolemManager();
49
324
    d_nmScope.reset(new NodeManagerScope(d_nodeManager.get()));
50
324
    d_smtEngine.reset(new SmtEngine(d_nodeManager.get()));
51
324
    d_smtEngine->finishInit();
52
324
  }
53
54
  std::unique_ptr<NodeManagerScope> d_nmScope;
55
  std::unique_ptr<NodeManager> d_nodeManager;
56
  SkolemManager* d_skolemManager;
57
  std::unique_ptr<SmtEngine> d_smtEngine;
58
};
59
60
1120
class TestSmtNoFinishInit : public TestInternal
61
{
62
 protected:
63
560
  void SetUp() override
64
  {
65
560
    d_nodeManager.reset(new NodeManager());
66
560
    d_skolemManager = d_nodeManager->getSkolemManager();
67
560
    d_nmScope.reset(new NodeManagerScope(d_nodeManager.get()));
68
560
    d_smtEngine.reset(new SmtEngine(d_nodeManager.get()));
69
560
  }
70
71
  std::unique_ptr<NodeManagerScope> d_nmScope;
72
  std::unique_ptr<NodeManager> d_nodeManager;
73
  SkolemManager* d_skolemManager;
74
  std::unique_ptr<SmtEngine> d_smtEngine;
75
};
76
77
/* -------------------------------------------------------------------------- */
78
/* Helpers.                                                                   */
79
/* -------------------------------------------------------------------------- */
80
81
/**
82
 * Very basic OutputChannel for testing simple Theory Behaviour.
83
 * Stores a call sequence for the output channel
84
 */
85
enum OutputChannelCallType
86
{
87
  CONFLICT,
88
  PROPAGATE,
89
  PROPAGATE_AS_DECISION,
90
  AUG_LEMMA,
91
  LEMMA,
92
  EXPLANATION
93
};
94
95
inline std::ostream& operator<<(std::ostream& out, OutputChannelCallType type)
96
{
97
  switch (type)
98
  {
99
    case CONFLICT: return out << "CONFLICT";
100
    case PROPAGATE: return out << "PROPAGATE";
101
    case PROPAGATE_AS_DECISION: return out << "PROPAGATE_AS_DECISION";
102
    case AUG_LEMMA: return out << "AUG_LEMMA";
103
    case LEMMA: return out << "LEMMA";
104
    case EXPLANATION: return out << "EXPLANATION";
105
    default: return out << "UNDEFINED-OutputChannelCallType!" << int(type);
106
  }
107
}
108
109
class DummyOutputChannel : public cvc5::theory::OutputChannel
110
{
111
 public:
112
6
  DummyOutputChannel() {}
113
6
  ~DummyOutputChannel() override {}
114
115
  void safePoint(Resource r) override {}
116
  void conflict(TNode n) override { push(CONFLICT, n); }
117
118
  void trustedConflict(TrustNode n) override { push(CONFLICT, n.getNode()); }
119
120
  bool propagate(TNode n) override
121
  {
122
    push(PROPAGATE, n);
123
    return true;
124
  }
125
126
4
  void lemma(TNode n,
127
             theory::LemmaProperty p = theory::LemmaProperty::NONE) override
128
  {
129
4
    push(LEMMA, n);
130
4
  }
131
132
  void trustedLemma(TrustNode n, theory::LemmaProperty p) override
133
  {
134
    push(LEMMA, n.getNode());
135
  }
136
137
  void requirePhase(TNode, bool) override {}
138
  void setIncomplete(theory::IncompleteId id) override {}
139
140
6
  void clear() { d_callHistory.clear(); }
141
142
  Node getIthNode(int i) const
143
  {
144
    Node tmp = (d_callHistory[i]).second;
145
    return tmp;
146
  }
147
148
  OutputChannelCallType getIthCallType(int i) const
149
  {
150
    return (d_callHistory[i]).first;
151
  }
152
153
  unsigned getNumCalls() const { return d_callHistory.size(); }
154
155
  void printIth(std::ostream& os, int i) const
156
  {
157
    os << "[DummyOutputChannel " << i;
158
    os << " " << getIthCallType(i);
159
    os << " " << getIthNode(i) << "]";
160
  }
161
162
 private:
163
4
  void push(OutputChannelCallType call, TNode n)
164
  {
165
4
    d_callHistory.push_back(std::make_pair(call, n));
166
4
  }
167
168
  std::vector<std::pair<enum OutputChannelCallType, Node> > d_callHistory;
169
};
170
171
/* -------------------------------------------------------------------------- */
172
173
84
class DummyTheoryRewriter : public theory::TheoryRewriter
174
{
175
 public:
176
48
  theory::RewriteResponse preRewrite(TNode n) override
177
  {
178
48
    return theory::RewriteResponse(theory::REWRITE_DONE, n);
179
  }
180
181
96
  theory::RewriteResponse postRewrite(TNode n) override
182
  {
183
96
    return theory::RewriteResponse(theory::REWRITE_DONE, n);
184
  }
185
};
186
187
class DummyProofRuleChecker : public ProofRuleChecker
188
{
189
 public:
190
42
  DummyProofRuleChecker() {}
191
42
  ~DummyProofRuleChecker() {}
192
  void registerTo(ProofChecker* pc) override {}
193
194
 protected:
195
  Node checkInternal(PfRule id,
196
                     const std::vector<Node>& children,
197
                     const std::vector<Node>& args) override
198
  {
199
    return Node::null();
200
  }
201
};
202
203
/** Dummy Theory interface.  */
204
template <theory::TheoryId theoryId>
205
84
class DummyTheory : public theory::Theory
206
{
207
 public:
208
42
  DummyTheory(Env& env, theory::OutputChannel& out, theory::Valuation valuation)
209
      : Theory(theoryId, env, out, valuation),
210
42
        d_state(env, valuation)
211
  {
212
    // use a default theory state object
213
42
    d_theoryState = &d_state;
214
42
  }
215
216
36
  theory::TheoryRewriter* getTheoryRewriter() override { return &d_rewriter; }
217
  ProofRuleChecker* getProofChecker() override { return &d_checker; }
218
219
  void registerTerm(TNode n)
220
  {
221
    // check that we registerTerm() a term only once
222
    ASSERT_TRUE(d_registered.find(n) == d_registered.end());
223
224
    for (TNode::iterator i = n.begin(); i != n.end(); ++i)
225
    {
226
      // check that registerTerm() is called in reverse topological order
227
      ASSERT_TRUE(d_registered.find(*i) != d_registered.end());
228
    }
229
230
    d_registered.insert(n);
231
  }
232
233
  void presolve() override { Unimplemented(); }
234
  void preRegisterTerm(TNode n) override { Unimplemented(); }
235
  void propagate(Effort level) override { Unimplemented(); }
236
4
  bool preNotifyFact(
237
      TNode atom, bool pol, TNode fact, bool isPrereg, bool isInternal) override
238
  {
239
    // do not assert to equality engine, since this theory does not use one
240
4
    return true;
241
  }
242
  TrustNode explain(TNode n) override { return TrustNode::null(); }
243
  Node getValue(TNode n) { return Node::null(); }
244
  std::string identify() const override { return "DummyTheory" + d_id; }
245
246
  std::set<Node> d_registered;
247
248
 private:
249
  /** Default theory state object */
250
  theory::TheoryState d_state;
251
  /**
252
   * This fake theory class is equally useful for bool, uf, arith, etc.  It
253
   * keeps an identifier to identify itself.
254
   */
255
  std::string d_id;
256
  /** The theory rewriter for this theory. */
257
  DummyTheoryRewriter d_rewriter;
258
  /** The proof checker for this theory. */
259
  DummyProofRuleChecker d_checker;
260
};
261
262
/* -------------------------------------------------------------------------- */
263
}  // namespace test
264
}  // namespace cvc5
265
#endif