Skip to content

Commit 215c7ae

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 59c882b commit 215c7ae

File tree

2 files changed

+32
-48
lines changed

2 files changed

+32
-48
lines changed

src/goto-instrument/cover.cpp

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,18 +1190,15 @@ void instrument_cover_goals(
11901190
const symbol_tablet &symbol_table,
11911191
goto_programt &goto_program,
11921192
coverage_criteriont criterion,
1193-
message_handlert &message_handler,
1194-
bool function_only)
1193+
message_handlert &message_handler)
11951194
{
11961195
coverage_goalst goals; // empty already covered goals
11971196
instrument_cover_goals(
11981197
symbol_table,
11991198
goto_program,
12001199
criterion,
12011200
message_handler,
1202-
goals,
1203-
function_only,
1204-
false);
1201+
goals);
12051202
}
12061203

12071204
/// Call a goto_program trivial unless it has: * Any declarations * At least 2
@@ -1235,14 +1232,8 @@ void instrument_cover_goals(
12351232
goto_programt &goto_program,
12361233
coverage_criteriont criterion,
12371234
message_handlert &message_handler,
1238-
coverage_goalst &goals,
1239-
bool function_only,
1240-
bool ignore_trivial)
1235+
coverage_goalst &goals)
12411236
{
1242-
// exclude trivial coverage goals of a goto program
1243-
if(ignore_trivial && program_is_trivial(goto_program))
1244-
return;
1245-
12461237
// ignore if built-in library
12471238
if(!goto_program.instructions.empty() &&
12481239
goto_program.instructions.front().source_location.is_built_in())
@@ -1259,19 +1250,11 @@ void instrument_cover_goals(
12591250

12601251
Forall_goto_program_instructions(i_it, goto_program)
12611252
{
1262-
std::string curr_function=id2string(i_it->function);
1263-
1264-
// if the --cover-function-only flag is set, then we only add coverage
1265-
// instrumentation for the entry function
1266-
bool cover_curr_function=
1267-
!function_only ||
1268-
curr_function.find(config.main)!=std::string::npos;
1269-
12701253
switch(criterion)
12711254
{
12721255
case coverage_criteriont::ASSERTION:
12731256
// turn into 'assert(false)' to avoid simplification
1274-
if(i_it->is_assert() && cover_curr_function)
1257+
if(i_it->is_assert())
12751258
{
12761259
i_it->guard=false_exprt();
12771260
i_it->source_location.set(ID_coverage_criterion, coverage_criterion);
@@ -1282,7 +1265,7 @@ void instrument_cover_goals(
12821265

12831266
case coverage_criteriont::COVER:
12841267
// turn __CPROVER_cover(x) into 'assert(!x)'
1285-
if(i_it->is_function_call() && cover_curr_function)
1268+
if(i_it->is_function_call())
12861269
{
12871270
const code_function_callt &code_function_call=
12881271
to_code_function_call(i_it->code);
@@ -1324,8 +1307,7 @@ void instrument_cover_goals(
13241307
// check whether the current goal already exists
13251308
if(!goals.is_existing_goal(source_location) &&
13261309
!source_location.get_file().empty() &&
1327-
!source_location.is_built_in() &&
1328-
cover_curr_function)
1310+
!source_location.is_built_in())
13291311
{
13301312
std::string comment="block "+b;
13311313
const irep_idt function=i_it->function;
@@ -1348,8 +1330,7 @@ void instrument_cover_goals(
13481330
if(i_it->is_assert())
13491331
i_it->make_skip();
13501332

1351-
if(i_it==goto_program.instructions.begin() &&
1352-
cover_curr_function)
1333+
if(i_it==goto_program.instructions.begin())
13531334
{
13541335
// we want branch coverage to imply 'entry point of function'
13551336
// coverage
@@ -1367,7 +1348,7 @@ void instrument_cover_goals(
13671348
t->function=i_it->function;
13681349
}
13691350

1370-
if(i_it->is_goto() && !i_it->guard.is_true() && cover_curr_function &&
1351+
if(i_it->is_goto() && !i_it->guard.is_true() &&
13711352
!i_it->source_location.is_built_in())
13721353
{
13731354
std::string b=
@@ -1406,7 +1387,7 @@ void instrument_cover_goals(
14061387
i_it->make_skip();
14071388

14081389
// Conditions are all atomic predicates in the programs.
1409-
if(cover_curr_function && !i_it->source_location.is_built_in())
1390+
if(!i_it->source_location.is_built_in())
14101391
{
14111392
const std::set<exprt> conditions=collect_conditions(i_it);
14121393

@@ -1448,7 +1429,7 @@ void instrument_cover_goals(
14481429
i_it->make_skip();
14491430

14501431
// Decisions are maximal Boolean combinations of conditions.
1451-
if(cover_curr_function && !i_it->source_location.is_built_in())
1432+
if(!i_it->source_location.is_built_in())
14521433
{
14531434
const std::set<exprt> decisions=collect_decisions(i_it);
14541435

@@ -1494,7 +1475,7 @@ void instrument_cover_goals(
14941475
// 3. Each condition in a decision takes every possible outcome
14951476
// 4. Each condition in a decision is shown to independently
14961477
// affect the outcome of the decision.
1497-
if(cover_curr_function && !i_it->source_location.is_built_in())
1478+
if(!i_it->source_location.is_built_in())
14981479
{
14991480
const std::set<exprt> conditions=collect_conditions(i_it);
15001481
const std::set<exprt> decisions=collect_decisions(i_it);
@@ -1594,7 +1575,6 @@ void instrument_cover_goals(
15941575
coverage_criteriont criterion,
15951576
message_handlert &message_handler,
15961577
coverage_goalst &goals,
1597-
bool function_only,
15981578
bool ignore_trivial,
15991579
const std::string &cover_include_pattern)
16001580
{
@@ -1604,6 +1584,10 @@ void instrument_cover_goals(
16041584

16051585
Forall_goto_functions(f_it, goto_functions)
16061586
{
1587+
// exclude trivial coverage goals of a goto program
1588+
if(ignore_trivial && program_is_trivial(f_it->second.body))
1589+
return;
1590+
16071591
if(f_it->first==goto_functions.entry_point() ||
16081592
f_it->first==(CPROVER_PREFIX "initialize") ||
16091593
f_it->second.is_hidden() ||
@@ -1619,18 +1603,15 @@ void instrument_cover_goals(
16191603
f_it->second.body,
16201604
criterion,
16211605
message_handler,
1622-
goals,
1623-
function_only,
1624-
ignore_trivial);
1606+
goals);
16251607
}
16261608
}
16271609

16281610
void instrument_cover_goals(
16291611
const symbol_tablet &symbol_table,
16301612
goto_functionst &goto_functions,
16311613
coverage_criteriont criterion,
1632-
message_handlert &message_handler,
1633-
bool function_only)
1614+
message_handlert &message_handler)
16341615
{
16351616
// empty set of existing goals
16361617
coverage_goalst goals;
@@ -1640,7 +1621,6 @@ void instrument_cover_goals(
16401621
criterion,
16411622
message_handler,
16421623
goals,
1643-
function_only,
16441624
false,
16451625
"");
16461626
}
@@ -1714,6 +1694,16 @@ bool instrument_cover_goals(
17141694
}
17151695
}
17161696

1697+
// cover entry point function only
1698+
std::string cover_include_pattern=cmdline.get_value("cover-include-pattern");
1699+
if(cmdline.isset("cover-function-only"))
1700+
{
1701+
std::regex special_characters(
1702+
"\\.|\\\\|\\*|\\+|\\?|\\{|\\}|\\[|\\]|\\(|\\)|\\^|\\$|\\|");
1703+
cover_include_pattern=
1704+
std::regex_replace(config.main, special_characters, "\\$&");
1705+
}
1706+
17171707
// check existing test goals
17181708
coverage_goalst existing_goals;
17191709
if(cmdline.isset("existing-coverage"))
@@ -1744,9 +1734,8 @@ bool instrument_cover_goals(
17441734
criterion,
17451735
message_handler,
17461736
existing_goals,
1747-
cmdline.isset("cover-function-only"),
17481737
cmdline.isset("no-trivial-tests"),
1749-
cmdline.get_value("cover-include-pattern"));
1738+
cover_include_pattern);
17501739
}
17511740

17521741
// check whether all existing goals match with instrumented goals

src/goto-instrument/cover.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,29 @@ void instrument_cover_goals(
4949
const symbol_tablet &,
5050
goto_functionst &,
5151
coverage_criteriont,
52-
message_handlert &message_handler,
53-
bool function_only=false);
52+
message_handlert &message_handler);
5453

5554
void instrument_cover_goals(
5655
const symbol_tablet &,
5756
goto_programt &,
5857
coverage_criteriont,
59-
message_handlert &message_handler,
60-
bool function_only=false);
58+
message_handlert &message_handler);
6159

6260
void instrument_cover_goals(
6361
const symbol_tablet &,
6462
goto_functionst &,
6563
coverage_criteriont,
6664
message_handlert &message_handler,
6765
coverage_goalst &,
68-
bool function_only=false,
6966
bool ignore_trivial=false,
70-
const std::string &cover_inclue_pattern="");
67+
const std::string &cover_include_pattern="");
7168

7269
void instrument_cover_goals(
7370
const symbol_tablet &,
7471
goto_programt &,
7572
coverage_criteriont,
7673
message_handlert &message_handler,
77-
coverage_goalst &goals,
78-
bool function_only=false,
79-
bool ignore_trivial=false);
74+
coverage_goalst &goals);
8075

8176
bool instrument_cover_goals(
8277
const cmdlinet &,

0 commit comments

Comments
 (0)