53 goto_functionst::function_mapt::const_iterator gf_it,
83 std::map<goto_programt::const_targett, coverage_conditiont>
87 typedef std::map<unsigned, coverage_linet>
102 std::ostringstream oss;
110 fraction=
static_cast<float>(covered)/static_cast<float>(total);
113 oss << fraction*100.0 <<
'%';
117 oss << covered <<
" of " << total;
128 std::ostringstream oss;
129 oss <<
rate(covered, total, per_cent)
130 <<
" (" << covered <<
'/' << total <<
')';
136 goto_functionst::function_mapt::const_iterator gf_it,
140 assert(gf_it->second.body_available());
145 --gf_it->second.body.instructions.end();
146 assert(end_function->is_end_function());
147 file_name=end_function->source_location.get_file();
175 sig_type=gf_it->second.type;
186 for(
const auto &cov_line : coverage_lines_map)
190 line.
set_attribute(
"number", std::to_string(cov_line.first));
191 line.
set_attribute(
"hits", std::to_string(cov_line.second.hits));
192 if(cov_line.second.conditions.empty())
200 std::size_t number=0, total_taken=0;
201 for(
const auto &c : cov_line.second.conditions)
207 unsigned taken=c.second.false_taken+c.second.true_taken;
213 "condition-coverage",
227 if(it->source_location.is_nil() ||
228 it->source_location.get_file()!=
file_name ||
230 it->is_end_function())
233 const bool is_branch=it->is_goto() && !it->guard.is_constant();
237 std::pair<coverage_lines_mapt::iterator, bool> entry=
248 if(!entry.first->second.conditions.insert(
249 {it, coverage_conditiont()}).second)
253 symex_coveraget::coveraget::const_iterator c_entry=
255 if(c_entry!=coverage.end())
257 if(!(c_entry->second.size()==1 || is_branch))
259 std::cerr << it->location_number <<
'\n';
260 for(
const auto &cov : c_entry->second)
261 std::cerr << cov.second.succ->location_number <<
'\n';
263 assert(c_entry->second.size()==1 || is_branch);
265 for(
const auto &cov : c_entry->second)
267 assert(cov.second.num_executions>0);
269 if(entry.first->second.hits==0)
272 if(cov.second.num_executions>entry.first->second.hits)
273 entry.first->second.hits=cov.second.num_executions;
277 auto cond_entry=entry.first->second.conditions.find(it);
278 assert(cond_entry!=entry.first->second.conditions.end());
280 if(it->get_target()==cov.second.succ)
282 if(!cond_entry->second.false_taken)
284 cond_entry->second.false_taken=
true;
290 if(!cond_entry->second.true_taken)
292 cond_entry->second.true_taken=
true;
306 typedef std::map<irep_idt, coverage_recordt> file_recordst;
307 file_recordst file_records;
311 if(!gf_it->second.body_available() ||
318 std::pair<file_recordst::iterator, bool> entry=
319 file_records.insert(std::make_pair(func_cov.
get_file(),
333 for(xmlt::elementst::const_iterator
350 for(file_recordst::const_iterator it=file_records.begin();
351 it!=file_records.end();
380 xmlt &xml_coverage)
const 385 std::string overall_line_rate_str=
387 std::string overall_branch_rate_str=
394 xml_coverage.
set_attribute(
"line-rate", overall_line_rate_str);
395 xml_coverage.
set_attribute(
"branch-rate", overall_branch_rate_str);
415 package.
set_attribute(
"branch-rate", overall_branch_rate_str);
421 std::ostream &os)
const 423 xmlt xml_coverage(
"coverage");
426 os <<
"<?xml version=\"1.0\"?>\n";
427 os <<
"<!DOCTYPE coverage SYSTEM \"" 428 <<
"http://cobertura.sourceforge.net/xml/coverage-04.dtd\">\n";
436 const std::string &path)
const 438 assert(!path.empty());
444 std::ofstream out(path.c_str());
void build_cobertura(const goto_functionst &goto_functions, xmlt &xml_coverage) const
const std::string & id2string(const irep_idt &d)
const symbol_tablet & get_symbol_table() const
void compute_coverage_lines(const goto_programt &goto_program, const irep_idt &file_name, const symex_coveraget::coveraget &coverage, coverage_lines_mapt &dest)
bool generate_report(const goto_functionst &goto_functions, const std::string &path) const
Goto Programs with Functions.
std::map< goto_programt::const_targett, coverage_innert > coveraget
void compute_overall_coverage(const goto_functionst &goto_functions, coverage_recordt &dest) const
instructionst::const_iterator const_targett
bool output_report(const goto_functionst &goto_functions, std::ostream &os) const
const irep_idt & get_file() const
static std::string rate_detailed(std::size_t covered, std::size_t total, bool per_cent=false)
static irep_idt entry_point()
code_typet original_return_type(const symbol_tablet &symbol_table, const irep_idt &function_id)
void set_attribute(const std::string &attribute, unsigned value)
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
xmlt & new_element(const std::string &name)
std::size_t branches_total
std::map< unsigned, coverage_linet > coverage_lines_mapt
static std::string rate(std::size_t covered, std::size_t total, bool per_cent=false)
A specialization of goto_program_templatet over goto programs in which instructions have codet type...
std::size_t lines_covered
unsigned safe_string2unsigned(const std::string &str, int base)
absolute_timet current_time()
goto_program_coverage_recordt(const namespacet &ns, goto_functionst::function_mapt::const_iterator gf_it, const symex_coveraget::coveraget &coverage)
Record and print code coverage of symbolic execution.
#define forall_goto_functions(it, functions)
#define forall_goto_program_instructions(it, program)
std::size_t branches_covered
std::map< goto_programt::const_targett, coverage_conditiont > conditions
coverage_recordt(const std::string &node_id)