Skip to content

Commit a4e0df8

Browse files
committed
Add unit test of the get function
1 parent 8066fb7 commit a4e0df8

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

unit/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,70 @@ TEST_CASE(
386386
"SMT solver does not support given command."});
387387
}
388388
}
389+
390+
TEST_CASE(
391+
"smt2_incremental_decision_proceduret getting values back from solver.",
392+
"[core][smt2_incremental]")
393+
{
394+
decision_procedure_test_environmentt test{};
395+
const symbolt foo = make_test_symbol("foo", signedbv_typet{16});
396+
const smt_identifier_termt foo_term{"foo", smt_bit_vector_sortt{16}};
397+
const exprt expr_42 = from_integer({42}, signedbv_typet{16});
398+
const smt_bit_vector_constant_termt term_42{42, 16};
399+
SECTION("Set \"foo\" identifier and solve.")
400+
{
401+
test.sent_commands.clear();
402+
const exprt equal_42 = equal_exprt{foo.symbol_expr(), expr_42};
403+
test.procedure.set_to(equal_42, true);
404+
test.mock_responses.push_back(smt_check_sat_responset{smt_sat_responset{}});
405+
test.procedure();
406+
REQUIRE(
407+
test.sent_commands ==
408+
std::vector<smt_commandt>{
409+
smt_declare_function_commandt{foo_term, {}},
410+
smt_assert_commandt{smt_core_theoryt::equal(foo_term, term_42)},
411+
smt_check_sat_commandt{}});
412+
SECTION("Get \"foo\" value back")
413+
{
414+
test.sent_commands.clear();
415+
test.mock_responses.push_back(
416+
smt_get_value_responset{{{foo_term, term_42}}});
417+
REQUIRE(test.procedure.get(foo.symbol_expr()) == expr_42);
418+
REQUIRE(
419+
test.sent_commands ==
420+
std::vector<smt_commandt>{smt_get_value_commandt{foo_term}});
421+
}
422+
SECTION("Get value of non-set symbol")
423+
{
424+
// smt2_incremental_decision_proceduret is used this way when cbmc is
425+
// invoked with the combination of `--trace` and `--slice-formula`.
426+
test.sent_commands.clear();
427+
const exprt bar =
428+
make_test_symbol("bar", signedbv_typet{16}).symbol_expr();
429+
REQUIRE(test.procedure.get(bar) == bar);
430+
REQUIRE(test.sent_commands.empty());
431+
}
432+
SECTION("Get value of type less symbol back")
433+
{
434+
// smt2_incremental_decision_proceduret is used this way as part of
435+
// building the goto trace, to get the partial order concurrency clock
436+
// values.
437+
test.sent_commands.clear();
438+
const symbol_exprt baz = symbol_exprt::typeless("baz");
439+
REQUIRE(test.procedure.get(baz) == baz);
440+
REQUIRE(test.sent_commands.empty());
441+
}
442+
SECTION("Get value of trivially solved expression")
443+
{
444+
test.sent_commands.clear();
445+
const smt_termt not_true_term =
446+
smt_core_theoryt::make_not(smt_bool_literal_termt{true});
447+
test.mock_responses.push_back(smt_get_value_responset{
448+
{{not_true_term, smt_bool_literal_termt{false}}}});
449+
REQUIRE(test.procedure.get(not_exprt{true_exprt{}}) == false_exprt{});
450+
REQUIRE(
451+
test.sent_commands ==
452+
std::vector<smt_commandt>{smt_get_value_commandt{not_true_term}});
453+
}
454+
}
455+
}

0 commit comments

Comments
 (0)