CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cover_goals_report_util.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Cover Goals Reporting Utilities
4
5Author: Daniel Kroening, Peter Schrammel
6
7\*******************************************************************/
8
11
13
14#include <iomanip>
15
16#include <util/json.h>
17#include <util/json_irep.h>
18#include <util/json_stream.h>
19#include <util/ui_message.h>
20#include <util/xml.h>
21#include <util/xml_irep.h>
22
24 const propertiest &properties,
25 unsigned iterations,
27{
28 const std::size_t goals_covered =
30 log.status() << "** " << goals_covered << " of " << properties.size()
31 << " covered (" << std::fixed << std::setw(1)
32 << std::setprecision(1)
33 << (properties.empty()
34 ? 100.0
35 : 100.0 * goals_covered / properties.size())
36 << "%)" << messaget::eom;
37 log.statistics() << "** Used " << iterations << " iteration"
38 << (iterations == 1 ? "" : "s") << messaget::eom;
39}
40
41static void output_goals_plain(const propertiest &properties, messaget &log)
42{
43 log.result() << "\n** coverage results:" << messaget::eom;
44
45 for(const auto &property_pair : properties)
46 {
47 log.result() << "[" << property_pair.first << "]";
48
49 if(property_pair.second.pc->source_location().is_not_nil())
50 log.result() << ' ' << property_pair.second.pc->source_location();
51
52 if(!property_pair.second.description.empty())
53 log.result() << ' ' << property_pair.second.description;
54
55 log.result() << ": "
56 << (property_pair.second.status == property_statust::FAIL
57 ? "SATISFIED"
58 : "FAILED")
59 << '\n';
60 }
61
62 log.result() << messaget::eom;
63}
64
65static void output_goals_xml(const propertiest &properties, messaget &log)
66{
67 for(const auto &property_pair : properties)
68 {
70 "goal",
71 {{"id", id2string(property_pair.first)},
72 {"description", property_pair.second.description},
73 {"status",
74 property_pair.second.status == property_statust::FAIL ? "SATISFIED"
75 : "FAILED"}},
76 {});
77
78 const auto &source_location = property_pair.second.pc->source_location();
79 if(source_location.is_not_nil())
80 {
81 xml_result.new_element() = xml(source_location);
82
84 source_location.get_basic_block_source_lines();
85 if(basic_block_lines.is_not_nil())
86 {
87 xmlt basic_block_lines_xml{"basic_block_lines"};
88 for(const auto &file_entry : basic_block_lines.get_named_sub())
89 {
90 for(const auto &lines_entry : file_entry.second.get_named_sub())
91 {
92 xmlt line{"line"};
93 line.set_attribute("file", id2string(file_entry.first));
94 line.set_attribute("function", id2string(lines_entry.first));
95 line.data = id2string(lines_entry.second.id());
96 basic_block_lines_xml.new_element(line);
97 }
98 }
100 }
101 }
102
103 log.result() << xml_result;
104 }
105}
106
108 const propertiest &properties,
109 messaget &log,
110 ui_message_handlert &ui_message_handler)
111{
112 if(log.status().tellp() > 0)
113 log.status() << messaget::eom; // force end of previous message
115 ui_message_handler.get_json_stream().push_back_stream_object();
116 json_stream_arrayt &goals_array = json_result.push_back_stream_array("goals");
117 for(const auto &property_pair : properties)
118 {
120
122 json_goal["status"] = json_stringt(
123 property_info.status == property_statust::FAIL ? "satisfied" : "failed");
124 json_goal["goal"] = json_stringt(property_pair.first);
125 json_goal["description"] = json_stringt(property_info.description);
126
127 const auto &source_location = property_info.pc->source_location();
128 if(source_location.is_not_nil())
129 {
130 json_goal["sourceLocation"] = json(source_location);
131
132 const irept &basic_block_lines =
133 source_location.get_basic_block_source_lines();
134 if(basic_block_lines.is_not_nil())
135 {
137 for(const auto &file_entry : basic_block_lines.get_named_sub())
138 {
140 for(const auto &lines_entry : file_entry.second.get_named_sub())
141 {
143 json_stringt{lines_entry.second.id()};
144 }
146 }
147 json_goal["basicBlockLines"] = basic_block_lines_json;
148 }
149 }
150
151 goals_array.push_back(std::move(json_goal));
152 }
153 const std::size_t goals_covered =
155 json_result.push_back(
156 "goalsCovered", json_numbert(std::to_string(goals_covered)));
157 json_result.push_back(
158 "totalGoals", json_numbert(std::to_string(properties.size())));
159}
160
162 const propertiest &properties,
163 unsigned iterations,
164 ui_message_handlert &ui_message_handler)
165{
166 messaget log(ui_message_handler);
167 switch(ui_message_handler.get_ui())
168 {
170 {
171 output_goals_plain(properties, log);
172 break;
173 }
175 {
176 output_goals_xml(properties, log);
177 break;
178 }
180 {
181 output_goals_json(properties, log, ui_message_handler);
182 break;
183 }
184 }
185 output_goals_iterations(properties, iterations, log);
186}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition irep.h:364
Provides methods for streaming JSON arrays.
Definition json_stream.h:93
Provides methods for streaming JSON objects.
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:154
static eomt eom
Definition message.h:289
virtual uit get_ui() const
Definition ui_message.h:33
virtual json_stream_arrayt & get_json_stream()
Definition ui_message.h:40
Definition xml.h:21
void set_attribute(const std::string &attribute, unsigned value)
Definition xml.cpp:198
static void output_goals_iterations(const propertiest &properties, unsigned iterations, messaget &log)
static void output_goals_xml(const propertiest &properties, messaget &log)
static void output_goals_json(const propertiest &properties, messaget &log, ui_message_handlert &ui_message_handler)
void output_goals(const propertiest &properties, unsigned iterations, ui_message_handlert &ui_message_handler)
Outputs the properties interpreted as 'coverage goals' and the number of goto verifier iterations tha...
static void output_goals_plain(const propertiest &properties, messaget &log)
Cover Goals Reporting Utilities.
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
double log(double x)
Definition math.c:2449
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
std::size_t count_properties(const propertiest &properties, property_statust status)
Return the number of properties with given status.
xmlt xml(const irep_idt &property_id, const property_infot &property_info)
@ FAIL
The property was violated.
std::map< irep_idt, property_infot > propertiest
A map of property IDs to property infos.
Definition properties.h:76