1
1
// Author: Diffblue Ltd.
2
2
3
- #include < testing-utils/use_catch.h>
3
+ #include < util/arith_tools.h>
4
+ #include < util/bitvector_types.h>
5
+ #include < util/config.h>
6
+ #include < util/exception_utils.h>
7
+ #include < util/make_unique.h>
8
+ #include < util/namespace.h>
9
+ #include < util/symbol_table.h>
4
10
5
11
#include < solvers/smt2_incremental/smt2_incremental_decision_procedure.h>
6
12
#include < solvers/smt2_incremental/smt_commands.h>
10
16
#include < solvers/smt2_incremental/smt_sorts.h>
11
17
#include < solvers/smt2_incremental/smt_terms.h>
12
18
#include < testing-utils/invariant.h>
13
- #include < util/arith_tools.h>
14
- #include < util/bitvector_types.h>
15
- #include < util/exception_utils.h>
16
- #include < util/make_unique.h>
17
- #include < util/namespace.h>
18
- #include < util/symbol_table.h>
19
+ #include < testing-utils/use_catch.h>
19
20
20
21
// Used by catch framework for printing in the case of test failures. This
21
22
// means that we get error messages showing the smt formula expressed as SMT2
@@ -104,12 +105,26 @@ struct decision_procedure_test_environmentt final
104
105
std::deque<smt_responset> mock_responses;
105
106
std::vector<smt_commandt> sent_commands;
106
107
null_message_handlert message_handler;
108
+ smt_object_sizet object_size_function;
107
109
smt2_incremental_decision_proceduret procedure{
108
110
ns,
109
111
util_make_unique<smt_mock_solver_processt>(
110
112
[&](const smt_commandt &smt_command) { this ->send (smt_command); },
111
113
[&]() { return this ->receive_response (); }),
112
114
message_handler};
115
+ static decision_procedure_test_environmentt make ()
116
+ {
117
+ // These config lines are necessary before construction because pointer
118
+ // widths and object bit width encodings depend on the global configuration.
119
+ config.ansi_c .mode = configt::ansi_ct::flavourt::GCC;
120
+ config.ansi_c .set_arch_spec_i386 ();
121
+ return {};
122
+ }
123
+
124
+ private:
125
+ // This is private to ensure the above make() function is used to make
126
+ // correctly configured instances.
127
+ decision_procedure_test_environmentt () = default ;
113
128
};
114
129
115
130
void decision_procedure_test_environmentt::send (const smt_commandt &smt_command)
@@ -147,17 +162,16 @@ TEST_CASE(
147
162
" smt2_incremental_decision_proceduret commands sent" ,
148
163
" [core][smt2_incremental]" )
149
164
{
150
- decision_procedure_test_environmentt test{} ;
165
+ auto test = decision_procedure_test_environmentt::make () ;
151
166
SECTION (" Construction / solver initialisation." )
152
167
{
153
- smt_object_sizet object_size_function;
154
168
REQUIRE (
155
169
test.sent_commands ==
156
170
std::vector<smt_commandt>{
157
171
smt_set_option_commandt{smt_option_produce_modelst{true }},
158
172
smt_set_logic_commandt{
159
173
smt_logic_quantifier_free_uninterpreted_functions_bit_vectorst{}},
160
- object_size_function.declaration });
174
+ test. object_size_function .declaration });
161
175
test.sent_commands .clear ();
162
176
SECTION (" Set symbol to true." )
163
177
{
@@ -296,7 +310,7 @@ TEST_CASE(
296
310
" smt2_incremental_decision_proceduret number of solver calls." ,
297
311
" [core][smt2_incremental]" )
298
312
{
299
- decision_procedure_test_environmentt test{} ;
313
+ auto test = decision_procedure_test_environmentt::make () ;
300
314
REQUIRE (test.procedure .get_number_of_solver_calls () == 0 );
301
315
test.mock_responses .push_back (smt_check_sat_responset{smt_unsat_responset{}});
302
316
test.procedure ();
@@ -311,7 +325,7 @@ TEST_CASE(
311
325
" internal decision_proceduret::resultt" ,
312
326
" [core][smt2_incremental]" )
313
327
{
314
- decision_procedure_test_environmentt test{} ;
328
+ auto test = decision_procedure_test_environmentt::make () ;
315
329
SECTION (" sat" )
316
330
{
317
331
test.mock_responses = {smt_check_sat_responset{smt_sat_responset{}}};
@@ -334,7 +348,7 @@ TEST_CASE(
334
348
" response." ,
335
349
" [core][smt2_incremental]" )
336
350
{
337
- decision_procedure_test_environmentt test{} ;
351
+ auto test = decision_procedure_test_environmentt::make () ;
338
352
SECTION (" Expected success response." )
339
353
{
340
354
test.mock_responses = {smt_success_responset{},
@@ -359,7 +373,7 @@ TEST_CASE(
359
373
" check-sat." ,
360
374
" [core][smt2_incremental]" )
361
375
{
362
- decision_procedure_test_environmentt test{} ;
376
+ auto test = decision_procedure_test_environmentt::make () ;
363
377
SECTION (" get-value response" )
364
378
{
365
379
test.mock_responses = {
@@ -394,7 +408,10 @@ TEST_CASE(
394
408
" smt2_incremental_decision_proceduret getting values back from solver." ,
395
409
" [core][smt2_incremental]" )
396
410
{
397
- decision_procedure_test_environmentt test{};
411
+ auto test = decision_procedure_test_environmentt::make ();
412
+ const auto null_object_size_definition =
413
+ test.object_size_function .make_definition (
414
+ 0 , smt_bit_vector_constant_termt{0 , 32 });
398
415
const symbolt foo = make_test_symbol (" foo" , signedbv_typet{16 });
399
416
const smt_identifier_termt foo_term{" foo" , smt_bit_vector_sortt{16 }};
400
417
const exprt expr_42 = from_integer ({42 }, signedbv_typet{16 });
@@ -411,6 +428,7 @@ TEST_CASE(
411
428
std::vector<smt_commandt>{
412
429
smt_declare_function_commandt{foo_term, {}},
413
430
smt_assert_commandt{smt_core_theoryt::equal (foo_term, term_42)},
431
+ null_object_size_definition,
414
432
smt_check_sat_commandt{}});
415
433
SECTION (" Get \" foo\" value back" )
416
434
{
0 commit comments