Skip to content

Utilities for reporting overall result/status/exit code [depends: 3583, blocks: 3585] #3584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cbmc/all_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
#include <chrono>

#include <goto-checker/bmc_util.h>
#include <goto-checker/report_util.h>

#include <util/xml.h>
#include <util/json.h>
Expand Down
1 change: 1 addition & 0 deletions src/cbmc/bmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Author: Daniel Kroening, [email protected]
#include <linking/static_lifetime_init.h>

#include <goto-checker/bmc_util.h>
#include <goto-checker/report_util.h>
#include <goto-checker/solver_factory.h>

#include "counterexample_beautification.h"
Expand Down
1 change: 1 addition & 0 deletions src/cbmc/fault_localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Author: Peter Schrammel
#include <goto-programs/xml_goto_trace.h>

#include <goto-checker/bmc_util.h>
#include <goto-checker/report_util.h>

#include "counterexample_beautification.h"

Expand Down
1 change: 1 addition & 0 deletions src/goto-checker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SRC = bmc_util.cpp \
incremental_goto_checker.cpp \
goto_verifier.cpp \
properties.cpp \
report_util.cpp \
solver_factory.cpp \
symex_coverage.cpp \
symex_bmc.cpp \
Expand Down
55 changes: 0 additions & 55 deletions src/goto-checker/bmc_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,58 +225,3 @@ void slice(
<< " remaining after simplification" << messaget::eom;
}

void report_success(ui_message_handlert &ui_message_handler)
{
messaget msg(ui_message_handler);
msg.result() << "VERIFICATION SUCCESSFUL" << messaget::eom;

switch(ui_message_handler.get_ui())
{
case ui_message_handlert::uit::PLAIN:
break;

case ui_message_handlert::uit::XML_UI:
{
xmlt xml("cprover-status");
xml.data = "SUCCESS";
msg.result() << xml;
}
break;

case ui_message_handlert::uit::JSON_UI:
{
json_objectt json_result;
json_result["cProverStatus"] = json_stringt("success");
msg.result() << json_result;
}
break;
}
}

void report_failure(ui_message_handlert &ui_message_handler)
{
messaget msg(ui_message_handler);
msg.result() << "VERIFICATION FAILED" << messaget::eom;

switch(ui_message_handler.get_ui())
{
case ui_message_handlert::uit::PLAIN:
break;

case ui_message_handlert::uit::XML_UI:
{
xmlt xml("cprover-status");
xml.data = "FAILURE";
msg.result() << xml;
}
break;

case ui_message_handlert::uit::JSON_UI:
{
json_objectt json_result;
json_result["cProverStatus"] = json_stringt("failure");
msg.result() << json_result;
}
break;
}
}
3 changes: 0 additions & 3 deletions src/goto-checker/bmc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ void convert_symex_target_equation(
prop_convt &,
message_handlert &);

void report_failure(ui_message_handlert &);
void report_success(ui_message_handlert &);

void build_error_trace(
goto_tracet &,
const namespacet &,
Expand Down
56 changes: 56 additions & 0 deletions src/goto-checker/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ Author: Daniel Kroening, Peter Schrammel

#include "properties.h"

#include <util/exit_codes.h>
#include <util/invariant.h>
#include <util/json.h>
#include <util/xml.h>

std::string as_string(resultt result)
{
Expand Down Expand Up @@ -88,3 +91,56 @@ propertiest initialize_properties(const abstract_goto_modelt &goto_model)
}
return properties;
}

std::string
as_string(const irep_idt &property_id, const property_infot &property_info)
{
return "[" + id2string(property_id) + "] " + property_info.description +
": " + as_string(property_info.status);
}

xmlt xml(const irep_idt &property_id, const property_infot &property_info)
{
xmlt xml_result("result");
xml_result.set_attribute("property", id2string(property_id));
xml_result.set_attribute("status", as_string(property_info.status));
return xml_result;
}

json_objectt
json(const irep_idt &property_id, const property_infot &property_info)
{
json_objectt result;
result["property"] = json_stringt(property_id);
result["description"] = json_stringt(property_info.description);
result["status"] = json_stringt(as_string(property_info.status));
return result;
}

int result_to_exit_code(resultt result)
{
switch(result)
{
case resultt::PASS:
return CPROVER_EXIT_VERIFICATION_SAFE;
case resultt::FAIL:
return CPROVER_EXIT_VERIFICATION_UNSAFE;
case resultt::ERROR:
return CPROVER_EXIT_INTERNAL_ERROR;
case resultt::UNKNOWN:
return CPROVER_EXIT_VERIFICATION_INCONCLUSIVE;
}
UNREACHABLE;
}

std::size_t
count_properties(const propertiest &properties, property_statust status)
{
std::size_t count = 0;
for(const auto &property_pair : properties)
{
if(property_pair.second.status == status)
++count;
}
return count;
}
16 changes: 16 additions & 0 deletions src/goto-checker/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Author: Daniel Kroening, Peter Schrammel

#include <goto-programs/goto_model.h>

class json_objectt;
class xmlt;

/// The status of a property
enum class property_statust
{
Expand Down Expand Up @@ -73,4 +76,17 @@ typedef std::unordered_map<irep_idt, property_infot> propertiest;
/// Returns the properties in the goto model
propertiest initialize_properties(const abstract_goto_modelt &);

std::string
as_string(const irep_idt &property_id, const property_infot &property_info);

xmlt xml(const irep_idt &property_id, const property_infot &property_info);

json_objectt
json(const irep_idt &property_id, const property_infot &property_info);

int result_to_exit_code(resultt result);

/// Return the number of properties with given \p status
std::size_t count_properties(const propertiest &, property_statust);

#endif // CPROVER_GOTO_CHECKER_PROPERTIES_H
Loading