Skip to content

Commit 693e40b

Browse files
committed
Export goto-lib instrument passes to Rust API and use them in test
1 parent 9810f5b commit 693e40b

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/libcprover-cpp/api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void api_sessiont::verify_model() const
166166
verifier.report();
167167
}
168168

169-
void api_sessiont::drop_unused_functions()
169+
void api_sessiont::drop_unused_functions() const
170170
{
171171
INVARIANT(
172172
implementation->model != nullptr,
@@ -181,7 +181,7 @@ void api_sessiont::drop_unused_functions()
181181
*implementation->model, *implementation->message_handler);
182182
}
183183

184-
void api_sessiont::validate_goto_model()
184+
void api_sessiont::validate_goto_model() const
185185
{
186186
INVARIANT(
187187
implementation->model != nullptr,

src/libcprover-cpp/api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ struct api_sessiont
7272
void verify_model() const;
7373

7474
/// Drop unused functions from the loaded goto_model simplifying it
75-
void drop_unused_functions();
75+
void drop_unused_functions() const;
7676

7777
/// Validate the loaded goto model
78-
void validate_goto_model();
78+
void validate_goto_model() const;
7979

8080
// A simple API version information function.
8181
std::unique_ptr<std::string> get_api_version() const;

src/libcprover-rust/src/lib.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub mod ffi {
1313
fn get_api_version(&self) -> UniquePtr<CxxString>;
1414
fn load_model_from_files(&self, files: &CxxVector<CxxString>);
1515
fn verify_model(&self);
16+
fn validate_goto_model(&self);
17+
fn drop_unused_functions(&self);
1618

1719
// Helper/Utility functions
1820
fn translate_vector_of_string(elements: Vec<String>) -> &'static CxxVector<CxxString>;
@@ -35,7 +37,7 @@ fn print_response(vec: &CxxVector<CxxString>) {
3537
}
3638
}
3739

38-
// To test run "cargo test -- --nocapture"
40+
// To test run "CBMC_LIB_DIR=<path_to_build/libs> cargo test -- --test-threads=1 --nocapture"
3941
#[cfg(test)]
4042
mod tests {
4143
use super::*;
@@ -51,7 +53,7 @@ mod tests {
5153
}
5254

5355
#[test]
54-
fn translate_vector_of_rust_string_to_CPP() {
56+
fn translate_vector_of_rust_string_to_cpp() {
5557
let vec: Vec<String> = vec![
5658
"/tmp/example.c".to_owned(),
5759
"/tmp/example2.c".to_owned()];
@@ -77,6 +79,11 @@ mod tests {
7779
// Invoke load_model_from_files and see if the model
7880
// has been loaded.
7981
client.load_model_from_files(vect);
82+
// Validate integrity of passed goto-model.
83+
client.validate_goto_model();
84+
85+
let msgs = ffi::get_messages();
86+
print_response(msgs);
8087
}
8188

8289
#[test]
@@ -89,9 +96,34 @@ mod tests {
8996
let vect = ffi::translate_vector_of_string(vec);
9097
client.load_model_from_files(vect);
9198

99+
// Validate integrity of goto-model
100+
client.validate_goto_model();
101+
92102
client.verify_model();
93103

94104
let msgs = ffi::get_messages();
95105
print_response(msgs);
96106
}
107+
108+
#[test]
109+
fn it_can_drop_unused_functions_from_model() {
110+
let binding = ffi::new_api_session();
111+
let client = match binding.as_ref() {
112+
Some(api_ref) => api_ref,
113+
None => panic!("Failed to acquire API session handle"),
114+
};
115+
116+
let vec: Vec<String> = vec![
117+
"/tmp/example.c".to_owned()];
118+
119+
let vect = ffi::translate_vector_of_string(vec);
120+
assert_eq!(vect.len(), 1);
121+
122+
client.load_model_from_files(vect);
123+
// Perform a drop of any unused functions.
124+
client.drop_unused_functions();
125+
126+
let msgs = ffi::get_messages();
127+
print_response(msgs);
128+
}
97129
}

0 commit comments

Comments
 (0)