Skip to content

Commit c172622

Browse files
added warning message for incomplete/incorrect goals
1 parent 0d39c4a commit c172622

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

src/goto-instrument/cover.cpp

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ bool coverage_goalst::get_coverage_goals(
142142
for(const auto &each_goal : goals_in_json["goals"].array)
143143
{
144144
// get and set the bytecode_index
145-
irep_idt bytecode_index=
145+
irep_idt bytecodeIndex=
146146
each_goal["sourceLocation"]["bytecode_index"].value;
147-
source_location.set_java_bytecode_index(bytecode_index);
147+
source_location.set_java_bytecode_index(bytecodeIndex);
148148

149149
// get and set the file
150150
irep_idt file=each_goal["sourceLocation"]["file"].value;
@@ -166,25 +166,47 @@ bool coverage_goalst::get_coverage_goals(
166166
return false;
167167
}
168168

169+
/// store existing goal
170+
/// \param goal: source location of the existing goal
169171
void coverage_goalst::add_goal(source_locationt goal)
170172
{
171-
existing_goals.push_back(goal);
173+
existing_goals[goal]=false;
174+
}
175+
176+
/// check whether we have an existing goal that is uncovered
177+
/// \param msg: message to be printed about the uncovered goal
178+
void coverage_goalst::check_uncovered_goals(messaget msg)
179+
{
180+
for(auto const &existing_loc : existing_goals)
181+
{
182+
if(!existing_loc.second)
183+
{
184+
msg.warning() << "Warning: existing goal in file "
185+
<< existing_loc.first.get_file()
186+
<< " line " << existing_loc.first.get_line()
187+
<< " function " << existing_loc.first.get_function()
188+
<< " is uncovered" << messaget::eom;
189+
}
190+
}
172191
}
173192

174193
/// compare the value of the current goal to the existing ones
175194
/// \param source_loc: source location of the current goal
176195
/// \return true : if the current goal exists false : otherwise
177-
bool coverage_goalst::is_existing_goal(source_locationt source_loc) const
196+
bool coverage_goalst::is_existing_goal(source_locationt source_loc)
178197
{
179-
for(const auto &existing_loc : existing_goals)
198+
for(auto const &existing_loc : existing_goals)
180199
{
181-
if((source_loc.get_file()==existing_loc.get_file()) &&
182-
(source_loc.get_function()==existing_loc.get_function()) &&
183-
(source_loc.get_line()==existing_loc.get_line()) &&
200+
if((source_loc.get_file()==existing_loc.first.get_file()) &&
201+
(source_loc.get_function()==existing_loc.first.get_function()) &&
202+
(source_loc.get_line()==existing_loc.first.get_line()) &&
184203
(source_loc.get_java_bytecode_index().empty() ||
185204
(source_loc.get_java_bytecode_index()==
186-
existing_loc.get_java_bytecode_index())))
187-
return true;
205+
existing_loc.first.get_java_bytecode_index())))
206+
{
207+
existing_goals[existing_loc.first]=true;
208+
return true;
209+
}
188210
}
189211
return false;
190212
}
@@ -998,7 +1020,7 @@ void instrument_cover_goals(
9981020
const symbol_tablet &symbol_table,
9991021
goto_programt &goto_program,
10001022
coverage_criteriont criterion,
1001-
const coverage_goalst &goals,
1023+
coverage_goalst &goals,
10021024
bool function_only,
10031025
bool ignore_trivial)
10041026
{
@@ -1342,7 +1364,7 @@ void instrument_cover_goals(
13421364
const symbol_tablet &symbol_table,
13431365
goto_functionst &goto_functions,
13441366
coverage_criteriont criterion,
1345-
const coverage_goalst &goals,
1367+
coverage_goalst &goals,
13461368
bool function_only,
13471369
bool ignore_trivial)
13481370
{
@@ -1450,10 +1472,10 @@ bool instrument_cover_goals(
14501472
}
14511473

14521474
// check existing test goals
1453-
coverage_goalst existing_goals;
1475+
static coverage_goalst existing_goals;
14541476
if(cmdline.isset("existing-coverage"))
14551477
{
1456-
msg.status() << "Check existing coverage goals" << messaget::eom;
1478+
msg.status() << "Add existing coverage goals" << messaget::eom;
14571479
// get file with covered test goals
14581480
const std::string coverage=cmdline.get_value("existing-coverage");
14591481
// get a coverage_goalst object
@@ -1477,6 +1499,10 @@ bool instrument_cover_goals(
14771499
cmdline.isset("no-trivial-tests"));
14781500
}
14791501

1502+
// check whether all existing goals have been covered
1503+
msg.status() << "Checking uncovered goals" << messaget::eom;
1504+
existing_goals.check_uncovered_goals(msg);
1505+
14801506
if(cmdline.isset("cover-traces-must-terminate"))
14811507
{
14821508
// instrument an additional goal in CPROVER_START. This will rephrase

src/goto-instrument/cover.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ class coverage_goalst
2525
message_handlert &message_handler,
2626
coverage_goalst &goals);
2727
void add_goal(source_locationt goal);
28-
bool is_existing_goal(source_locationt source_loc) const;
28+
bool is_existing_goal(source_locationt source_loc);
29+
void check_uncovered_goals(messaget msg);
2930

3031
private:
31-
std::vector<source_locationt> existing_goals;
32+
std::map<source_locationt, bool> existing_goals;
3233
};
3334

3435
enum class coverage_criteriont
@@ -56,15 +57,15 @@ void instrument_cover_goals(
5657
const symbol_tablet &symbol_table,
5758
goto_functionst &goto_functions,
5859
coverage_criteriont,
59-
const coverage_goalst &goals,
60+
coverage_goalst &goals,
6061
bool function_only=false,
6162
bool ignore_trivial=false);
6263

6364
void instrument_cover_goals(
6465
const symbol_tablet &symbol_table,
6566
goto_programt &goto_program,
6667
coverage_criteriont,
67-
const coverage_goalst &goals,
68+
coverage_goalst &goals,
6869
bool function_only=false,
6970
bool ignore_trivial=false);
7071

0 commit comments

Comments
 (0)