@@ -108,7 +108,8 @@ class basic_blockst
108
108
bool coverage_goalst::get_coverage_goals (
109
109
const std::string &coverage_file,
110
110
message_handlert &message_handler,
111
- coverage_goalst &goals)
111
+ coverage_goalst &goals,
112
+ const irep_idt &mode)
112
113
{
113
114
jsont json;
114
115
source_locationt source_location;
@@ -141,22 +142,53 @@ bool coverage_goalst::get_coverage_goals(
141
142
// store the source location for each existing goal
142
143
for (const auto &each_goal : goals_in_json[" goals" ].array )
143
144
{
144
- // get and set the bytecode_index
145
- irep_idt bytecodeIndex=
146
- each_goal[" sourceLocation" ][" bytecode_index" ].value ;
147
- source_location.set_java_bytecode_index (bytecodeIndex);
145
+ // ensure minimal requirements for a goal entry
146
+ PRECONDITION (
147
+ (!each_goal[" goal" ].is_null ()) ||
148
+ (!each_goal[" sourceLocation" ][" bytecode_index" ].is_null ()) ||
149
+ (!each_goal[" sourceLocation" ][" file" ].is_null () &&
150
+ !each_goal[" sourceLocation" ][" function" ].is_null () &&
151
+ !each_goal[" sourceLocation" ][" line" ].is_null ()));
152
+
153
+ // check whether bytecode_index is provided for Java programs
154
+ if (mode==ID_java &&
155
+ each_goal[" sourceLocation" ][" bytecode_index" ].is_null ())
156
+ {
157
+ messaget message (message_handler);
158
+ message.error () << coverage_file
159
+ << " file does not contain bytecode_index"
160
+ << messaget::eom;
161
+ return true ;
162
+ }
148
163
149
- // get and set the file
150
- irep_idt file=each_goal[" sourceLocation" ][" file" ].value ;
151
- source_location.set_file (file);
164
+ if (!each_goal[" sourceLocation" ][" bytecode_index" ].is_null ())
165
+ {
166
+ // get and set the bytecode_index
167
+ irep_idt bytecode_index=
168
+ each_goal[" sourceLocation" ][" bytecode_index" ].value ;
169
+ source_location.set_java_bytecode_index (bytecode_index);
170
+ }
152
171
153
- // get and set the function
154
- irep_idt function=each_goal[" sourceLocation" ][" function" ].value ;
155
- source_location.set_function (function);
172
+ if (!each_goal[" sourceLocation" ][" file" ].is_null ())
173
+ {
174
+ // get and set the file
175
+ irep_idt file=each_goal[" sourceLocation" ][" file" ].value ;
176
+ source_location.set_file (file);
177
+ }
156
178
157
- // get and set the line
158
- irep_idt line=each_goal[" sourceLocation" ][" line" ].value ;
159
- source_location.set_line (line);
179
+ if (!each_goal[" sourceLocation" ][" function" ].is_null ())
180
+ {
181
+ // get and set the function
182
+ irep_idt function=each_goal[" sourceLocation" ][" function" ].value ;
183
+ source_location.set_function (function);
184
+ }
185
+
186
+ if (!each_goal[" sourceLocation" ][" line" ].is_null ())
187
+ {
188
+ // get and set the line
189
+ irep_idt line=each_goal[" sourceLocation" ][" line" ].value ;
190
+ source_location.set_line (line);
191
+ }
160
192
161
193
// store the existing goal
162
194
goals.add_goal (source_location);
@@ -175,17 +207,18 @@ void coverage_goalst::add_goal(source_locationt goal)
175
207
176
208
// / check whether we have an existing goal that is uncovered
177
209
// / \param msg: message to be printed about the uncovered goal
178
- void coverage_goalst::check_uncovered_goals (messaget msg)
210
+ void coverage_goalst::check_uncovered_goals (messaget & msg)
179
211
{
180
- for (auto const &existing_loc : existing_goals)
212
+ for (const auto &existing_loc : existing_goals)
181
213
{
182
214
if (!existing_loc.second )
183
215
{
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;
216
+ msg.warning ()
217
+ << " Warning: existing goal in file "
218
+ << existing_loc.first .get_file ()
219
+ << " line " << existing_loc.first .get_line ()
220
+ << " function " << existing_loc.first .get_function ()
221
+ << " is uncovered" << messaget::eom;
189
222
}
190
223
}
191
224
}
@@ -195,7 +228,7 @@ void coverage_goalst::check_uncovered_goals(messaget msg)
195
228
// / \return true : if the current goal exists false : otherwise
196
229
bool coverage_goalst::is_existing_goal (source_locationt source_loc)
197
230
{
198
- for (auto const &existing_loc : existing_goals)
231
+ for (const auto &existing_loc : existing_goals)
199
232
{
200
233
if ((source_loc.get_file ()==existing_loc.first .get_file ()) &&
201
234
(source_loc.get_function ()==existing_loc.first .get_function ()) &&
@@ -1472,14 +1505,20 @@ bool instrument_cover_goals(
1472
1505
}
1473
1506
1474
1507
// check existing test goals
1475
- static coverage_goalst existing_goals;
1508
+ coverage_goalst existing_goals;
1476
1509
if (cmdline.isset (" existing-coverage" ))
1477
1510
{
1511
+ // get the mode to ensure invariants
1512
+ // (e.g., bytecode_index for Java programs)
1513
+ namespacet ns (symbol_table);
1514
+ const irep_idt &mode=ns.lookup (goto_functions.entry_point ()).mode ;
1515
+
1478
1516
msg.status () << " Add existing coverage goals" << messaget::eom;
1479
1517
// get file with covered test goals
1480
1518
const std::string coverage=cmdline.get_value (" existing-coverage" );
1481
1519
// get a coverage_goalst object
1482
- if (coverage_goalst::get_coverage_goals (coverage, msgh, existing_goals))
1520
+ if (coverage_goalst::get_coverage_goals (
1521
+ coverage, msgh, existing_goals, mode))
1483
1522
{
1484
1523
msg.error () << " get_coverage_goals failed" << messaget::eom;
1485
1524
return true ;
0 commit comments