Skip to content

Commit 7943da0

Browse files
Add report_util for outputting verification results
Prints the property report in plain text, JSON or XML.
1 parent c00fd37 commit 7943da0

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

src/goto-checker/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SRC = bmc_util.cpp \
22
goto_checker.cpp \
33
goto_verifier.cpp \
44
properties.cpp \
5+
report_util.cpp \
56
solver_factory.cpp \
67
symex_coverage.cpp \
78
symex_bmc.cpp \

src/goto-checker/report_util.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*******************************************************************\
2+
3+
Module: Bounded Model Checking Utilities
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Bounded Model Checking Utilities
11+
12+
#include "report_util.h"
13+
14+
void output_properties(
15+
const propertiest &properties,
16+
ui_message_handlert &ui_message_handler)
17+
{
18+
messaget log(ui_message_handler);
19+
switch(ui_message_handler.get_ui())
20+
{
21+
case ui_message_handlert::uit::PLAIN:
22+
{
23+
log.result() << "\n** Results:" << messaget::eom;
24+
// collect properties in a vector
25+
std::vector<propertiest::const_iterator> sorted_properties;
26+
for(auto p_it = properties.begin(); p_it != properties.end(); p_it++)
27+
sorted_properties.push_back(p_it);
28+
// now determine an ordering for those goals:
29+
// 1. alphabetical ordering of file name
30+
// 2. numerical ordering of line number
31+
// 3. alphabetical ordering of goal ID
32+
std::sort(
33+
sorted_properties.begin(),
34+
sorted_properties.end(),
35+
[](propertiest::const_iterator pit1, propertiest::const_iterator pit2) {
36+
const auto &p1 = pit1->second.location->source_location;
37+
const auto &p2 = pit2->second.location->source_location;
38+
if(p1.get_file() != p2.get_file())
39+
return id2string(p1.get_file()) < id2string(p2.get_file());
40+
else if(!p1.get_line().empty() && !p2.get_line().empty())
41+
return std::stoul(id2string(p1.get_line())) <
42+
std::stoul(id2string(p2.get_line()));
43+
else
44+
return id2string(pit1->first) < id2string(pit2->first);
45+
});
46+
// now show in the order we have determined
47+
irep_idt previous_function;
48+
irep_idt current_file;
49+
for(const auto &p : sorted_properties)
50+
{
51+
const auto &l = p->second.location->source_location;
52+
if(l.get_function() != previous_function)
53+
{
54+
if(!previous_function.empty())
55+
log.result() << '\n';
56+
previous_function = l.get_function();
57+
if(!previous_function.empty())
58+
{
59+
current_file = l.get_file();
60+
if(!current_file.empty())
61+
log.result() << current_file << ' ';
62+
if(!l.get_function().empty())
63+
log.result() << "function " << l.get_function();
64+
log.result() << messaget::eom;
65+
}
66+
}
67+
log.result() << messaget::faint << '[' << p->first << "] "
68+
<< messaget::reset;
69+
if(l.get_file() != current_file)
70+
log.result() << "file " << l.get_file() << ' ';
71+
if(!l.get_line().empty())
72+
log.result() << "line " << l.get_line() << ' ';
73+
log.result() << p->second.description << ": ";
74+
switch(p->second.result)
75+
{
76+
case property_resultt::NOT_REACHED:
77+
log.result() << messaget::magenta;
78+
break;
79+
case property_resultt::UNKNOWN:
80+
log.result() << messaget::bright_magenta;
81+
break;
82+
case property_resultt::NOT_REACHABLE:
83+
log.result() << messaget::bright_green;
84+
break;
85+
case property_resultt::PASS:
86+
log.result() << messaget::green;
87+
break;
88+
case property_resultt::FAIL:
89+
log.result() << messaget::red;
90+
break;
91+
case property_resultt::ERROR:
92+
log.result() << messaget::bright_red;
93+
break;
94+
}
95+
log.result() << as_string(p->second.result) << messaget::reset
96+
<< messaget::eom;
97+
}
98+
log.status() << "\n** "
99+
<< count_properties(properties, property_resultt::FAIL)
100+
<< " of " << properties.size() << " failed" << messaget::eom;
101+
break;
102+
}
103+
case ui_message_handlert::uit::XML_UI:
104+
{
105+
for(const auto &property_pair : properties)
106+
{
107+
log.result() << xml(property_pair.first, property_pair.second);
108+
}
109+
break;
110+
}
111+
case ui_message_handlert::uit::JSON_UI:
112+
{
113+
json_stream_objectt &json_result =
114+
ui_message_handler.get_json_stream().push_back_stream_object();
115+
json_stream_arrayt &result_array =
116+
json_result.push_back_stream_array("result");
117+
for(const auto &property_pair : properties)
118+
{
119+
result_array.push_back(json(property_pair.first, property_pair.second));
120+
}
121+
break;
122+
}
123+
}
124+
}

src/goto-checker/report_util.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*******************************************************************\
2+
3+
Module: Bounded Model Checking Utilities
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Bounded Model Checking Utilities
11+
12+
#ifndef CPROVER_GOTO_CHECKER_REPORT_UTIL_H
13+
#define CPROVER_GOTO_CHECKER_REPORT_UTIL_H
14+
15+
#include "properties.h"
16+
17+
class ui_message_handlert;
18+
19+
void output_properties(
20+
const propertiest &properties,
21+
ui_message_handlert &ui_message_handler);
22+
23+
#endif // CPROVER_GOTO_CHECKER_REPORT_UTIL_H

0 commit comments

Comments
 (0)