Skip to content

Commit 719a88e

Browse files
author
Enrico Steffinlongo
committed
Add array_of_exprt unit and regression tests
1 parent 96675c2 commit 719a88e

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
int main()
2+
{
3+
int example_array[10000];
4+
unsigned int index;
5+
__CPROVER_assume(index < 999);
6+
7+
__CPROVER_array_set(example_array, 43);
8+
__CPROVER_assert(example_array[index] != 43, "False array condition");
9+
10+
__CPROVER_array_set(example_array, 42);
11+
__CPROVER_assert(example_array[index] == 42, "Valid array condition");
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
array_of.c
3+
4+
Passing problem to incremental SMT2 solving
5+
line \d+ False array condition: FAILURE
6+
line \d+ Valid array condition: SUCCESS
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
--
11+
Test using __CPROVER_array_set consisting in an `array_of` node which sets all values of a given
12+
array to a given value.
13+
This test uses a forall SMT statement.

unit/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,5 +614,36 @@ TEST_CASE(
614614
smt_declare_function_commandt{index_term, {}},
615615
smt_assert_commandt{smt_core_theoryt::equal(
616616
foo_term, smt_array_theoryt::select(array_term, index_term))}};
617+
REQUIRE(test.sent_commands == expected_commands);
618+
}
619+
SECTION("array_of_exprt - all elements set to a given value")
620+
{
621+
const array_of_exprt array_of_expr{
622+
from_integer(42, value_type), array_type};
623+
test.sent_commands.clear();
624+
test.procedure.set_to(
625+
equal_exprt{
626+
foo.symbol_expr(), index_exprt{array_of_expr, index.symbol_expr()}},
627+
true);
628+
const auto foo_term = smt_identifier_termt{"foo", smt_bit_vector_sortt{8}};
629+
const auto array_term = smt_identifier_termt{
630+
"array_0",
631+
smt_array_sortt{smt_bit_vector_sortt{32}, smt_bit_vector_sortt{8}}};
632+
const auto index_term =
633+
smt_identifier_termt{"index", smt_bit_vector_sortt{32}};
634+
const auto forall_term = smt_identifier_termt{
635+
id2string(array_term.identifier()) + "_index", smt_bit_vector_sortt{32}};
636+
const std::vector<smt_commandt> expected_commands{
637+
smt_declare_function_commandt{foo_term, {}},
638+
smt_declare_function_commandt{array_term, {}},
639+
smt_assert_commandt{smt_forall_termt{
640+
{forall_term},
641+
smt_core_theoryt::equal(
642+
smt_array_theoryt::select(array_term, forall_term),
643+
smt_bit_vector_constant_termt{42, 8})}},
644+
smt_declare_function_commandt{index_term, {}},
645+
smt_assert_commandt{smt_core_theoryt::equal(
646+
foo_term, smt_array_theoryt::select(array_term, index_term))}};
647+
REQUIRE(test.sent_commands == expected_commands);
617648
}
618649
}

0 commit comments

Comments
 (0)