Skip to content

Commit 3274d1b

Browse files
marek-trtiktautschnig
authored andcommitted
graphml: Special (hacky) structure of concurrency witness.
1 parent 050627f commit 3274d1b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/goto-programs/graphml_witness.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,59 @@ static bool contains_symbol_prefix(const exprt &expr, const std::string &prefix)
244244
/// counterexample witness
245245
void graphml_witnesst::operator()(const goto_tracet &goto_trace)
246246
{
247+
unsigned int max_thread_idx=0U;
248+
bool trace_has_violation=false;
249+
for(goto_tracet::stepst::const_iterator it=goto_trace.steps.begin();
250+
it!=goto_trace.steps.end();
251+
++it)
252+
{
253+
if(it->thread_nr>max_thread_idx)
254+
max_thread_idx=it->thread_nr;
255+
if(it->type==goto_trace_stept::typet::ASSERT && !it->cond_value)
256+
trace_has_violation=true;
257+
}
258+
247259
graphml.key_values["sourcecodelang"]="C";
248260

249261
const graphmlt::node_indext sink=graphml.add_node();
250262
graphml[sink].node_name="sink";
251263
graphml[sink].is_violation=false;
252264
graphml[sink].has_invariant=false;
253265

266+
if(max_thread_idx > 0U && trace_has_violation)
267+
{
268+
std::vector<graphmlt::node_indext> nodes;
269+
270+
for(unsigned int i=0U; i<=max_thread_idx+1U; ++i)
271+
{
272+
nodes.push_back(graphml.add_node());
273+
graphml[nodes.back()].node_name="N" + std::to_string(i);
274+
graphml[nodes.back()].is_violation=(i==max_thread_idx+1U) ? true : false;
275+
graphml[nodes.back()].has_invariant=false;
276+
}
277+
278+
for(auto it=nodes.cbegin(); std::next(it)!=nodes.cend(); ++it)
279+
{
280+
xmlt edge("edge");
281+
edge.set_attribute("source", graphml[*it].node_name);
282+
edge.set_attribute("target", graphml[*std::next(it)].node_name);
283+
const auto thread_id=std::distance(nodes.cbegin(), it);
284+
xmlt &data=edge.new_element("data");
285+
data.set_attribute("key", "createThread");
286+
data.data=std::to_string(thread_id);
287+
if(thread_id==0)
288+
{
289+
xmlt &data=edge.new_element("data");
290+
data.set_attribute("key", "enterFunction");
291+
data.data="main";
292+
}
293+
graphml[*std::next(it)].in[*it].xml_node=edge;
294+
graphml[*it].out[*std::next(it)].xml_node=edge;
295+
}
296+
297+
return;
298+
}
299+
254300
// step numbers start at 1
255301
std::vector<std::size_t> step_to_node(goto_trace.steps.size()+1, 0);
256302

0 commit comments

Comments
 (0)