11// Author: Diffblue Ltd.
22
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>
410
511#include < solvers/smt2_incremental/smt2_incremental_decision_procedure.h>
612#include < solvers/smt2_incremental/smt_commands.h>
1016#include < solvers/smt2_incremental/smt_sorts.h>
1117#include < solvers/smt2_incremental/smt_terms.h>
1218#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>
1920
2021// Used by catch framework for printing in the case of test failures. This
2122// means that we get error messages showing the smt formula expressed as SMT2
@@ -104,12 +105,26 @@ struct decision_procedure_test_environmentt final
104105 std::deque<smt_responset> mock_responses;
105106 std::vector<smt_commandt> sent_commands;
106107 null_message_handlert message_handler;
108+ smt_object_sizet object_size_function;
107109 smt2_incremental_decision_proceduret procedure{
108110 ns,
109111 util_make_unique<smt_mock_solver_processt>(
110112 [&](const smt_commandt &smt_command) { this ->send (smt_command); },
111113 [&]() { return this ->receive_response (); }),
112114 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 ;
113128};
114129
115130void decision_procedure_test_environmentt::send (const smt_commandt &smt_command)
@@ -147,17 +162,16 @@ TEST_CASE(
147162 " smt2_incremental_decision_proceduret commands sent" ,
148163 " [core][smt2_incremental]" )
149164{
150- decision_procedure_test_environmentt test{} ;
165+ auto test = decision_procedure_test_environmentt::make () ;
151166 SECTION (" Construction / solver initialisation." )
152167 {
153- smt_object_sizet object_size_function;
154168 REQUIRE (
155169 test.sent_commands ==
156170 std::vector<smt_commandt>{
157171 smt_set_option_commandt{smt_option_produce_modelst{true }},
158172 smt_set_logic_commandt{
159173 smt_logic_quantifier_free_uninterpreted_functions_bit_vectorst{}},
160- object_size_function.declaration });
174+ test. object_size_function .declaration });
161175 test.sent_commands .clear ();
162176 SECTION (" Set symbol to true." )
163177 {
@@ -296,7 +310,7 @@ TEST_CASE(
296310 " smt2_incremental_decision_proceduret number of solver calls." ,
297311 " [core][smt2_incremental]" )
298312{
299- decision_procedure_test_environmentt test{} ;
313+ auto test = decision_procedure_test_environmentt::make () ;
300314 REQUIRE (test.procedure .get_number_of_solver_calls () == 0 );
301315 test.mock_responses .push_back (smt_check_sat_responset{smt_unsat_responset{}});
302316 test.procedure ();
@@ -311,7 +325,7 @@ TEST_CASE(
311325 " internal decision_proceduret::resultt" ,
312326 " [core][smt2_incremental]" )
313327{
314- decision_procedure_test_environmentt test{} ;
328+ auto test = decision_procedure_test_environmentt::make () ;
315329 SECTION (" sat" )
316330 {
317331 test.mock_responses = {smt_check_sat_responset{smt_sat_responset{}}};
@@ -334,7 +348,7 @@ TEST_CASE(
334348 " response." ,
335349 " [core][smt2_incremental]" )
336350{
337- decision_procedure_test_environmentt test{} ;
351+ auto test = decision_procedure_test_environmentt::make () ;
338352 SECTION (" Expected success response." )
339353 {
340354 test.mock_responses = {smt_success_responset{},
@@ -359,7 +373,7 @@ TEST_CASE(
359373 " check-sat." ,
360374 " [core][smt2_incremental]" )
361375{
362- decision_procedure_test_environmentt test{} ;
376+ auto test = decision_procedure_test_environmentt::make () ;
363377 SECTION (" get-value response" )
364378 {
365379 test.mock_responses = {
@@ -394,7 +408,10 @@ TEST_CASE(
394408 " smt2_incremental_decision_proceduret getting values back from solver." ,
395409 " [core][smt2_incremental]" )
396410{
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 });
398415 const symbolt foo = make_test_symbol (" foo" , signedbv_typet{16 });
399416 const smt_identifier_termt foo_term{" foo" , smt_bit_vector_sortt{16 }};
400417 const exprt expr_42 = from_integer ({42 }, signedbv_typet{16 });
@@ -411,6 +428,7 @@ TEST_CASE(
411428 std::vector<smt_commandt>{
412429 smt_declare_function_commandt{foo_term, {}},
413430 smt_assert_commandt{smt_core_theoryt::equal (foo_term, term_42)},
431+ null_object_size_definition,
414432 smt_check_sat_commandt{}});
415433 SECTION (" Get \" foo\" value back" )
416434 {
0 commit comments