Skip to content

Commit 5c9eb59

Browse files
Merge pull request #1233 from theyoucheng/fault-localization-xml-ui
Fix the output of the fault localization result in XML
2 parents aea00bf + 13cc598 commit 5c9eb59

File tree

2 files changed

+86
-16
lines changed

2 files changed

+86
-16
lines changed

src/cbmc/fault_localization.cpp

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ Author: Peter Schrammel
1717
#include <util/std_expr.h>
1818
#include <util/message.h>
1919
#include <util/time_stopping.h>
20+
#include <util/xml_expr.h>
2021

2122
#include <solvers/prop/minimize.h>
2223
#include <solvers/prop/literal_expr.h>
2324

2425
#include <goto-symex/build_goto_trace.h>
26+
#include <goto-programs/xml_goto_trace.h>
2527

2628
#include "counterexample_beautification.h"
2729

@@ -144,7 +146,7 @@ void fault_localizationt::run(irep_idt goal_id)
144146

145147
if(goal_id==ID_nil)
146148
goal_id=failed->source.pc->source_location.get_property_id();
147-
lpointst &lpoints = lpoints_map[goal_id];
149+
lpointst &lpoints=lpoints_map[goal_id];
148150

149151
// collect lpoints
150152
collect_guards(lpoints);
@@ -168,7 +170,7 @@ void fault_localizationt::report(irep_idt goal_id)
168170
if(goal_id==ID_nil)
169171
goal_id=failed->source.pc->source_location.get_property_id();
170172

171-
lpointst &lpoints = lpoints_map[goal_id];
173+
lpointst &lpoints=lpoints_map[goal_id];
172174

173175
if(lpoints.empty())
174176
{
@@ -192,6 +194,41 @@ void fault_localizationt::report(irep_idt goal_id)
192194
<< eom;
193195
}
194196

197+
xmlt fault_localizationt::report_xml(irep_idt goal_id)
198+
{
199+
xmlt xml_diagnosis("diagnosis");
200+
xml_diagnosis.new_element("method").data="linear fault localization";
201+
202+
if(goal_id==ID_nil)
203+
goal_id=failed->source.pc->source_location.get_property_id();
204+
205+
xml_diagnosis.set_attribute("property", id2string(goal_id));
206+
207+
const lpointst &lpoints=lpoints_map[goal_id];
208+
209+
if(lpoints.empty())
210+
{
211+
xml_diagnosis.new_element("result").data="unable to localize fault";
212+
return xml_diagnosis;
213+
}
214+
215+
debug() << "Fault localization scores:" << eom;
216+
const lpointt *max=&lpoints.begin()->second;
217+
for(const auto &pair : lpoints)
218+
{
219+
const auto &value=pair.second;
220+
debug() << value.target->source_location
221+
<< "\n score: " << value.score << eom;
222+
if(max->score<value.score)
223+
max=&value;
224+
}
225+
226+
xmlt xml_location=xml(max->target->source_location);
227+
xml_diagnosis.new_element("result").new_element().swap(xml_location);
228+
229+
return xml_diagnosis;
230+
}
231+
195232
safety_checkert::resultt fault_localizationt::operator()()
196233
{
197234
if(options.get_bool_option("stop-on-fail"))
@@ -250,8 +287,27 @@ safety_checkert::resultt fault_localizationt::stop_on_fail()
250287

251288
// localize faults
252289
run(ID_nil);
253-
status() << "\n** Most likely fault location:" << eom;
254-
report(ID_nil);
290+
291+
switch(bmc.ui)
292+
{
293+
case ui_message_handlert::uit::PLAIN:
294+
{
295+
status() << "\n** Most likely fault location:" << eom;
296+
report(ID_nil);
297+
break;
298+
}
299+
case ui_message_handlert::uit::XML_UI:
300+
{
301+
xmlt dest("fault-localization");
302+
xmlt xml_diagnosis=report_xml(ID_nil);
303+
dest.new_element().swap(xml_diagnosis);
304+
status() << preformatted_output << dest << eom;
305+
break;
306+
}
307+
case ui_message_handlert::uit::JSON_UI:
308+
// not implemented
309+
break;
310+
}
255311

256312
bmc.report_failure();
257313
return safety_checkert::resultt::UNSAFE;
@@ -266,27 +322,27 @@ safety_checkert::resultt fault_localizationt::stop_on_fail()
266322
void fault_localizationt::goal_covered(
267323
const cover_goalst::goalt &)
268324
{
269-
for(auto &g : goal_map)
325+
for(auto &goal_pair : goal_map)
270326
{
271327
// failed already?
272-
if(g.second.status==goalt::statust::FAILURE)
328+
if(goal_pair.second.status==goalt::statust::FAILURE)
273329
continue;
274330

275331
// check whether failed
276-
for(auto &c : g.second.instances)
332+
for(auto &inst : goal_pair.second.instances)
277333
{
278-
literalt cond=c->cond_literal;
334+
literalt cond=inst->cond_literal;
279335

280336
if(solver.l_get(cond).is_false())
281337
{
282-
g.second.status=goalt::statust::FAILURE;
283-
symex_target_equationt::SSA_stepst::iterator next=c;
338+
goal_pair.second.status=goalt::statust::FAILURE;
339+
symex_target_equationt::SSA_stepst::iterator next=inst;
284340
next++; // include the assertion
285-
build_goto_trace(bmc.equation, next, solver, bmc.ns,
286-
g.second.goto_trace);
341+
build_goto_trace(
342+
bmc.equation, next, solver, bmc.ns, goal_pair.second.goto_trace);
287343

288344
// localize faults
289-
run(g.first);
345+
run(goal_pair.first);
290346

291347
break;
292348
}
@@ -305,17 +361,29 @@ void fault_localizationt::report(
305361
if(cover_goals.number_covered()>0)
306362
{
307363
status() << "\n** Most likely fault location:" << eom;
308-
for(auto &g : goal_map)
364+
for(auto &goal_pair : goal_map)
309365
{
310-
if(g.second.status!=goalt::statust::FAILURE)
366+
if(goal_pair.second.status!=goalt::statust::FAILURE)
311367
continue;
312-
report(g.first);
368+
report(goal_pair.first);
313369
}
314370
}
315371
break;
316372
case ui_message_handlert::uit::XML_UI:
373+
{
374+
xmlt dest("fault-localization");
375+
for(auto &goal_pair : goal_map)
376+
{
377+
if(goal_pair.second.status!=goalt::statust::FAILURE)
378+
continue;
379+
xmlt xml_diagnosis=report_xml(goal_pair.first);
380+
dest.new_element().swap(xml_diagnosis);
381+
}
382+
status() << preformatted_output << dest << eom;
383+
}
317384
break;
318385
case ui_message_handlert::uit::JSON_UI:
386+
// not implemented
319387
break;
320388
}
321389
}

src/cbmc/fault_localization.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class fault_localizationt:
9090

9191
void report(irep_idt goal_id);
9292

93+
xmlt report_xml(irep_idt goal_id);
94+
9395
// override bmc_all_propertiest
9496
virtual void report(const cover_goalst &cover_goals);
9597

0 commit comments

Comments
 (0)