|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Tests for variable_sensitivity_domaint::to_predicate |
| 4 | +
|
| 5 | + Author: Jez Higgins |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <analyses/variable-sensitivity/variable_sensitivity_domain.h> |
| 10 | +#include <analyses/variable-sensitivity/variable_sensitivity_object_factory.h> |
| 11 | +#include <analyses/variable-sensitivity/variable_sensitivity_test_helpers.h> |
| 12 | +#include <testing-utils/use_catch.h> |
| 13 | +#include <util/arith_tools.h> |
| 14 | +#include <util/bitvector_types.h> |
| 15 | +#include <util/mathematical_types.h> |
| 16 | + |
| 17 | +SCENARIO( |
| 18 | + "variable_sensitivity_domain to predicate", |
| 19 | + "[core][analyses][variable-sensitivity][variable_sensitivity_domain][to_" |
| 20 | + "predicate]") |
| 21 | +{ |
| 22 | + auto config = vsd_configt::constant_domain(); |
| 23 | + config.context_tracking.data_dependency_context = false; |
| 24 | + config.context_tracking.last_write_context = false; |
| 25 | + auto object_factory = |
| 26 | + variable_sensitivity_object_factoryt::configured_with(config); |
| 27 | + symbol_tablet symbol_table; |
| 28 | + namespacet ns(symbol_table); |
| 29 | + |
| 30 | + GIVEN("to_predicate()") |
| 31 | + { |
| 32 | + WHEN("it is TOP") |
| 33 | + { |
| 34 | + auto domain = variable_sensitivity_domaint(object_factory, config); |
| 35 | + domain.make_top(); |
| 36 | + THEN_PREDICATE(domain, "TRUE"); |
| 37 | + } |
| 38 | + WHEN("it is BOTTOM") |
| 39 | + { |
| 40 | + auto domain = variable_sensitivity_domaint(object_factory, config); |
| 41 | + domain.make_bottom(); |
| 42 | + THEN_PREDICATE(domain, "FALSE"); |
| 43 | + } |
| 44 | + } |
| 45 | + GIVEN("to_predicate(expr)") |
| 46 | + { |
| 47 | + WHEN("1 + 2") |
| 48 | + { |
| 49 | + auto type = signedbv_typet(32); |
| 50 | + auto val1 = from_integer(1, type); |
| 51 | + auto val2 = from_integer(2, type); |
| 52 | + |
| 53 | + auto domain = variable_sensitivity_domaint(object_factory, config); |
| 54 | + domain.make_top(); |
| 55 | + |
| 56 | + auto pred = domain.to_predicate(plus_exprt(val1, val2), ns); |
| 57 | + THEN("predicate is 1 + 2 == 3") |
| 58 | + { |
| 59 | + auto repr = expr_to_str(pred); |
| 60 | + REQUIRE(repr == "1 + 2 == 3"); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + GIVEN("to_predicate(std::vector<expr>)") |
| 65 | + { |
| 66 | + auto domain = variable_sensitivity_domaint(object_factory, config); |
| 67 | + domain.make_top(); |
| 68 | + |
| 69 | + auto type = signedbv_typet(32); |
| 70 | + auto val1 = from_integer(1, type); |
| 71 | + auto val2 = from_integer(2, type); |
| 72 | + auto val3 = from_integer(3, type); |
| 73 | + auto onePlusTwo = plus_exprt(val1, val2); |
| 74 | + auto twoPlusThree = plus_exprt(val2, val3); |
| 75 | + |
| 76 | + WHEN("{ }") |
| 77 | + { |
| 78 | + auto pred = domain.to_predicate(std::vector<exprt>(), ns); |
| 79 | + THEN("predicate is FALSE") |
| 80 | + { |
| 81 | + auto repr = expr_to_str(pred); |
| 82 | + REQUIRE(repr == "FALSE"); |
| 83 | + } |
| 84 | + } |
| 85 | + WHEN("{ 1 + 2 }") |
| 86 | + { |
| 87 | + auto pred = domain.to_predicate({onePlusTwo}, ns); |
| 88 | + THEN("predicate is 1 + 2 == 3") |
| 89 | + { |
| 90 | + auto repr = expr_to_str(pred); |
| 91 | + REQUIRE(repr == "1 + 2 == 3"); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + WHEN("{ 1 + 2, 2 + 3 }") |
| 96 | + { |
| 97 | + auto pred = domain.to_predicate({onePlusTwo, twoPlusThree}, ns); |
| 98 | + THEN("predicate is 1 + 2 == 3 && 2 + 3 == 5") |
| 99 | + { |
| 100 | + auto repr = expr_to_str(pred); |
| 101 | + REQUIRE(repr == "1 + 2 == 3 && 2 + 3 == 5"); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments