Skip to content

Commit bca694a

Browse files
authored
Replace CBMC output parser (rust-lang#1433)
1 parent cecd55f commit bca694a

File tree

16 files changed

+1085
-1044
lines changed

16 files changed

+1085
-1044
lines changed

Cargo.lock

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ dependencies = [
156156
"walkdir",
157157
]
158158

159+
[[package]]
160+
name = "console"
161+
version = "0.15.1"
162+
source = "registry+https://github.com/rust-lang/crates.io-index"
163+
checksum = "89eab4d20ce20cea182308bca13088fecea9c05f6776cf287205d41a0ed3c847"
164+
dependencies = [
165+
"encode_unicode",
166+
"libc",
167+
"once_cell",
168+
"terminal_size",
169+
"unicode-width",
170+
"winapi",
171+
]
172+
159173
[[package]]
160174
name = "cprover_bindings"
161175
version = "0.7.0"
@@ -185,6 +199,12 @@ version = "1.7.0"
185199
source = "registry+https://github.com/rust-lang/crates.io-index"
186200
checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be"
187201

202+
[[package]]
203+
name = "encode_unicode"
204+
version = "0.3.6"
205+
source = "registry+https://github.com/rust-lang/crates.io-index"
206+
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
207+
188208
[[package]]
189209
name = "getopts"
190210
version = "0.2.21"
@@ -318,8 +338,12 @@ dependencies = [
318338
"anyhow",
319339
"cargo_metadata",
320340
"clap",
341+
"console",
321342
"glob",
322343
"kani_metadata",
344+
"once_cell",
345+
"pathdiff",
346+
"regex",
323347
"serde",
324348
"serde_json",
325349
"structopt",
@@ -549,6 +573,12 @@ dependencies = [
549573
"windows-sys",
550574
]
551575

576+
[[package]]
577+
name = "pathdiff"
578+
version = "0.2.1"
579+
source = "registry+https://github.com/rust-lang/crates.io-index"
580+
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
581+
552582
[[package]]
553583
name = "pin-project-lite"
554584
version = "0.2.9"
@@ -831,6 +861,16 @@ dependencies = [
831861
"unicode-ident",
832862
]
833863

864+
[[package]]
865+
name = "terminal_size"
866+
version = "0.1.17"
867+
source = "registry+https://github.com/rust-lang/crates.io-index"
868+
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
869+
dependencies = [
870+
"libc",
871+
"winapi",
872+
]
873+
834874
[[package]]
835875
name = "textwrap"
836876
version = "0.11.0"

kani-driver/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ publish = false
1515
kani_metadata = { path = "../kani_metadata" }
1616
cargo_metadata = "0.15.0"
1717
anyhow = "1"
18+
console = "0.15.1"
19+
once_cell = "1.13.0"
1820
serde = { version = "1", features = ["derive"] }
1921
serde_json = "1"
2022
structopt = "0.3"
2123
clap = "2.34"
2224
glob = "0.3"
2325
toml = "0.5"
26+
regex = "1.6"
27+
pathdiff = "0.2.1"
2428

2529
# A good set of suggested dependencies can be found in rustup:
2630
# https://github.com/rust-lang/rustup/blob/master/Cargo.toml

kani-driver/src/call_cbmc.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::process::Command;
99
use std::time::Instant;
1010

1111
use crate::args::KaniArgs;
12+
use crate::cbmc_output_parser::process_cbmc_output;
1213
use crate::session::KaniSession;
1314

1415
#[derive(PartialEq, Eq)]
@@ -24,7 +25,7 @@ impl KaniSession {
2425

2526
{
2627
let mut temps = self.temporaries.borrow_mut();
27-
temps.push(output_filename.clone());
28+
temps.push(output_filename);
2829
}
2930

3031
let args: Vec<OsString> = self.cbmc_flags(file, harness)?;
@@ -33,32 +34,41 @@ impl KaniSession {
3334
let mut cmd = Command::new("cbmc");
3435
cmd.args(args);
3536

36-
if self.args.output_format == crate::args::OutputFormat::Old {
37+
let now = Instant::now();
38+
39+
let verification_result = if self.args.output_format == crate::args::OutputFormat::Old {
3740
if self.run_terminal(cmd).is_err() {
38-
return Ok(VerificationStatus::Failure);
41+
Ok(VerificationStatus::Failure)
42+
} else {
43+
Ok(VerificationStatus::Success)
3944
}
4045
} else {
41-
// extra argument
46+
// Add extra argument to receive the output in JSON format.
47+
// Done here because `--visualize` uses the XML format instead.
4248
cmd.arg("--json-ui");
4349

44-
let now = Instant::now();
45-
let _cbmc_result = self.run_redirect(cmd, &output_filename)?;
46-
let elapsed = now.elapsed().as_secs_f32();
47-
let format_result = self.format_cbmc_output(&output_filename);
48-
49-
if format_result.is_err() {
50-
// Because of things like --assertion-reach-checks and other future features,
51-
// we now decide if we fail or not based solely on the output of the formatter.
52-
return Ok(VerificationStatus::Failure);
53-
// todo: this is imperfect, since we don't know why failure happened.
54-
// the best possible fix is port to rust instead of using python, or getting more
55-
// feedback than just exit status (or using a particular magic exit code?)
50+
// Spawn the CBMC process and process its output below
51+
let cbmc_process_opt = self.run_piped(cmd)?;
52+
if let Some(cbmc_process) = cbmc_process_opt {
53+
// The introduction of reachability checks forces us to decide
54+
// the verification result based on the postprocessing of CBMC results.
55+
let processed_result = process_cbmc_output(
56+
cbmc_process,
57+
self.args.extra_pointer_checks,
58+
&self.args.output_format,
59+
);
60+
Ok(processed_result)
61+
} else {
62+
Ok(VerificationStatus::Failure)
5663
}
57-
// TODO: We should print this even the verification fails but not if it crashes.
64+
};
65+
// TODO: We should print this even the verification fails but not if it crashes.
66+
if !self.args.dry_run {
67+
let elapsed = now.elapsed().as_secs_f32();
5868
println!("Verification Time: {}s", elapsed);
5969
}
6070

61-
Ok(VerificationStatus::Success)
71+
verification_result
6272
}
6373

6474
/// used by call_cbmc_viewer, invokes different variants of CBMC.

kani-driver/src/call_display_results.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)