Skip to content

Commit 8cb487f

Browse files
Petr BauchPetr Bauch
authored andcommitted
Added unit test for missing symbol in table
Builds a goto program with one assert and checks that: 1) with the right symbol in the table the validation succeeds, 2) without the symbol the validation fails.
1 parent c668985 commit 8cb487f

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SRC += analyses/ai/ai.cpp \
1515
analyses/does_remove_const/does_type_preserve_const_correctness.cpp \
1616
analyses/does_remove_const/is_type_at_least_as_const_as.cpp \
1717
goto-programs/goto_trace_output.cpp \
18+
goto-programs/goto_program_table_consistency.cpp \
1819
interpreter/interpreter.cpp \
1920
json/json_parser.cpp \
2021
path_strategies.cpp \
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for goto_program::validate
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <goto-programs/goto_function.h>
10+
#include <testing-utils/catch.hpp>
11+
#include <util/arith_tools.h>
12+
13+
SCENARIO(
14+
"Validation of consistent program/table pair",
15+
"[core][goto-programs][validate]")
16+
{
17+
GIVEN("A program with one assertion")
18+
{
19+
symbol_tablet symbol_table;
20+
const typet type = signedbv_typet(32);
21+
symbolt symbol;
22+
irep_idt symbol_name = "a";
23+
symbol.name = symbol_name;
24+
symbol_exprt varx(symbol_name, type);
25+
26+
exprt val10 = from_integer(10, type);
27+
binary_relation_exprt x_le_10(varx, ID_le, val10);
28+
29+
goto_functiont goto_function;
30+
auto &instructions = goto_function.body.instructions;
31+
instructions.emplace_back(goto_program_instruction_typet::ASSERT);
32+
instructions.back().make_assertion(x_le_10);
33+
34+
WHEN("Symbol table has the right symbol")
35+
{
36+
symbol_table.insert(symbol);
37+
38+
THEN("The consistency check succeeds")
39+
{
40+
goto_function.validate(symbol_table, validation_modet::INVARIANT);
41+
42+
REQUIRE(true);
43+
}
44+
}
45+
46+
WHEN("Symbol table does not have the symbol")
47+
{
48+
THEN("The consistency check fails")
49+
{
50+
bool caught = false;
51+
try
52+
{
53+
goto_function.validate(symbol_table, validation_modet::EXCEPTION);
54+
}
55+
catch(incorrect_goto_program_exceptiont &e)
56+
{
57+
caught = true;
58+
}
59+
REQUIRE(caught);
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)