Skip to content

Commit 7ceafcc

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Added unit test for wrong type in table
Builds a goto model with one function and checks that: 1) with the right type in the table the validation succeeds, 2) with the wrong type the validation fails.
1 parent 43052d5 commit 7ceafcc

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
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_model_function_type_consistency.cpp \
1819
interpreter/interpreter.cpp \
1920
json/json_parser.cpp \
2021
path_strategies.cpp \
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for goto_model::validate
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <goto-programs/goto_model.h>
10+
#include <testing-utils/catch.hpp>
11+
#include <util/arith_tools.h>
12+
13+
SCENARIO(
14+
"Validation of consistent program/table pair (function type)",
15+
"[core][goto-programs][validate]")
16+
{
17+
GIVEN("A model with one function")
18+
{
19+
const typet type1 = signedbv_typet(32);
20+
const typet type2 = signedbv_typet(64);
21+
code_typet fun_type1({}, type1);
22+
code_typet fun_type2({}, type2);
23+
24+
symbolt function_symbol;
25+
irep_idt function_symbol_name = "foo";
26+
function_symbol.name = function_symbol_name;
27+
28+
goto_modelt goto_model;
29+
goto_model.goto_functions.function_map[function_symbol.name] =
30+
goto_functiont();
31+
goto_model.goto_functions.function_map[function_symbol.name].type =
32+
fun_type1;
33+
34+
WHEN("Symbol table has the right type")
35+
{
36+
function_symbol.type = fun_type1;
37+
goto_model.symbol_table.insert(function_symbol);
38+
namespacet ns(goto_model.symbol_table);
39+
40+
THEN("The consistency check succeeds")
41+
{
42+
goto_model.validate(ns, validation_modet::INVARIANT);
43+
44+
REQUIRE(true);
45+
}
46+
}
47+
48+
WHEN("Symbol table has the wrong type")
49+
{
50+
function_symbol.type = fun_type2;
51+
goto_model.symbol_table.insert(function_symbol);
52+
namespacet ns(goto_model.symbol_table);
53+
54+
THEN("The consistency check fails")
55+
{
56+
bool caught = false;
57+
try
58+
{
59+
goto_model.validate(ns, validation_modet::EXCEPTION);
60+
}
61+
catch(incorrect_goto_program_exceptiont &e)
62+
{
63+
caught = true;
64+
}
65+
REQUIRE(caught);
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)