Skip to content

Commit 37c7842

Browse files
author
Daniel Kroening
authored
Merge pull request #204 from peterschrammel/test-output
Split test output into goals and tests
2 parents 1a1e4ea + 84adc25 commit 37c7842

File tree

3 files changed

+86
-73
lines changed

3 files changed

+86
-73
lines changed

src/cbmc/bmc_cover.cpp

Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class bmc_covert:
117117

118118
// if satisified, we compute a goto_trace
119119
bool satisfied;
120-
goto_tracet goto_trace;
121120

122121
goalt(
123122
const std::string &_description,
@@ -143,6 +142,12 @@ class bmc_covert:
143142
return disjunction(tmp);
144143
}
145144
};
145+
146+
struct testt
147+
{
148+
goto_tracet goto_trace;
149+
std::vector<irep_idt> covered_goals;
150+
};
146151

147152
inline irep_idt id(goto_programt::const_targett loc)
148153
{
@@ -151,8 +156,10 @@ class bmc_covert:
151156

152157
typedef std::map<irep_idt, goalt> goal_mapt;
153158
goal_mapt goal_map;
159+
typedef std::vector<testt> testst;
160+
testst tests;
154161

155-
std::string get_test(const goto_tracet &goto_trace)
162+
std::string get_test(const goto_tracet &goto_trace) const
156163
{
157164
bool first=true;
158165
std::string test;
@@ -196,6 +203,8 @@ Function: bmc_covert::satisfying_assignment
196203

197204
void bmc_covert::satisfying_assignment()
198205
{
206+
tests.push_back(testt());
207+
testt &test = tests.back();
199208
for(auto &g_it : goal_map)
200209
{
201210
goalt &g=g_it.second;
@@ -212,13 +221,13 @@ void bmc_covert::satisfying_assignment()
212221
{
213222
status() << "Covered " << g.description << messaget::eom;
214223
g.satisfied=true;
215-
symex_target_equationt::SSA_stepst::iterator next=c_it.step;
216-
next++; // include the instruction itself
217-
build_goto_trace(bmc.equation, next, solver, bmc.ns, g.goto_trace);
224+
test.covered_goals.push_back(g_it.first);
218225
break;
219226
}
220227
}
221228
}
229+
build_goto_trace(bmc.equation, bmc.equation.SSA_steps.end(),
230+
solver, bmc.ns, test.goto_trace);
222231
}
223232

224233
/*******************************************************************\
@@ -378,88 +387,101 @@ bool bmc_covert::operator()()
378387
{
379388
const goalt &goal=it.second;
380389

381-
xmlt xml_result("result");
382-
xml_result.set_attribute("goal", id2string(it.first));
390+
xmlt xml_result("goal");
391+
xml_result.set_attribute("id", id2string(it.first));
383392
xml_result.set_attribute("description", goal.description);
384393
xml_result.set_attribute("status", goal.satisfied?"SATISFIED":"FAILED");
385394

386395
if(goal.source_location.is_not_nil())
387396
xml_result.new_element()=xml(goal.source_location);
388397

389-
if(goal.satisfied)
398+
std::cout << xml_result << "\n";
399+
}
400+
401+
for(const auto & test : tests)
402+
{
403+
xmlt xml_result("test");
404+
if(bmc.options.get_bool_option("trace"))
390405
{
391-
if(bmc.options.get_bool_option("trace"))
392-
{
393-
convert(bmc.ns, goal.goto_trace, xml_result.new_element());
394-
}
395-
else
396-
{
397-
xmlt &xml_test=xml_result.new_element("test");
406+
convert(bmc.ns, test.goto_trace, xml_result.new_element());
407+
}
408+
else
409+
{
410+
xmlt &xml_test=xml_result.new_element("inputs");
398411

399-
for(const auto & step : goal.goto_trace.steps)
412+
for(const auto & step : test.goto_trace.steps)
413+
{
414+
if(step.is_input())
400415
{
401-
if(step.is_input())
402-
{
403-
xmlt &xml_input=xml_test.new_element("input");
404-
xml_input.set_attribute("id", id2string(step.io_id));
405-
if(step.io_args.size()==1)
406-
xml_input.new_element("value")=
407-
xml(step.io_args.front(), bmc.ns);
408-
}
416+
xmlt &xml_input=xml_test.new_element("input");
417+
xml_input.set_attribute("id", id2string(step.io_id));
418+
if(step.io_args.size()==1)
419+
xml_input.new_element("value")=
420+
xml(step.io_args.front(), bmc.ns);
409421
}
410-
411422
}
412423
}
413424

425+
for(const auto & goal_id : test.covered_goals)
426+
{
427+
xmlt &xml_goal=xml_result.new_element("goal");
428+
xml_goal.set_attribute("id", id2string(goal_id));
429+
}
430+
414431
std::cout << xml_result << "\n";
415432
}
416-
417433
break;
418434
}
419435
case ui_message_handlert::JSON_UI:
420436
{
421437
json_objectt json_result;
422-
json_arrayt &result_array=json_result["results"].make_array();
438+
json_arrayt &goals_array=json_result["goals"].make_array();
423439
for(const auto & it : goal_map)
424440
{
425441
const goalt &goal=it.second;
426442

427-
json_objectt &result=result_array.push_back().make_object();
443+
json_objectt &result=goals_array.push_back().make_object();
428444
result["status"]=json_stringt(goal.satisfied?"satisfied":"failed");
429445
result["goal"]=json_stringt(id2string(it.first));
430446
result["description"]=json_stringt(goal.description);
431447

432448
if(goal.source_location.is_not_nil())
433449
result["sourceLocation"]=json(goal.source_location);
450+
}
451+
json_result["totalGoals"]=json_numbert(i2string(goal_map.size()));
452+
json_result["goalsCovered"]=json_numbert(i2string(goals_covered));
434453

435-
if(goal.satisfied)
454+
json_arrayt &tests_array=json_result["tests"].make_array();
455+
for(const auto & test : tests)
456+
{
457+
json_objectt &result=tests_array.push_back().make_object();
458+
if(bmc.options.get_bool_option("trace"))
436459
{
437-
if(bmc.options.get_bool_option("trace"))
438-
{
439-
jsont &json_trace=result["trace"];
440-
convert(bmc.ns, goal.goto_trace, json_trace);
441-
}
442-
else
443-
{
444-
json_arrayt &json_test=result["test"].make_array();
460+
jsont &json_trace=result["trace"];
461+
convert(bmc.ns, test.goto_trace, json_trace);
462+
}
463+
else
464+
{
465+
json_arrayt &json_test=result["inputs"].make_array();
445466

446-
for(const auto & step : goal.goto_trace.steps)
467+
for(const auto & step : test.goto_trace.steps)
468+
{
469+
if(step.is_input())
447470
{
448-
if(step.is_input())
449-
{
450-
json_objectt json_input;
451-
json_input["id"]=json_stringt(id2string(step.io_id));
452-
if(step.io_args.size()==1)
453-
json_input["value"]=json(step.io_args.front(), bmc.ns);
454-
json_test.push_back(json_input);
455-
}
471+
json_objectt json_input;
472+
json_input["id"]=json_stringt(id2string(step.io_id));
473+
if(step.io_args.size()==1)
474+
json_input["value"]=json(step.io_args.front(), bmc.ns);
475+
json_test.push_back(json_input);
456476
}
457-
458477
}
459478
}
479+
json_arrayt &goal_refs=result["coveredGoals"].make_array();
480+
for(const auto & goal_id : test.covered_goals)
481+
{
482+
goal_refs.push_back(json_stringt(id2string(goal_id)));
483+
}
460484
}
461-
json_result["totalGoals"]=json_numbert(i2string(goal_map.size()));
462-
json_result["goalsCovered"]=json_numbert(i2string(goals_covered));
463485
std::cout << ",\n" << json_result;
464486
break;
465487
}
@@ -478,16 +500,10 @@ bool bmc_covert::operator()()
478500

479501
if(bmc.ui==ui_message_handlert::PLAIN)
480502
{
481-
std::set<std::string> tests;
482-
483-
for(const auto & it : goal_map)
484-
if(it.second.satisfied)
485-
tests.insert(get_test(it.second.goto_trace));
486-
487503
std::cout << "Test suite:" << '\n';
488504

489-
for(const auto & t : tests)
490-
std::cout << t << '\n';
505+
for(const auto & test : tests)
506+
std::cout << get_test(test.goto_trace) << '\n';
491507
}
492508

493509
return false;

src/goto-programs/json_goto_trace.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,19 @@ void convert(
8989
if(!json_location.is_null())
9090
json_assignment["sourceLocation"]=json_location;
9191

92-
std::string value_string, binary_string, type_string,
93-
full_lhs_string, full_lhs_value_string;
94-
95-
//if(it.lhs_object_value.is_not_nil())
96-
// value_string=from_expr(ns, identifier, it.lhs_object_value);
92+
std::string value_string, binary_string, type_string, full_lhs_string;
93+
json_objectt full_lhs_value;
9794

9895
if(it.full_lhs.is_not_nil())
9996
full_lhs_string=from_expr(ns, identifier, it.full_lhs);
10097

98+
#if 0
10199
if(it.full_lhs_value.is_not_nil())
102100
full_lhs_value_string=from_expr(ns, identifier, it.full_lhs_value);
101+
#endif
103102

104-
//if(it.lhs_object_value.type().is_not_nil())
105-
// type_string=from_type(ns, identifier, it.lhs_object_value.type());
103+
if(it.full_lhs_value.is_not_nil())
104+
full_lhs_value = json(it.full_lhs_value, ns);
106105

107106
const symbolt *symbol;
108107
irep_idt base_name, display_name;
@@ -117,7 +116,7 @@ void convert(
117116
json_assignment["mode"]=json_stringt(id2string(symbol->mode));
118117
}
119118

120-
json_assignment["value"]=json_stringt(full_lhs_value_string);
119+
json_assignment["value"]=full_lhs_value;
121120
json_assignment["lhs"]=json_stringt(full_lhs_string);
122121
json_assignment["hidden"]=jsont::json_boolean(it.hidden);
123122
json_assignment["thread"]=json_numbert(i2string(it.thread_nr));
@@ -144,8 +143,7 @@ void convert(
144143
if(l_it.is_nil())
145144
json_values.push_back(json_stringt(""));
146145
else
147-
json_values.push_back(
148-
json_stringt(from_expr(ns, "", l_it)));
146+
json_values.push_back(json(l_it, ns));
149147
}
150148

151149
if(!json_location.is_null())
@@ -169,8 +167,7 @@ void convert(
169167
if(l_it.is_nil())
170168
json_values.push_back(json_stringt(""));
171169
else
172-
json_values.push_back(
173-
json_stringt(from_expr(ns, "", l_it)));
170+
json_values.push_back(json(l_it, ns));
174171
}
175172

176173
if(!json_location.is_null())

src/util/json_expr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ json_objectt json(
130130
else if(type.id()==ID_struct)
131131
{
132132
result["name"]=json_stringt("struct");
133-
json_arrayt members=result["members"].make_array();
133+
json_arrayt &members=result["members"].make_array();
134134
const union_typet::componentst &components=
135135
to_union_type(type).components();
136136
for(const auto & it : components)
@@ -143,7 +143,7 @@ json_objectt json(
143143
else if(type.id()==ID_union)
144144
{
145145
result["name"]=json_stringt("union");
146-
json_arrayt members=result["members"].make_array();
146+
json_arrayt &members=result["members"].make_array();
147147
const union_typet::componentst &components=
148148
to_union_type(type).components();
149149
for(const auto & it : components)
@@ -274,7 +274,7 @@ json_objectt json(
274274
else if(expr.id()==ID_array)
275275
{
276276
result["name"]=json_stringt("array");
277-
json_arrayt elements=result["elements"].make_array();
277+
json_arrayt &elements=result["elements"].make_array();
278278

279279
unsigned index=0;
280280

@@ -297,7 +297,7 @@ json_objectt json(
297297
const struct_typet::componentst &components=struct_type.components();
298298
assert(components.size()==expr.operands().size());
299299

300-
json_arrayt members=result["members"].make_array();
300+
json_arrayt &members=result["members"].make_array();
301301
for(unsigned m=0; m<expr.operands().size(); m++)
302302
{
303303
json_objectt &e=members.push_back().make_object();

0 commit comments

Comments
 (0)