84 std::map<goto_programt::const_targett, coverage_conditiont>
conditions;
98 std::ostringstream
oss;
106 fraction =
static_cast<float>(covered) /
static_cast<float>(
total);
109 oss << fraction * 100.0 <<
'%';
122 std::ostringstream
oss;
142 "last instruction in a function body is end function");
178 if(
cov_line.second.conditions.empty())
187 for(
const auto &
c :
cov_line.second.conditions)
193 unsigned taken =
c.second.false_taken +
c.second.true_taken;
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->guard.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);
242 std::cerr << it->location_number <<
'\n';
244 std::cerr <<
cov.second.succ->location_number <<
'\n';
248 "instructions other than branch instructions have exactly 1 successor");
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)
301 !
gf_entry.second.body_available() ||
311 std::pair<file_recordst::iterator, bool> entry =
file_records.insert(
325 for(xmlt::elementst::const_iterator it =
326 func_cov.xml.elements.front().elements.begin();
327 it !=
func_cov.xml.elements.front().elements.end();
342 for(file_recordst::const_iterator it =
file_records.begin();
357 "branch-rate",
rate(
f_cov.branches_covered,
f_cov.branches_total));
358 class_xml.set_attribute(
"complexity",
"0.0");
361 dest.lines_covered +=
f_cov.lines_covered;
363 dest.branches_covered +=
f_cov.branches_covered;
364 dest.branches_total +=
f_cov.branches_total;
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);
391 "lines-covered", std::to_string(
overall_cov.lines_covered));
393 "lines-valid", std::to_string(
overall_cov.lines_total));
395 "branches-covered", std::to_string(
overall_cov.branches_covered));
397 "branches-valid", std::to_string(
overall_cov.branches_total));
405 xmlt &
package = packages.new_element(overall_cov.xml);
406 package.set_attribute(
"name",
"");
409 package.set_attribute(
"complexity",
"0.0");
414 std::ostream &os)
const
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());
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
std::map< goto_programt::const_targett, coverage_innert > coveraget
bool output_report(const goto_functionst &goto_functions, std::ostream &os) const
void build_cobertura(const goto_functionst &goto_functions, xmlt &xml_coverage) const
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 INITIALIZE_FUNCTION
unsigned safe_string2unsigned(const std::string &str, int base)
std::map< goto_programt::const_targett, coverage_conditiont > conditions
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.