Skip to content

Commit 6c39443

Browse files
Remove existing coverage goals
This is obsolete in cover.cpp as the --existing-coverage option will be implemented as a separate pass.
1 parent a22dd1c commit 6c39443

File tree

2 files changed

+3
-192
lines changed

2 files changed

+3
-192
lines changed

src/goto-instrument/cover.cpp

+3-170
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Date: May 2016
2525
#include <util/cprover_prefix.h>
2626
#include <util/config.h>
2727

28-
#include <json/json_parser.h>
2928
#include <util/message.h>
3029

3130
namespace
@@ -293,139 +292,6 @@ class basic_blockst
293292
};
294293
}
295294

296-
bool coverage_goalst::get_coverage_goals(
297-
const std::string &coverage_file,
298-
message_handlert &message_handler,
299-
coverage_goalst &goals,
300-
const irep_idt &mode)
301-
{
302-
messaget message(message_handler);
303-
jsont json;
304-
source_locationt source_location;
305-
306-
message.status() << "Load existing coverage goals\n";
307-
308-
// check coverage file
309-
if(parse_json(coverage_file, message_handler, json))
310-
{
311-
message.error() << coverage_file << " file is not a valid json file"
312-
<< messaget::eom;
313-
return true;
314-
}
315-
316-
// make sure that we have an array of elements
317-
if(!json.is_array())
318-
{
319-
message.error() << "expecting an array in the " << coverage_file
320-
<< " file, but got "
321-
<< json << messaget::eom;
322-
return true;
323-
}
324-
325-
// traverse the given JSON file
326-
for(const auto &each_goal : json.array)
327-
{
328-
// ensure minimal requirements for a goal entry
329-
PRECONDITION(
330-
(!each_goal["goal"].is_null()) ||
331-
(!each_goal["sourceLocation"]["bytecodeIndex"].is_null()) ||
332-
(!each_goal["sourceLocation"]["file"].is_null() &&
333-
!each_goal["sourceLocation"]["function"].is_null() &&
334-
!each_goal["sourceLocation"]["line"].is_null()));
335-
336-
// check whether bytecodeIndex is provided for Java programs
337-
if(mode==ID_java &&
338-
each_goal["sourceLocation"]["bytecodeIndex"].is_null())
339-
{
340-
messaget message(message_handler);
341-
message.error() << coverage_file
342-
<< " file does not contain bytecodeIndex"
343-
<< messaget::eom;
344-
return true;
345-
}
346-
347-
if(!each_goal["sourceLocation"]["bytecodeIndex"].is_null())
348-
{
349-
// get and set the bytecodeIndex
350-
irep_idt bytecode_index=
351-
each_goal["sourceLocation"]["bytecodeIndex"].value;
352-
source_location.set_java_bytecode_index(bytecode_index);
353-
}
354-
355-
if(!each_goal["sourceLocation"]["file"].is_null())
356-
{
357-
// get and set the file
358-
irep_idt file=each_goal["sourceLocation"]["file"].value;
359-
source_location.set_file(file);
360-
}
361-
362-
if(!each_goal["sourceLocation"]["function"].is_null())
363-
{
364-
// get and set the function
365-
irep_idt function=each_goal["sourceLocation"]["function"].value;
366-
source_location.set_function(function);
367-
}
368-
369-
if(!each_goal["sourceLocation"]["line"].is_null())
370-
{
371-
// get and set the line
372-
irep_idt line=each_goal["sourceLocation"]["line"].value;
373-
source_location.set_line(line);
374-
}
375-
376-
// store the existing goal
377-
goals.add_goal(source_location);
378-
message.status() << " " << source_location << "\n";
379-
}
380-
message.status() << messaget::eom;
381-
382-
return false;
383-
}
384-
385-
/// store existing goal
386-
/// \param goal: source location of the existing goal
387-
void coverage_goalst::add_goal(source_locationt goal)
388-
{
389-
existing_goals[goal]=false;
390-
}
391-
392-
/// check whether we have an existing goal that does not match
393-
/// an instrumented goal
394-
/// \param msg: Message stream
395-
void coverage_goalst::check_existing_goals(messaget &msg)
396-
{
397-
for(const auto &existing_loc : existing_goals)
398-
{
399-
if(!existing_loc.second)
400-
{
401-
msg.warning()
402-
<< "Warning: unmatched existing goal "
403-
<< existing_loc.first << messaget::eom;
404-
}
405-
}
406-
}
407-
408-
/// compare the value of the current goal to the existing ones
409-
/// \param source_loc: source location of the current goal
410-
/// \return true : if the current goal exists false : otherwise
411-
bool coverage_goalst::is_existing_goal(source_locationt source_loc)
412-
{
413-
for(const auto &existing_loc : existing_goals)
414-
{
415-
if((source_loc.get_file()==existing_loc.first.get_file()) &&
416-
(source_loc.get_function()==existing_loc.first.get_function()) &&
417-
(source_loc.get_line()==existing_loc.first.get_line()) &&
418-
(source_loc.get_java_bytecode_index().empty() ||
419-
(source_loc.get_java_bytecode_index()==
420-
existing_loc.first.get_java_bytecode_index())))
421-
{
422-
existing_goals[existing_loc.first]=true;
423-
return true;
424-
}
425-
}
426-
return false;
427-
}
428-
429295
const char *as_string(coverage_criteriont c)
430296
{
431297
switch(c)
@@ -1196,13 +1062,11 @@ void instrument_cover_goals(
11961062
message_handlert &message_handler,
11971063
bool function_only)
11981064
{
1199-
coverage_goalst goals; // empty already covered goals
12001065
instrument_cover_goals(
12011066
symbol_table,
12021067
goto_program,
12031068
criterion,
12041069
message_handler,
1205-
goals,
12061070
function_only,
12071071
false);
12081072
}
@@ -1238,7 +1102,6 @@ void instrument_cover_goals(
12381102
goto_programt &goto_program,
12391103
coverage_criteriont criterion,
12401104
message_handlert &message_handler,
1241-
coverage_goalst &goals,
12421105
bool function_only,
12431106
bool ignore_trivial)
12441107
{
@@ -1325,10 +1188,9 @@ void instrument_cover_goals(
13251188
basic_blocks.source_location_of(block_nr);
13261189

13271190
// check whether the current goal already exists
1328-
if(!goals.is_existing_goal(source_location) &&
1329-
!source_location.get_file().empty() &&
1330-
!source_location.is_built_in() &&
1331-
cover_curr_function)
1191+
if(
1192+
!source_location.get_file().empty() &&
1193+
!source_location.is_built_in() && cover_curr_function)
13321194
{
13331195
std::string comment="block "+b;
13341196
const irep_idt function=i_it->function;
@@ -1597,7 +1459,6 @@ void instrument_cover_goals(
15971459
goto_functionst &goto_functions,
15981460
coverage_criteriont criterion,
15991461
message_handlert &message_handler,
1600-
coverage_goalst &goals,
16011462
bool function_only,
16021463
bool ignore_trivial,
16031464
const std::string &cover_include_pattern)
@@ -1623,7 +1484,6 @@ void instrument_cover_goals(
16231484
f_it->second.body,
16241485
criterion,
16251486
message_handler,
1626-
goals,
16271487
function_only,
16281488
ignore_trivial);
16291489
}
@@ -1636,14 +1496,11 @@ void instrument_cover_goals(
16361496
message_handlert &message_handler,
16371497
bool function_only)
16381498
{
1639-
// empty set of existing goals
1640-
coverage_goalst goals;
16411499
instrument_cover_goals(
16421500
symbol_table,
16431501
goto_functions,
16441502
criterion,
16451503
message_handler,
1646-
goals,
16471504
function_only,
16481505
false,
16491506
"");
@@ -1718,26 +1575,6 @@ bool instrument_cover_goals(
17181575
}
17191576
}
17201577

1721-
// check existing test goals
1722-
coverage_goalst existing_goals;
1723-
if(cmdline.isset("existing-coverage"))
1724-
{
1725-
// get the mode to ensure invariants
1726-
// (e.g., bytecodeIndex for Java programs)
1727-
namespacet ns(symbol_table);
1728-
const irep_idt &mode=ns.lookup(goto_functions.entry_point()).mode;
1729-
1730-
// get file with covered test goals
1731-
const std::string coverage=cmdline.get_value("existing-coverage");
1732-
// get a coverage_goalst object
1733-
if(coverage_goalst::get_coverage_goals(
1734-
coverage, message_handler, existing_goals, mode))
1735-
{
1736-
msg.error() << "Loading existing coverage goals failed" << messaget::eom;
1737-
return true;
1738-
}
1739-
}
1740-
17411578
msg.status() << "Instrumenting coverage goals" << messaget::eom;
17421579

17431580
for(const auto &criterion : criteria)
@@ -1747,15 +1584,11 @@ bool instrument_cover_goals(
17471584
goto_functions,
17481585
criterion,
17491586
message_handler,
1750-
existing_goals,
17511587
cmdline.isset("cover-function-only"),
17521588
cmdline.isset("no-trivial-tests"),
17531589
cmdline.get_value("cover-include-pattern"));
17541590
}
17551591

1756-
// check whether all existing goals match with instrumented goals
1757-
existing_goals.check_existing_goals(msg);
1758-
17591592
if(cmdline.isset("cover-traces-must-terminate"))
17601593
{
17611594
// instrument an additional goal in CPROVER_START. This will rephrase

src/goto-instrument/cover.h

-22
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,11 @@ Date: May 2016
2020
class message_handlert;
2121
class messaget;
2222

23-
class coverage_goalst
24-
{
25-
public:
26-
static bool get_coverage_goals(
27-
const std::string &coverage,
28-
message_handlert &message_handler,
29-
coverage_goalst &goals,
30-
const irep_idt &mode);
31-
void add_goal(source_locationt goal);
32-
bool is_existing_goal(source_locationt source_loc);
33-
void check_existing_goals(messaget &msg);
34-
35-
private:
36-
std::map<source_locationt, bool> existing_goals;
37-
};
38-
3923
enum class coverage_criteriont
4024
{
4125
LOCATION, BRANCH, DECISION, CONDITION,
4226
PATH, MCDC, ASSERTION, COVER };
4327

44-
bool consider_goals(
45-
const goto_programt &,
46-
coverage_goalst &);
47-
4828
void instrument_cover_goals(
4929
const symbol_tablet &,
5030
goto_functionst &,
@@ -64,7 +44,6 @@ void instrument_cover_goals(
6444
goto_functionst &,
6545
coverage_criteriont,
6646
message_handlert &message_handler,
67-
coverage_goalst &,
6847
bool function_only=false,
6948
bool ignore_trivial=false,
7049
const std::string &cover_inclue_pattern="");
@@ -74,7 +53,6 @@ void instrument_cover_goals(
7453
goto_programt &,
7554
coverage_criteriont,
7655
message_handlert &message_handler,
77-
coverage_goalst &goals,
7856
bool function_only=false,
7957
bool ignore_trivial=false);
8058

0 commit comments

Comments
 (0)