|
7 | 7 | #include <solvers/smt2_incremental/smt_terms.h>
|
8 | 8 | #include <solvers/smt2_incremental/smt_to_smt2_string.h>
|
9 | 9 |
|
| 10 | +#include <util/arith_tools.h> |
| 11 | +#include <util/bitvector_types.h> |
| 12 | +#include <util/mp_arith.h> |
10 | 13 | #include <util/std_expr.h>
|
11 | 14 | #include <util/std_types.h>
|
12 | 15 |
|
| 16 | +static mp_integer power2(unsigned exponent) |
| 17 | +{ |
| 18 | + mp_integer result; |
| 19 | + result.setPower2(exponent); |
| 20 | + return result; |
| 21 | +} |
| 22 | + |
| 23 | +/// Returns the maximum integer value which can be stored in \p bits as an |
| 24 | +/// unsigned integer. |
| 25 | +static mp_integer max_int(const std::size_t bits) |
| 26 | +{ |
| 27 | + return power2(bits) - 1; |
| 28 | +} |
| 29 | + |
13 | 30 | TEST_CASE("Value expr construction from smt.", "[core][smt2_incremental]")
|
14 | 31 | {
|
15 | 32 | optionalt<smt_termt> input_term;
|
16 | 33 | optionalt<exprt> expected_result;
|
17 | 34 |
|
18 | 35 | using rowt = std::pair<smt_termt, exprt>;
|
| 36 | + |
| 37 | + // clang-format off |
| 38 | +#define UNSIGNED_BIT_VECTOR_TESTS(bits) \ |
| 39 | + rowt{smt_bit_vector_constant_termt{0, (bits)}, \ |
| 40 | + from_integer(0, unsignedbv_typet{(bits)})}, \ |
| 41 | + rowt{smt_bit_vector_constant_termt{42, (bits)}, \ |
| 42 | + from_integer(42, unsignedbv_typet{(bits)})}, \ |
| 43 | + rowt{smt_bit_vector_constant_termt{max_int((bits) - 1), (bits)}, \ |
| 44 | + from_integer(max_int((bits) - 1), unsignedbv_typet{(bits)})}, \ |
| 45 | + rowt{smt_bit_vector_constant_termt{power2((bits) - 1), (bits)}, \ |
| 46 | + from_integer(power2((bits) - 1), unsignedbv_typet{(bits)})}, \ |
| 47 | + rowt{smt_bit_vector_constant_termt{max_int((bits)), (bits)}, \ |
| 48 | + from_integer(max_int((bits)), unsignedbv_typet{(bits)})} |
| 49 | + |
| 50 | +#define SIGNED_BIT_VECTOR_TESTS(bits) \ |
| 51 | + rowt{smt_bit_vector_constant_termt{0, (bits)}, \ |
| 52 | + from_integer(0, signedbv_typet{(bits)})}, \ |
| 53 | + rowt{smt_bit_vector_constant_termt{42, (bits)}, \ |
| 54 | + from_integer(42, signedbv_typet{(bits)})}, \ |
| 55 | + rowt{smt_bit_vector_constant_termt{max_int((bits) - 1), (bits)}, \ |
| 56 | + from_integer(max_int((bits) - 1), signedbv_typet{(bits)})}, \ |
| 57 | + rowt{smt_bit_vector_constant_termt{power2((bits) - 1), (bits)}, \ |
| 58 | + from_integer(-power2((bits) - 1), signedbv_typet{(bits)})}, \ |
| 59 | + rowt{smt_bit_vector_constant_termt{max_int((bits)), (bits)}, \ |
| 60 | + from_integer(-1, signedbv_typet{(bits)})} |
| 61 | + // clang-format on |
| 62 | + |
19 | 63 | std::tie(input_term, expected_result) = GENERATE(
|
20 | 64 | rowt{smt_bool_literal_termt{true}, true_exprt{}},
|
21 |
| - rowt{smt_bool_literal_termt{false}, false_exprt{}}); |
| 65 | + rowt{smt_bool_literal_termt{false}, false_exprt{}}, |
| 66 | + UNSIGNED_BIT_VECTOR_TESTS(8), |
| 67 | + SIGNED_BIT_VECTOR_TESTS(8), |
| 68 | + UNSIGNED_BIT_VECTOR_TESTS(16), |
| 69 | + SIGNED_BIT_VECTOR_TESTS(16), |
| 70 | + UNSIGNED_BIT_VECTOR_TESTS(32), |
| 71 | + SIGNED_BIT_VECTOR_TESTS(32), |
| 72 | + UNSIGNED_BIT_VECTOR_TESTS(64), |
| 73 | + SIGNED_BIT_VECTOR_TESTS(64)); |
22 | 74 | SECTION(
|
23 | 75 | "Construction of \"" + id2string(expected_result->type().id()) +
|
24 | 76 | "\" from \"" + smt_to_smt2_string(*input_term) + "\"")
|
|
0 commit comments