Skip to content

Commit 0415b70

Browse files
marek-trtiktautschnig
authored andcommitted
graphml: Special (hacky) structure of concurrency witness.
1 parent d7d9eb7 commit 0415b70

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/goto-programs/graphml_witness.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,59 @@ static bool contains_symbol_prefix(const exprt &expr, const std::string &prefix)
229229
/// counterexample witness
230230
void graphml_witnesst::operator()(const goto_tracet &goto_trace)
231231
{
232+
unsigned int max_thread_idx=0U;
233+
bool trace_has_violation=false;
234+
for(goto_tracet::stepst::const_iterator it=goto_trace.steps.begin();
235+
it!=goto_trace.steps.end();
236+
++it)
237+
{
238+
if(it->thread_nr>max_thread_idx)
239+
max_thread_idx=it->thread_nr;
240+
if(it->type==goto_trace_stept::typet::ASSERT && !it->cond_value)
241+
trace_has_violation=true;
242+
}
243+
232244
graphml.key_values["sourcecodelang"]="C";
233245

234246
const graphmlt::node_indext sink=graphml.add_node();
235247
graphml[sink].node_name="sink";
236248
graphml[sink].is_violation=false;
237249
graphml[sink].has_invariant=false;
238250

251+
if(max_thread_idx > 0U && trace_has_violation)
252+
{
253+
std::vector<graphmlt::node_indext> nodes;
254+
255+
for(unsigned int i=0U; i<=max_thread_idx+1U; ++i)
256+
{
257+
nodes.push_back(graphml.add_node());
258+
graphml[nodes.back()].node_name="N" + std::to_string(i);
259+
graphml[nodes.back()].is_violation=(i==max_thread_idx+1U) ? true : false;
260+
graphml[nodes.back()].has_invariant=false;
261+
}
262+
263+
for(auto it=nodes.cbegin(); std::next(it)!=nodes.cend(); ++it)
264+
{
265+
xmlt edge("edge");
266+
edge.set_attribute("source", graphml[*it].node_name);
267+
edge.set_attribute("target", graphml[*std::next(it)].node_name);
268+
const auto thread_id=std::distance(nodes.cbegin(), it);
269+
xmlt &data=edge.new_element("data");
270+
data.set_attribute("key", "createThread");
271+
data.data=std::to_string(thread_id);
272+
if(thread_id==0)
273+
{
274+
xmlt &data=edge.new_element("data");
275+
data.set_attribute("key", "enterFunction");
276+
data.data="main";
277+
}
278+
graphml[*std::next(it)].in[*it].xml_node=edge;
279+
graphml[*it].out[*std::next(it)].xml_node=edge;
280+
}
281+
282+
return;
283+
}
284+
239285
// step numbers start at 1
240286
std::vector<std::size_t> step_to_node(goto_trace.steps.size()+1, 0);
241287

0 commit comments

Comments
 (0)