Skip to content

Commit c159cba

Browse files
Merge pull request #7443 from thomasspriggs/tas/api-verification
Add verification API call
2 parents f872937 + 2e817d1 commit c159cba

File tree

6 files changed

+116
-15
lines changed

6 files changed

+116
-15
lines changed

src/libcprover-cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ file(GLOB_RECURSE sources "*.cpp" "*.h")
33
# This step builds the API in the form of a statically linked library (libcprover-api-cpp.a)
44
add_library(cprover-api-cpp ${sources})
55
generic_includes(cprover-api-cpp)
6-
target_link_libraries(cprover-api-cpp goto-programs util langapi ansi-c)
6+
target_link_libraries(cprover-api-cpp goto-checker goto-programs util langapi ansi-c)

src/libcprover-cpp/api.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@
66
#include <util/config.h>
77
#include <util/message.h>
88
#include <util/options.h>
9+
#include <util/ui_message.h>
910

1011
#include <goto-programs/goto_model.h>
1112
#include <goto-programs/initialize_goto_model.h>
13+
#include <goto-programs/link_to_library.h>
14+
#include <goto-programs/process_goto_program.h>
15+
#include <goto-programs/remove_skip.h>
16+
#include <goto-programs/set_properties.h>
1217

1318
#include <ansi-c/ansi_c_language.h>
19+
#include <ansi-c/cprover_library.h>
20+
#include <assembler/remove_asm.h>
21+
#include <goto-checker/all_properties_verifier_with_trace_storage.h>
22+
#include <goto-checker/multi_path_symex_checker.h>
1423
#include <langapi/mode.h>
24+
#include <pointer-analysis/add_failed_symbols.h>
1525

1626
#include <memory>
1727
#include <string>
@@ -105,3 +115,47 @@ void api_sessiont::load_model_from_files(const std::vector<std::string> &files)
105115
implementation->model = util_make_unique<goto_modelt>(initialize_goto_model(
106116
files, *implementation->message_handler, *implementation->options));
107117
}
118+
119+
void api_sessiont::verify_model()
120+
{
121+
PRECONDITION(implementation->model);
122+
123+
// Remove inline assembler; this needs to happen before adding the library.
124+
remove_asm(*implementation->model);
125+
126+
// add the library
127+
messaget log{*implementation->message_handler};
128+
log.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")"
129+
<< messaget::eom;
130+
link_to_library(
131+
*implementation->model,
132+
*implementation->message_handler,
133+
cprover_c_library_factory);
134+
135+
// Common removal of types and complex constructs
136+
if(::process_goto_program(
137+
*implementation->model, *implementation->options, log))
138+
{
139+
return;
140+
}
141+
142+
// add failed symbols
143+
// needs to be done before pointer analysis
144+
add_failed_symbols(implementation->model->symbol_table);
145+
146+
// label the assertions
147+
// This must be done after adding assertions and
148+
// before using the argument of the "property" option.
149+
// Do not re-label after using the property slicer because
150+
// this would cause the property identifiers to change.
151+
label_properties(*implementation->model);
152+
153+
remove_skip(*implementation->model);
154+
155+
ui_message_handlert ui_message_handler(*implementation->message_handler);
156+
all_properties_verifier_with_trace_storaget<multi_path_symex_checkert>
157+
verifier(
158+
*implementation->options, ui_message_handler, *implementation->model);
159+
(void)verifier();
160+
verifier.report();
161+
}

src/libcprover-cpp/api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ struct api_sessiont
6868
/// \param files: A vector<string> containing the filenames to be loaded
6969
void load_model_from_files(const std::vector<std::string> &files);
7070

71+
/// Verify previously loaded model.
72+
void verify_model();
73+
7174
private:
7275
std::unique_ptr<api_session_implementationt> implementation;
7376
};
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
ansi-c
2-
langapi
2+
assembler
3+
goto-checker
34
goto-programs
5+
langapi
6+
pointer-analysis
47
util

src/libcprover-cpp/options.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
#include "options.h"
44

5+
#include <util/cmdline.h>
56
#include <util/make_unique.h>
67
#include <util/options.h>
78

9+
#include <ansi-c/goto_check_c.h>
10+
#include <goto-checker/solver_factory.h>
11+
812
api_optionst api_optionst::create()
913
{
1014
return api_optionst{};
@@ -16,9 +20,22 @@ api_optionst &api_optionst::simplify(bool on)
1620
return *this;
1721
}
1822

23+
static std::unique_ptr<optionst> make_internal_default_options()
24+
{
25+
std::unique_ptr<optionst> options = util_make_unique<optionst>();
26+
cmdlinet command_line;
27+
PARSE_OPTIONS_GOTO_CHECK(command_line, (*options));
28+
parse_solver_options(command_line, *options);
29+
options->set_option("built-in-assertions", true);
30+
options->set_option("arrays-uf", "auto");
31+
options->set_option("depth", UINT32_MAX);
32+
options->set_option("sat-preprocessor", true);
33+
return options;
34+
}
35+
1936
std::unique_ptr<optionst> api_optionst::to_engine_options() const
2037
{
21-
optionst engine_options;
22-
engine_options.set_option("simplify", simplify_enabled);
23-
return util_make_unique<optionst>(engine_options);
38+
auto engine_options = make_internal_default_options();
39+
engine_options->set_option("simplify", simplify_enabled);
40+
return engine_options;
2441
}

unit/libcprover-cpp/api.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ std::string contains_in_ordert::describe() const
6262
return description.str();
6363
}
6464

65-
TEST_CASE("Test loading model from file.", "[core][libcprover-cpp]")
65+
TEST_CASE(
66+
"Test loading and verifying model from file.",
67+
"[core][libcprover-cpp]")
6668
{
6769
api_sessiont api(api_optionst::create());
6870

@@ -76,13 +78,35 @@ TEST_CASE("Test loading model from file.", "[core][libcprover-cpp]")
7678
output.emplace_back(api_message_get_string(message));
7779
};
7880

79-
api.set_message_callback(write_output, &output);
80-
api.load_model_from_files({"test.c"});
81-
CHECK_THAT(
82-
output,
83-
(contains_in_ordert{
84-
"Parsing test.c",
85-
"Converting",
86-
"Type-checking test",
87-
"Generating GOTO Program"}));
81+
SECTION("Load from file")
82+
{
83+
api.set_message_callback(write_output, &output);
84+
api.load_model_from_files({"test.c"});
85+
CHECK_THAT(
86+
output,
87+
(contains_in_ordert{
88+
"Parsing test.c",
89+
"Converting",
90+
"Type-checking test",
91+
"Generating GOTO Program"}));
92+
output.clear();
93+
SECTION("Verify")
94+
{
95+
api.verify_model();
96+
CHECK_THAT(
97+
output,
98+
(contains_in_ordert{
99+
"Removal of function pointers and virtual functions",
100+
"Generic Property Instrumentation",
101+
"Starting Bounded Model Checking",
102+
"Generated 1 VCC(s), 1 remaining after simplification",
103+
"Passing problem to propositional reduction",
104+
"converting SSA",
105+
"Running propositional reduction",
106+
"Post-processing",
107+
"SAT checker: instance is SATISFIABLE",
108+
"[main.assertion.1] line 8 assertion a[4] != 4: FAILURE",
109+
"VERIFICATION FAILED"}));
110+
}
111+
}
88112
}

0 commit comments

Comments
 (0)