Skip to content

Commit 6129d36

Browse files
author
Daniel Kroening
committed
beginnings of instrumentation-based coverage
1 parent 8416727 commit 6129d36

File tree

7 files changed

+96
-15
lines changed

7 files changed

+96
-15
lines changed

src/cbmc/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
1919
../pointer-analysis/goto_program_dereference$(OBJEXT) \
2020
../goto-instrument/full_slicer$(OBJEXT) \
2121
../goto-instrument/nondet_static$(OBJEXT) \
22+
../goto-instrument/cover$(OBJEXT) \
2223
../analyses/analyses$(LIBEXT) \
2324
../langapi/langapi$(LIBEXT) \
2425
../xmllang/xmllang$(LIBEXT) \

src/cbmc/cbmc_parse_options.cpp

+35-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ Author: Daniel Kroening, [email protected]
3737
#include <goto-programs/string_instrumentation.h>
3838
#include <goto-programs/loop_ids.h>
3939
#include <goto-programs/link_to_library.h>
40+
#include <goto-programs/remove_skip.h>
4041

4142
#include <goto-instrument/full_slicer.h>
4243
#include <goto-instrument/nondet_static.h>
44+
#include <goto-instrument/cover.h>
4345

4446
#include <pointer-analysis/add_failed_symbols.h>
4547

@@ -909,16 +911,43 @@ bool cbmc_parse_optionst::process_goto_program(
909911

910912
// recalculate numbers, etc.
911913
goto_functions.update();
912-
914+
913915
// add loop ids
914916
goto_functions.compute_loop_numbers();
915917

916-
// if we aim to cover assertions, replace
917-
// all assertions by false to prevent simplification
918+
// instrument cover goals
918919

919-
if(cmdline.isset("cover") &&
920-
cmdline.get_value("cover")=="assertions")
921-
make_assertions_false(goto_functions);
920+
if(cmdline.isset("cover"))
921+
{
922+
std::string criterion=cmdline.get_value("cover");
923+
924+
coverage_criteriont c;
925+
926+
if(criterion=="assertion" || criterion=="assertions")
927+
c=coverage_criteriont::ASSERTION;
928+
else if(criterion=="path" || criterion=="paths")
929+
c=coverage_criteriont::PATH;
930+
else if(criterion=="branch" || criterion=="branches")
931+
c=coverage_criteriont::BRANCH;
932+
else if(criterion=="location" || criterion=="locations")
933+
c=coverage_criteriont::LOCATION;
934+
else if(criterion=="decision" || criterion=="decisions")
935+
c=coverage_criteriont::DECISION;
936+
else if(criterion=="condition" || criterion=="conditions")
937+
c=coverage_criteriont::CONDITION;
938+
else if(criterion=="mcdc")
939+
c=coverage_criteriont::MCDC;
940+
else
941+
{
942+
error() << "unknown coverage criterion" << eom;
943+
return false;
944+
}
945+
946+
instrument_cover_goals(symbol_table, goto_functions, c);
947+
}
948+
949+
// remove skips
950+
remove_skip(goto_functions);
922951

923952
// show it?
924953
if(cmdline.isset("show-loops"))

src/goto-instrument/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SRC = goto_instrument_parse_options.cpp rw_set.cpp \
2323
wmm/event_graph.cpp wmm/pair_collection.cpp \
2424
goto_instrument_main.cpp horn_encoding.cpp \
2525
thread_instrumentation.cpp skip_loops.cpp loop_utils.cpp \
26-
code_contracts.cpp
26+
code_contracts.cpp cover.cpp
2727

2828
OBJ += ../ansi-c/ansi-c$(LIBEXT) \
2929
../cpp/cpp$(LIBEXT) \

src/goto-instrument/cover.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************\
2+
3+
Module: Coverage Instrumentation
4+
5+
Author: Daniel Kroening
6+
7+
Date: May 2016
8+
9+
\*******************************************************************/
10+
11+
#include "cover.h"
12+
13+
void instrument_cover_goals(
14+
const symbol_tablet &symbol_table,
15+
goto_programt &goto_program,
16+
coverage_criteriont criterion)
17+
{
18+
}
19+
20+
void instrument_cover_goals(
21+
const symbol_tablet &symbol_table,
22+
goto_functionst &goto_functions,
23+
coverage_criteriont criterion)
24+
{
25+
}

src/goto-instrument/cover.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************\
2+
3+
Module: Coverage Instrumentation
4+
5+
Author: Daniel Kroening
6+
7+
Date: May 2016
8+
9+
\*******************************************************************/
10+
11+
#ifndef CPROVER_COVER_H
12+
#define CPROVER_COVER_H
13+
14+
#include <goto-programs/goto_model.h>
15+
16+
enum class coverage_criteriont {
17+
LOCATION, BRANCH, DECISION, CONDITION,
18+
PATH, MCDC, ASSERTION };
19+
20+
void instrument_cover_goals(
21+
const symbol_tablet &symbol_table,
22+
goto_programt &goto_program,
23+
coverage_criteriont);
24+
25+
void instrument_cover_goals(
26+
const symbol_tablet &symbol_table,
27+
goto_functionst &goto_functions,
28+
coverage_criteriont);
29+
30+
#endif

src/goto-programs/goto_convert_functions.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Date: June 2003
1717

1818
#include "goto_convert_functions.h"
1919
#include "goto_inline.h"
20-
#include "remove_skip.h"
2120

2221
/*******************************************************************\
2322
@@ -294,11 +293,6 @@ void goto_convert_functionst::convert_function(const irep_idt &identifier)
294293
Forall_goto_program_instructions(i_it, f.body)
295294
i_it->function=identifier;
296295

297-
// remove_skip depends on the target numbers
298-
f.body.compute_target_numbers();
299-
300-
remove_skip(f.body);
301-
302296
f.body.update();
303297

304298
if(hide(f.body))

src/goto-programs/remove_skip.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ static bool is_skip(goto_programt::instructionst::iterator it)
4141
goto_programt::instructionst::iterator next_it=it;
4242
next_it++;
4343

44-
// a branch to the next instruction is a skip
45-
return it->targets.front()==next_it;
44+
// A branch to the next instruction is a skip
45+
// We also require the guard to be 'true'
46+
return it->guard.is_true() &&
47+
it->targets.front()==next_it;
4648
}
4749

4850
if(it->is_other())

0 commit comments

Comments
 (0)