102 std::ostringstream
oss;
110 fraction =
static_cast<float>(covered) /
static_cast<float>(total);
113 oss << fraction * 100.0 <<
'%';
117 oss << covered <<
" of " << total;
126 std::ostringstream
oss;
127 oss <<
rate(covered, total,
per_cent) <<
" (" << covered <<
'/' << total
146 "last instruction in a function body is end function");
182 if(
cov_line.second.conditions.empty())
191 for(
const auto &
c :
cov_line.second.conditions)
197 unsigned taken =
c.second.false_taken +
c.second.true_taken;
216 it->source_location().is_nil() ||
217 it->source_location().get_file() !=
file_name || it->is_dead() ||
218 it->is_end_function())
221 const bool is_branch = it->is_goto() && !it->condition().is_constant();
225 std::pair<coverage_lines_mapt::iterator, bool> entry =
236 if(!entry.first->second.conditions.insert({it, coverage_conditiont()})
241 symex_coveraget::coveraget::const_iterator
c_entry = coverage.find(it);
246 "instructions other than branch instructions or function calls have "
247 "exactly 1 successor",
248 "found at goto program instruction number " +
249 std::to_string(it->location_number));
254 cov.second.num_executions > 0,
255 "coverage entries can only exist with at least one execution");
257 if(entry.first->second.hits == 0)
260 if(
cov.second.num_executions > entry.first->second.hits)
261 entry.first->second.hits =
cov.second.num_executions;
265 auto cond_entry = entry.first->second.conditions.find(it);
267 cond_entry != entry.first->second.conditions.end(),
268 "branch should have condition");
270 if(it->get_target() ==
cov.second.succ)
302 !
gf_entry.second.body_available() ||
312 std::pair<file_recordst::iterator, bool> entry =
file_records.insert(
326 for(xmlt::elementst::const_iterator it =
327 func_cov.xml.elements.front().elements.begin();
328 it !=
func_cov.xml.elements.front().elements.end();
343 for(file_recordst::const_iterator it =
file_records.begin();
358 "branch-rate",
rate(
f_cov.branches_covered,
f_cov.branches_total));
359 class_xml.set_attribute(
"complexity",
"0.0");
381 auto now = std::chrono::system_clock::now();
382 auto current_time = std::chrono::time_point_cast<std::chrono::seconds>(
now);
383 std::time_t
tt = std::chrono::system_clock::to_time_t(
current_time);
392 "lines-covered", std::to_string(
overall_cov.lines_covered));
394 "lines-valid", std::to_string(
overall_cov.lines_total));
396 "branches-covered", std::to_string(
overall_cov.branches_covered));
398 "branches-valid", std::to_string(
overall_cov.branches_total));
406 xmlt &
package = packages.new_element(overall_cov.xml);
407 package.set_attribute(
"name",
"");
410 package.set_attribute(
"complexity",
"0.0");
415 std::ostream &os)
const
420 os <<
"<?xml version=\"1.0\"?>\n";
421 os <<
"<!DOCTYPE coverage SYSTEM \""
422 <<
"http://cobertura.sourceforge.net/xml/coverage-04.dtd\">\n";
430 const std::string &path)
const
438 std::ofstream out(path.c_str());
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
std::size_t lines_covered
std::size_t branches_total
std::size_t branches_covered
coverage_recordt(const std::string &node_id)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
A collection of goto functions.
function_mapt function_map
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
void compute_coverage_lines(const goto_programt &goto_program, const symex_coveraget::coveraget &coverage, coverage_lines_mapt &dest)
const irep_idt & get_file() const
std::map< unsigned, coverage_linet > coverage_lines_mapt
goto_program_coverage_recordt(const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program, const symex_coveraget::coveraget &coverage)
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
instructionst::const_iterator const_targett
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
void compute_overall_coverage(const goto_functionst &goto_functions, coverage_recordt &dest) const
bool generate_report(const goto_functionst &goto_functions, const std::string &path) const
bool output_report(const goto_functionst &goto_functions, std::ostream &os) const
void build_cobertura(const goto_functionst &goto_functions, xmlt &xml_coverage) const
std::map< goto_programt::const_targett, coverage_innert, goto_programt::target_less_than > coveraget
xmlt & new_element(const std::string &key)
void set_attribute(const std::string &attribute, unsigned value)
Goto Programs with Functions.
#define forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
#define INITIALIZE_FUNCTION
unsigned safe_string2unsigned(const std::string &str, int base)
std::map< goto_programt::const_targett, coverage_conditiont, goto_programt::target_less_than > conditions
A total order over targett and const_targett.
static std::string rate(std::size_t covered, std::size_t total, bool per_cent=false)
static std::string rate_detailed(std::size_t covered, std::size_t total, bool per_cent=false)
Record and print code coverage of symbolic execution.