Skip to content

Commit 910ca64

Browse files
committed
cbmc --symex-coverage-report: Cobertura-compatible coverage output
1 parent 7fe85ee commit 910ca64

9 files changed

+569
-3
lines changed

src/cbmc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SRC = cbmc_main.cpp cbmc_parse_options.cpp bmc.cpp cbmc_dimacs.cpp \
22
cbmc_languages.cpp counterexample_beautification.cpp \
33
bv_cbmc.cpp symex_bmc.cpp show_vcc.cpp cbmc_solvers.cpp \
44
xml_interface.cpp bmc_cover.cpp all_properties.cpp \
5-
fault_localization.cpp
5+
fault_localization.cpp symex_coverage.cpp
66

77
OBJ += ../ansi-c/ansi-c$(LIBEXT) \
88
../cpp/cpp$(LIBEXT) \

src/cbmc/bmc.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,15 @@ safety_checkert::resultt bmct::run(
528528
<< " remaining after simplification" << eom;
529529
}
530530

531+
// coverage report
532+
std::string cov_out=options.get_option("symex-coverage-report");
533+
if(!cov_out.empty() &&
534+
symex.output_coverage_report(goto_functions, cov_out))
535+
{
536+
error() << "Failed to write symex coverage report" << eom;
537+
return safety_checkert::ERROR;
538+
}
539+
531540
if(options.get_bool_option("show-vcc"))
532541
{
533542
show_vcc();

src/cbmc/bmc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class bmct:public safety_checkert
4343
ui(ui_message_handlert::PLAIN)
4444
{
4545
symex.constant_propagation=options.get_bool_option("propagation");
46+
symex.record_coverage=
47+
!options.get_option("symex-coverage-report").empty();
4648
}
4749

4850
virtual resultt run(const goto_functionst &goto_functions);

src/cbmc/cbmc_parse_options.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
434434
options.set_option("stop-on-fail", true);
435435
options.set_option("trace", true);
436436
}
437+
438+
if(cmdline.isset("symex-coverage-report"))
439+
options.set_option(
440+
"symex-coverage-report",
441+
cmdline.get_value("symex-coverage-report"));
437442
}
438443

439444
/*******************************************************************\
@@ -1086,6 +1091,7 @@ void cbmc_parse_optionst::help()
10861091
"\n"
10871092
"Analysis options:\n"
10881093
" --show-properties show the properties, but don't run analysis\n" // NOLINT(*)
1094+
" --symex-coverage-report f generate a Cobertura XML coverage report in f\n"
10891095
" --property id only check one specific property\n"
10901096
" --stop-on-fail stop analysis once a failed property is detected\n" // NOLINT(*)
10911097
" --trace give a counterexample trace for failed properties\n" //NOLINT(*)

src/cbmc/cbmc_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class optionst;
4646
"(error-label):(verbosity):(no-library)" \
4747
"(nondet-static)" \
4848
"(version)" \
49-
"(cover):" \
49+
"(cover):(symex-coverage-report):" \
5050
"(mm):" \
5151
"(i386-linux)(i386-macos)(i386-win32)(win32)(winx64)(gcc)" \
5252
"(ppc-macos)(unsigned-char)" \

src/cbmc/symex_bmc.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ symex_bmct::symex_bmct(
2929
symbol_tablet &_new_symbol_table,
3030
symex_targett &_target):
3131
goto_symext(_ns, _new_symbol_table, _target),
32-
max_unwind_is_set(false)
32+
record_coverage(false),
33+
max_unwind_is_set(false),
34+
symex_coverage(_ns)
3335
{
3436
}
3537

@@ -61,6 +63,10 @@ void symex_bmct::symex_step(
6163
last_source_location=source_location;
6264
}
6365

66+
if(record_coverage &&
67+
!state.guard.is_false())
68+
symex_coverage.covered(state.source.pc);
69+
6470
goto_symext::symex_step(goto_functions, state);
6571
}
6672

src/cbmc/symex_bmc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <goto-symex/goto_symex.h>
1515

16+
#include "symex_coverage.h"
17+
1618
class symex_bmct:
1719
public goto_symext,
1820
public messaget
@@ -49,6 +51,15 @@ class symex_bmct:
4951
loop_limits[id]=limit;
5052
}
5153

54+
bool output_coverage_report(
55+
const goto_functionst &goto_functions,
56+
const std::string &path) const
57+
{
58+
return symex_coverage.generate_report(goto_functions, path);
59+
}
60+
61+
bool record_coverage;
62+
5263
protected:
5364
// We have
5465
// 1) a global limit (max_unwind)
@@ -85,6 +96,8 @@ class symex_bmct:
8596
virtual void no_body(const irep_idt &identifier);
8697

8798
std::unordered_set<irep_idt, irep_id_hash> body_warnings;
99+
100+
symex_coveraget symex_coverage;
88101
};
89102

90103
#endif // CPROVER_CBMC_SYMEX_BMC_H

0 commit comments

Comments
 (0)