Skip to content

Commit 0fc08f3

Browse files
Replace cover-function-only by cover-include-pattern
cover-function-only (instrumentating coverage goals in the entry point function only) is now implemented with the help of cover-include-pattern (regex matching of functions to be instrumented). This is to avoid potential consistencies due to providing two mechanisms for filtering functions. cover-function-only has priority over the given cover-include-pattern.
1 parent d9cc0c0 commit 0fc08f3

File tree

2 files changed

+29
-68
lines changed

2 files changed

+29
-68
lines changed

src/goto-instrument/cover.cpp

+25-53
Original file line numberDiff line numberDiff line change
@@ -1055,22 +1055,6 @@ std::set<exprt> collect_decisions(const goto_programt::const_targett t)
10551055
return std::set<exprt>();
10561056
}
10571057

1058-
void instrument_cover_goals(
1059-
const symbol_tablet &symbol_table,
1060-
goto_programt &goto_program,
1061-
coverage_criteriont criterion,
1062-
message_handlert &message_handler,
1063-
bool function_only)
1064-
{
1065-
instrument_cover_goals(
1066-
symbol_table,
1067-
goto_program,
1068-
criterion,
1069-
message_handler,
1070-
function_only,
1071-
false);
1072-
}
1073-
10741058
/// Call a goto_program trivial unless it has: * Any declarations * At least 2
10751059
/// branches * At least 5 assignments
10761060
/// \par parameters: Program `goto_program`
@@ -1101,14 +1085,8 @@ void instrument_cover_goals(
11011085
const symbol_tablet &symbol_table,
11021086
goto_programt &goto_program,
11031087
coverage_criteriont criterion,
1104-
message_handlert &message_handler,
1105-
bool function_only,
1106-
bool ignore_trivial)
1088+
message_handlert &message_handler)
11071089
{
1108-
// exclude trivial coverage goals of a goto program
1109-
if(ignore_trivial && program_is_trivial(goto_program))
1110-
return;
1111-
11121090
// ignore if built-in library
11131091
if(!goto_program.instructions.empty() &&
11141092
goto_program.instructions.front().source_location.is_built_in())
@@ -1125,19 +1103,11 @@ void instrument_cover_goals(
11251103

11261104
Forall_goto_program_instructions(i_it, goto_program)
11271105
{
1128-
std::string curr_function=id2string(i_it->function);
1129-
1130-
// if the --cover-function-only flag is set, then we only add coverage
1131-
// instrumentation for the entry function
1132-
bool cover_curr_function=
1133-
!function_only ||
1134-
curr_function.find(config.main)!=std::string::npos;
1135-
11361106
switch(criterion)
11371107
{
11381108
case coverage_criteriont::ASSERTION:
11391109
// turn into 'assert(false)' to avoid simplification
1140-
if(i_it->is_assert() && cover_curr_function)
1110+
if(i_it->is_assert())
11411111
{
11421112
i_it->guard=false_exprt();
11431113
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
@@ -1148,7 +1118,7 @@ void instrument_cover_goals(
11481118

11491119
case coverage_criteriont::COVER:
11501120
// turn __CPROVER_cover(x) into 'assert(!x)'
1151-
if(i_it->is_function_call() && cover_curr_function)
1121+
if(i_it->is_function_call())
11521122
{
11531123
const code_function_callt &code_function_call=
11541124
to_code_function_call(i_it->code);
@@ -1190,7 +1160,7 @@ void instrument_cover_goals(
11901160
// check whether the current goal needs to be covered
11911161
if(
11921162
!source_location.get_file().empty() &&
1193-
!source_location.is_built_in() && cover_curr_function)
1163+
!source_location.is_built_in())
11941164
{
11951165
std::string comment="block "+b;
11961166
const irep_idt function=i_it->function;
@@ -1213,8 +1183,7 @@ void instrument_cover_goals(
12131183
if(i_it->is_assert())
12141184
i_it->make_skip();
12151185

1216-
if(i_it==goto_program.instructions.begin() &&
1217-
cover_curr_function)
1186+
if(i_it == goto_program.instructions.begin())
12181187
{
12191188
// we want branch coverage to imply 'entry point of function'
12201189
// coverage
@@ -1232,8 +1201,9 @@ void instrument_cover_goals(
12321201
t->function=i_it->function;
12331202
}
12341203

1235-
if(i_it->is_goto() && !i_it->guard.is_true() && cover_curr_function &&
1236-
!i_it->source_location.is_built_in())
1204+
if(
1205+
i_it->is_goto() && !i_it->guard.is_true() &&
1206+
!i_it->source_location.is_built_in())
12371207
{
12381208
std::string b=
12391209
std::to_string(basic_blocks.block_of(i_it)+1); // start with 1
@@ -1271,7 +1241,7 @@ void instrument_cover_goals(
12711241
i_it->make_skip();
12721242

12731243
// Conditions are all atomic predicates in the programs.
1274-
if(cover_curr_function && !i_it->source_location.is_built_in())
1244+
if(!i_it->source_location.is_built_in())
12751245
{
12761246
const std::set<exprt> conditions=collect_conditions(i_it);
12771247

@@ -1313,7 +1283,7 @@ void instrument_cover_goals(
13131283
i_it->make_skip();
13141284

13151285
// Decisions are maximal Boolean combinations of conditions.
1316-
if(cover_curr_function && !i_it->source_location.is_built_in())
1286+
if(!i_it->source_location.is_built_in())
13171287
{
13181288
const std::set<exprt> decisions=collect_decisions(i_it);
13191289

@@ -1359,7 +1329,7 @@ void instrument_cover_goals(
13591329
// 3. Each condition in a decision takes every possible outcome
13601330
// 4. Each condition in a decision is shown to independently
13611331
// affect the outcome of the decision.
1362-
if(cover_curr_function && !i_it->source_location.is_built_in())
1332+
if(!i_it->source_location.is_built_in())
13631333
{
13641334
const std::set<exprt> conditions=collect_conditions(i_it);
13651335
const std::set<exprt> decisions=collect_decisions(i_it);
@@ -1459,7 +1429,6 @@ void instrument_cover_goals(
14591429
goto_functionst &goto_functions,
14601430
coverage_criteriont criterion,
14611431
message_handlert &message_handler,
1462-
bool function_only,
14631432
bool ignore_trivial,
14641433
const std::string &cover_include_pattern)
14651434
{
@@ -1480,28 +1449,21 @@ void instrument_cover_goals(
14801449
continue;
14811450

14821451
instrument_cover_goals(
1483-
symbol_table,
1484-
f_it->second.body,
1485-
criterion,
1486-
message_handler,
1487-
function_only,
1488-
ignore_trivial);
1452+
symbol_table, f_it->second.body, criterion, message_handler);
14891453
}
14901454
}
14911455

14921456
void instrument_cover_goals(
14931457
const symbol_tablet &symbol_table,
14941458
goto_functionst &goto_functions,
14951459
coverage_criteriont criterion,
1496-
message_handlert &message_handler,
1497-
bool function_only)
1460+
message_handlert &message_handler)
14981461
{
14991462
instrument_cover_goals(
15001463
symbol_table,
15011464
goto_functions,
15021465
criterion,
15031466
message_handler,
1504-
function_only,
15051467
false,
15061468
"");
15071469
}
@@ -1575,6 +1537,17 @@ bool instrument_cover_goals(
15751537
}
15761538
}
15771539

1540+
// cover entry point function only
1541+
std::string cover_include_pattern =
1542+
cmdline.get_value("cover-include-pattern");
1543+
if(cmdline.isset("cover-function-only"))
1544+
{
1545+
std::regex special_characters(
1546+
"\\.|\\\\|\\*|\\+|\\?|\\{|\\}|\\[|\\]|\\(|\\)|\\^|\\$|\\|");
1547+
cover_include_pattern =
1548+
".*" + std::regex_replace(config.main, special_characters, "\\$&") + ".*";
1549+
}
1550+
15781551
msg.status() << "Instrumenting coverage goals" << messaget::eom;
15791552

15801553
for(const auto &criterion : criteria)
@@ -1584,9 +1557,8 @@ bool instrument_cover_goals(
15841557
goto_functions,
15851558
criterion,
15861559
message_handler,
1587-
cmdline.isset("cover-function-only"),
15881560
cmdline.isset("no-trivial-tests"),
1589-
cmdline.get_value("cover-include-pattern"));
1561+
cover_include_pattern);
15901562
}
15911563

15921564
if(cmdline.isset("cover-traces-must-terminate"))

src/goto-instrument/cover.h

+4-15
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,21 @@ void instrument_cover_goals(
2929
const symbol_tablet &,
3030
goto_functionst &,
3131
coverage_criteriont,
32-
message_handlert &message_handler,
33-
bool function_only=false);
32+
message_handlert &message_handler);
3433

3534
void instrument_cover_goals(
3635
const symbol_tablet &,
3736
goto_programt &,
3837
coverage_criteriont,
39-
message_handlert &message_handler,
40-
bool function_only=false);
38+
message_handlert &message_handler);
4139

4240
void instrument_cover_goals(
4341
const symbol_tablet &,
4442
goto_functionst &,
4543
coverage_criteriont,
4644
message_handlert &message_handler,
47-
bool function_only=false,
48-
bool ignore_trivial=false,
49-
const std::string &cover_inclue_pattern="");
50-
51-
void instrument_cover_goals(
52-
const symbol_tablet &,
53-
goto_programt &,
54-
coverage_criteriont,
55-
message_handlert &message_handler,
56-
bool function_only=false,
57-
bool ignore_trivial=false);
45+
bool ignore_trivial = false,
46+
const std::string &cover_include_pattern = "");
5847

5948
bool instrument_cover_goals(
6049
const cmdlinet &,

0 commit comments

Comments
 (0)