|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Unit tests for symex_target_equation::validate |
| 4 | +
|
| 5 | +Author: Diffblue Ltd. |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <testing-utils/message.h> |
| 10 | +#include <testing-utils/use_catch.h> |
| 11 | + |
| 12 | +#include <goto-symex/goto_symex_state.h> |
| 13 | +#include <goto-symex/renaming_level.h> |
| 14 | +#include <util/namespace.h> |
| 15 | +#include <util/symbol_table.h> |
| 16 | + |
| 17 | +SCENARIO("Level 1 renaming", "[core][goto-symex][symex-level1]") |
| 18 | +{ |
| 19 | + GIVEN("A symbol renamed to level 0, and a symex_level1t functor") |
| 20 | + { |
| 21 | + symbol_tablet symbol_table; |
| 22 | + namespacet ns{symbol_table}; |
| 23 | + const signedbv_typet int_type{32}; |
| 24 | + const symbol_exprt symbol_nonshared{"foo", int_type}; |
| 25 | + ssa_exprt ssa{symbol_nonshared}; |
| 26 | + symbol_table.insert([&] { |
| 27 | + symbolt symbol; |
| 28 | + symbol.name = symbol_nonshared.get_identifier(); |
| 29 | + symbol.type = symbol_nonshared.type(); |
| 30 | + symbol.value = symbol_nonshared; |
| 31 | + symbol.is_thread_local = true; |
| 32 | + return symbol; |
| 33 | + }()); |
| 34 | + auto l0_symbol = symex_level0(ssa, ns, 50); |
| 35 | + symex_level1t symex_level1; |
| 36 | + |
| 37 | + WHEN("The symbol is not yet inserted in symex_level1") |
| 38 | + { |
| 39 | + THEN("Renaming leaves it unchanged") |
| 40 | + { |
| 41 | + auto renamed = symex_level1(l0_symbol); |
| 42 | + REQUIRE(renamed.get().get_identifier() == "foo!50"); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + WHEN("The symbol is inserted in symex_level1 several times") |
| 47 | + { |
| 48 | + symex_level1.insert(l0_symbol, 12134); |
| 49 | + THEN("The symbol is renamed to the index inserted") |
| 50 | + { |
| 51 | + auto renamed = symex_level1(l0_symbol); |
| 52 | + REQUIRE(renamed.get().get_identifier() == "foo!50@12134"); |
| 53 | + } |
| 54 | + |
| 55 | + auto old = symex_level1.insert_or_replace(l0_symbol, 43950); |
| 56 | + THEN("insert_or_replace return the old value") |
| 57 | + { |
| 58 | + REQUIRE(old.has_value()); |
| 59 | + REQUIRE(old->second == 12134); |
| 60 | + } |
| 61 | + THEN("The symbol is renamed to the new value") |
| 62 | + { |
| 63 | + auto renamed2 = symex_level1(l0_symbol); |
| 64 | + REQUIRE(renamed2.get().get_identifier() == "foo!50@43950"); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + WHEN("insert_or_replace is called with a symbol not already inserted") |
| 69 | + { |
| 70 | + auto old = symex_level1.insert_or_replace(l0_symbol, 20051); |
| 71 | + THEN("insert_or_replace return an empty optional") |
| 72 | + { |
| 73 | + REQUIRE(!old.has_value()); |
| 74 | + } |
| 75 | + THEN("The symbol is renamed to the index inserted") |
| 76 | + { |
| 77 | + auto renamed = symex_level1(l0_symbol); |
| 78 | + REQUIRE(renamed.get().get_identifier() == "foo!50@20051"); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments