84 std::map<goto_programt::const_targett, coverage_conditiont>
conditions;
96 rate(std::size_t covered, std::size_t total,
bool per_cent =
false)
98 std::ostringstream oss;
106 fraction =
static_cast<float>(covered) /
static_cast<float>(total);
109 oss << fraction * 100.0 <<
'%';
113 oss << covered <<
" of " << total;
120 rate_detailed(std::size_t covered, std::size_t total,
bool per_cent =
false)
122 std::ostringstream oss;
123 oss <<
rate(covered, total, per_cent) <<
" (" << covered <<
'/' << total
141 end_function->is_end_function(),
142 "last instruction in a function body is end function");
143 file_name = end_function->source_location().get_file();
172 for(
const auto &cov_line : coverage_lines_map)
178 if(cov_line.second.conditions.empty())
186 std::size_t number = 0, total_taken = 0;
187 for(
const auto &c : cov_line.second.conditions)
193 unsigned taken = c.second.false_taken + c.second.true_taken;
194 total_taken += taken;
199 "condition-coverage",
rate_detailed(total_taken, number * 2,
true));
212 it->source_location().is_nil() ||
213 it->source_location().get_file() !=
file_name || it->is_dead() ||
214 it->is_end_function())
217 const bool is_branch = it->is_goto() && !it->condition().is_constant();
221 std::pair<coverage_lines_mapt::iterator, bool> entry =
232 if(!entry.first->second.conditions.insert({it, coverage_conditiont()})
237 symex_coveraget::coveraget::const_iterator c_entry = coverage.find(it);
238 if(c_entry != coverage.end())
240 if(!(c_entry->second.size() == 1 || is_branch))
242 std::cerr << it->location_number <<
'\n';
243 for(
const auto &cov : c_entry->second)
244 std::cerr << cov.second.succ->location_number <<
'\n';
247 c_entry->second.size() == 1 || is_branch,
248 "instructions other than branch instructions have exactly 1 successor");
250 for(
const auto &cov : c_entry->second)
253 cov.second.num_executions > 0,
254 "coverage entries can only exist with at least one execution");
256 if(entry.first->second.hits == 0)
259 if(cov.second.num_executions > entry.first->second.hits)
260 entry.first->second.hits = cov.second.num_executions;
264 auto cond_entry = entry.first->second.conditions.find(it);
266 cond_entry != entry.first->second.conditions.end(),
267 "branch should have condition");
269 if(it->get_target() == cov.second.succ)
271 if(!cond_entry->second.false_taken)
273 cond_entry->second.false_taken =
true;
279 if(!cond_entry->second.true_taken)
281 cond_entry->second.true_taken =
true;
295 typedef std::map<irep_idt, coverage_recordt> file_recordst;
296 file_recordst file_records;
301 !gf_entry.second.body_available() ||
309 ns, gf_entry.first, gf_entry.second.body,
coverage);
311 std::pair<file_recordst::iterator, bool> entry = file_records.insert(
325 for(xmlt::elementst::const_iterator it =
327 it != func_cov.
xml.
elements.front().elements.end();
342 for(file_recordst::const_iterator it = file_records.begin();
343 it != file_records.end();
370 xmlt &xml_coverage)
const
375 std::string overall_line_rate_str =
377 std::string overall_branch_rate_str =
380 auto now = std::chrono::system_clock::now();
381 auto current_time = std::chrono::time_point_cast<std::chrono::seconds>(now);
382 std::time_t tt = std::chrono::system_clock::to_time_t(current_time);
388 xml_coverage.
set_attribute(
"line-rate", overall_line_rate_str);
389 xml_coverage.
set_attribute(
"branch-rate", overall_branch_rate_str);
405 xmlt &
package = packages.new_element(overall_cov.xml);
407 package.set_attribute(
"line-rate", overall_line_rate_str);
408 package.set_attribute(
"branch-rate", overall_branch_rate_str);
409 package.set_attribute(
"complexity",
"0.0");
414 std::ostream &os)
const
416 xmlt xml_coverage(
"coverage");
419 os <<
"<?xml version=\"1.0\"?>\n";
420 os <<
"<!DOCTYPE coverage SYSTEM \""
421 <<
"http://cobertura.sourceforge.net/xml/coverage-04.dtd\">\n";
429 const std::string &path)
const
437 std::ofstream out(path.c_str());