Skip to content

Commit 91cd32b

Browse files
Add unit test for symex_level0t
This tests the behavior on different SSA expressions.
1 parent 2472546 commit 91cd32b

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ SRC += analyses/ai/ai.cpp \
3232
goto-programs/xml_expr.cpp \
3333
goto-symex/ssa_equation.cpp \
3434
goto-symex/is_constant.cpp \
35+
goto-symex/symex_level0.cpp \
3536
interpreter/interpreter.cpp \
3637
json/json_parser.cpp \
3738
json_symbol_table.cpp \

unit/goto-symex/symex_level0.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 0 renaming", "[core][goto-symex][symex-level0]")
18+
{
19+
GIVEN(
20+
"A symbol table with a thread local variable, a shared variable, "
21+
"a guard, and a function")
22+
{
23+
symbol_tablet symbol_table;
24+
namespacet ns{symbol_table};
25+
const signedbv_typet int_type{32};
26+
27+
const symbol_exprt symbol_nonshared{"nonShared", int_type};
28+
const ssa_exprt ssa_nonshared{symbol_nonshared};
29+
symbol_table.insert([&] {
30+
symbolt symbol;
31+
symbol.name = symbol_nonshared.get_identifier();
32+
symbol.type = symbol_nonshared.type();
33+
symbol.value = symbol_nonshared;
34+
symbol.is_thread_local = true;
35+
return symbol;
36+
}());
37+
38+
const symbol_exprt symbol_shared{"shared", int_type};
39+
const ssa_exprt ssa_shared{symbol_shared};
40+
symbol_table.insert([&] {
41+
symbolt symbol;
42+
symbol.name = symbol_shared.get_identifier();
43+
symbol.type = symbol_shared.type();
44+
symbol.value = symbol_shared;
45+
symbol.is_thread_local = false;
46+
return symbol;
47+
}());
48+
49+
const symbol_exprt symbol_guard{goto_symex_statet::guard_identifier(),
50+
bool_typet{}};
51+
const ssa_exprt ssa_guard{symbol_guard};
52+
symbol_table.insert([&] {
53+
symbolt symbol;
54+
symbol.name = symbol_guard.get_identifier();
55+
symbol.type = symbol_guard.type();
56+
symbol.value = symbol_guard;
57+
symbol.is_thread_local = false;
58+
return symbol;
59+
}());
60+
61+
const code_typet code_type({}, int_type);
62+
const symbol_exprt symbol_fun{"fun", code_type};
63+
const ssa_exprt ssa_fun{symbol_fun};
64+
symbol_table.insert([&] {
65+
symbolt fun_symbol;
66+
fun_symbol.name = symbol_fun.get_identifier();
67+
fun_symbol.type = symbol_fun.type();
68+
fun_symbol.value = symbol_fun;
69+
fun_symbol.is_thread_local = true;
70+
return fun_symbol;
71+
}());
72+
73+
WHEN("The non-shared symbol is renamed")
74+
{
75+
auto renamed = symex_level0t{}(ssa_nonshared, ns, 423);
76+
77+
THEN("Its L0 tag is set to the thread index")
78+
{
79+
REQUIRE(renamed.get().get_identifier() == "nonShared!423");
80+
}
81+
}
82+
83+
WHEN("The shared symbol is renamed")
84+
{
85+
auto renamed = symex_level0t{}(ssa_shared, ns, 423);
86+
87+
THEN("Its L0 tag is unchanged")
88+
{
89+
REQUIRE(renamed.get().get_identifier() == "shared");
90+
}
91+
}
92+
93+
WHEN("The guard is renamed")
94+
{
95+
auto renamed = symex_level0t{}(ssa_guard, ns, 423);
96+
97+
THEN("Its L0 tag is unchanged")
98+
{
99+
REQUIRE(
100+
renamed.get().get_identifier() ==
101+
goto_symex_statet::guard_identifier());
102+
}
103+
}
104+
105+
WHEN("The function is renamed")
106+
{
107+
auto renamed = symex_level0t{}(ssa_fun, ns, 423);
108+
109+
THEN("Its L0 tag is unchanged")
110+
{
111+
REQUIRE(renamed.get().get_identifier() == "fun");
112+
}
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)