ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
goto_coverage.h
Go to the documentation of this file.
5#include <map>
6#include <unordered_set>
7
9{
10public:
17 const namespacet &ns,
19 const std::string filename)
21 {
22 target_num = -1;
23 };
24 void assertion_coverage();
25 void branch_coverage();
27
28 // k-path coverage: at each branch, emit goals for every combination of the
29 // last (n-1) branch directions and the current direction (Williams et al.,
30 // EDCC 2005). A goal is `assert(!witness)`; SAT means the path is reachable
31 // and the goal is marked covered by multi_property_check, mirroring the
32 // branch_coverage convention. The structural AND-chain preserves SSA merge
33 // friendliness up to depth_cap; past depth_cap the witness is too deep to
34 // hand to the solver and is dropped (a Phase-2 ghost-flag fallback is
35 // tracked in #4325). Goal count is bounded by max_goals per function.
36 void k_path_coverage();
37
38 void insert_assert(
39 goto_programt &goto_program,
41 const expr2tc &guard);
42
43 // customize comment
44 void insert_assert(
45 goto_programt &goto_program,
47 const expr2tc &guard,
48 const std::string &idf);
49
50 // replace every assertion to a specific guard
52 const expr2tc &guard,
53 bool is_instrumentation = false);
54 // replace an assertion to a specific guard
56 const expr2tc &guard,
58 bool is_instrumentation);
59
60 // convert assert(cond) to assume(cond) to preserve path constraints
63
64 // convert assert(cond) to assert(!cond)
65 void negating_asserts(const std::string &tgt_fname);
66
67 // condition cov
68 void condition_coverage();
69 expr2tc gen_not_eq_expr(const expr2tc &lhs, const expr2tc &rhs);
70 expr2tc gen_and_expr(const expr2tc &lhs, const expr2tc &rhs);
71 expr2tc gen_not_expr(const expr2tc &expr) const;
72 int get_total_instrument() const;
73 int get_total_assert_instance() const;
74 std::set<std::pair<std::string, std::string>> get_total_cond_assert() const;
75 std::string get_filename_from_path(std::string path);
76 void set_target(const std::string &_tgt);
77 bool is_target_func(const irep_idt &f, const std::string &tgt_name) const;
78 bool
79 filter(const irep_idt &func_name, const goto_programt &goto_program) const;
80
81 // total numbers of instrumentation
82 static size_t total_assert;
83 static size_t total_assert_ins;
84 static std::set<std::pair<std::string, std::string>> total_cond;
85 static size_t total_branch;
86 static size_t total_func_branch;
87 static size_t total_kpath;
88 // |spanning_set| under Marré-Bertolino subsumption (issue #4335 PR1).
89 // Equals total_kpath when no goal is subsumed by another. Used as the
90 // denominator of the k-path coverage percentage to drop the lower
91 // bound contribution of redundant subsumed goals.
92 static size_t total_kpath_spanning;
93 // (msg, loc) pairs whose every emission is non-maximal. JSON report
94 // marks these as "spanning-set-redundant" and they are excluded from
95 // the spanning-set denominator.
96 static std::set<std::pair<std::string, std::string>>
98 // all instrumented claims (condition, location) for JSON report
99 static std::set<std::pair<std::string, std::string>> all_claims;
100 // Guard text of the opposite direction for each claim in all_claims, keyed
101 // the same way. A probe assert(c) left unviolated proves !c infeasible, so
102 // --dead-code-check names this rather than the claim's own comment. Derived
103 // from the expression, not by rewriting the comment text: gen_not_expr drops
104 // a leading not2t, so the comment "!flag" gives "flag" and not "!(!flag)",
105 // and from_expr re-parenthesises by precedence, so "x > 5" gives "!(x > 5)".
106 static std::map<std::pair<std::string, std::string>, std::string>
108
109 std::string target_function = "";
110 bool cov_assume_asserts = false;
111
112 // k-path coverage knobs (see #4325 "Decided defaults").
113 // n : prefix depth — number of consecutive branches in each witness
114 // (default 4 if --unwind is unset, else --unwind).
115 // d : post-simplification depth cap on the witness expression tree.
116 // Witnesses deeper than d are skipped in Phase 1 (no ghost-flag
117 // fallback yet — see #4325).
118 // m : per-function goal cap. On overflow, instrumentation aborts with
119 // an actionable error rather than silently truncating.
120 size_t k_path_n = 4;
122 size_t k_path_max_goals = 10000;
123
124protected:
125 expr2tc handle_single_guard(const expr2tc &expr, bool top_level);
127 const expr2tc &expr,
128 goto_programt &goto_program,
131 const expr2tc &top_ptr,
132 const expr2tc &pre_cond,
133 goto_programt &goto_program,
136 const expr2tc &top_ptr,
137 const expr2tc &pre_cond,
138 goto_programt &goto_program,
140
143
144 // we need to skip the conditions within the built-in library
145 // while keeping the file manually included by user
146 // this filter, however, is unsound.. E.g. if the src filename is the same as
147 // the builtin library name
148 std::string filename;
149
151};
152
154{
155public:
157 contextt &_context,
158 optionst &_options,
160 : goto_convertt(_context, _options), goto_functions(goto_functions)
161 {
162 options.set_option("goto-instrumented", true);
163 }
164 void remove_sideeffect();
166};
Definition context.h:57
goto_convertt(contextt &_context, optionst &_options)
Definition goto_convert_class.h:30
optionst & options
Definition goto_convert_class.h:40
goto_coverage_rm(contextt &_context, optionst &_options, goto_functionst &goto_functions)
Definition goto_coverage.h:156
void remove_sideeffect()
Definition goto_coverage_rm.cpp:6
goto_functionst & goto_functions
Definition goto_coverage.h:165
static size_t total_branch
Definition goto_coverage.h:85
static std::set< std::pair< std::string, std::string > > k_path_spanning_redundant
Definition goto_coverage.h:97
void replace_all_asserts_to_assume()
Definition goto_coverage.cpp:119
void replace_assert_to_assume(goto_programt::instructiont::targett &it)
Definition goto_coverage.cpp:107
expr2tc handle_single_guard(const expr2tc &expr, bool top_level)
Definition goto_coverage.cpp:1267
std::string get_filename_from_path(std::string path)
Definition goto_coverage.cpp:39
expr2tc gen_not_eq_expr(const expr2tc &lhs, const expr2tc &rhs)
Definition goto_coverage.cpp:1213
goto_coveraget(const namespacet &ns, goto_functionst &goto_functions)
Definition goto_coverage.h:11
void gen_cond_cov_assert(const expr2tc &top_ptr, const expr2tc &pre_cond, goto_programt &goto_program, goto_programt::instructiont::targett &it)
Recurse into all sub-expressions of ptr, calling gen_cond_cov_assert on each.
Definition goto_coverage.cpp:1105
static size_t total_kpath_spanning
Definition goto_coverage.h:92
expr2tc gen_and_expr(const expr2tc &lhs, const expr2tc &rhs)
Definition goto_coverage.cpp:1219
namespacet ns
Definition goto_coverage.h:141
void k_path_coverage()
Definition goto_coverage.cpp:583
void handle_operands_guard(const expr2tc &expr, goto_programt &goto_program, goto_programt::instructiont::targett &it)
Definition goto_coverage.cpp:1351
static size_t total_assert_ins
Definition goto_coverage.h:83
void branch_coverage()
Definition goto_coverage.cpp:257
bool is_target_func(const irep_idt &f, const std::string &tgt_name) const
Definition goto_coverage.cpp:1396
bool filter(const irep_idt &func_name, const goto_programt &goto_program) const
Definition goto_coverage.cpp:1463
int get_total_instrument() const
Definition goto_coverage.cpp:874
goto_functionst & goto_functions
Definition goto_coverage.h:142
void set_target(const std::string &_tgt)
Definition goto_coverage.cpp:1390
static std::set< std::pair< std::string, std::string > > all_claims
Definition goto_coverage.h:99
expr2tc gen_not_expr(const expr2tc &expr) const
Definition goto_coverage.cpp:1227
std::string filename
Definition goto_coverage.h:148
std::string target_function
Definition goto_coverage.h:109
size_t k_path_n
Definition goto_coverage.h:120
void add_cond_cov_assert(const expr2tc &top_ptr, const expr2tc &pre_cond, goto_programt &goto_program, goto_programt::instructiont::targett &it)
Definition goto_coverage.cpp:1190
void condition_coverage()
Definition goto_coverage.cpp:955
void replace_all_asserts_to_guard(const expr2tc &guard, bool is_instrumentation=false)
Definition goto_coverage.cpp:51
static size_t total_assert
Definition goto_coverage.h:82
static std::set< std::pair< std::string, std::string > > total_cond
Definition goto_coverage.h:84
static size_t total_kpath
Definition goto_coverage.h:87
size_t k_path_witness_depth
Definition goto_coverage.h:121
void insert_assert(goto_programt &goto_program, goto_programt::targett &it, const expr2tc &guard)
Definition goto_coverage.cpp:840
goto_coveraget(const namespacet &ns, goto_functionst &goto_functions, const std::string filename)
Definition goto_coverage.h:16
std::set< std::pair< std::string, std::string > > get_total_cond_assert() const
Definition goto_coverage.cpp:910
int get_total_assert_instance() const
Definition goto_coverage.cpp:900
static std::map< std::pair< std::string, std::string >, std::string > claim_negation
Definition goto_coverage.h:107
size_t k_path_max_goals
Definition goto_coverage.h:122
void branch_function_coverage()
Definition goto_coverage.cpp:176
void negating_asserts(const std::string &tgt_fname)
Definition goto_coverage.cpp:1428
static size_t total_func_branch
Definition goto_coverage.h:86
void replace_assert_to_guard(const expr2tc &guard, goto_programt::instructiont::targett &it, bool is_instrumentation)
Definition goto_coverage.cpp:84
int target_num
Definition goto_coverage.h:150
void assertion_coverage()
Definition goto_coverage.cpp:150
bool cov_assume_asserts
Definition goto_coverage.h:110
Definition goto_functions.h:56
std::list< classinstructiont >::iterator targett
the targets for gotos and catch
Definition goto_program.h:130
A generic container class for a control flow graph for one function, in the form of a goto-program.
Definition goto_program.h:63
instructionst::iterator targett
Definition goto_program.h:590
Definition irep_idt.h:12
Definition namespace.h:10
Definition options.h:11
irep_container< expr2t > expr2tc
Definition irep2.h:431
Definition path.py:1