Skip to content

Commit adebe36

Browse files
authored
Report CBMC verification time (rust-lang#1247)
1 parent dcb2992 commit adebe36

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

kani-driver/src/call_cbmc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use kani_metadata::HarnessMetadata;
66
use std::ffi::OsString;
77
use std::path::Path;
88
use std::process::Command;
9+
use std::time::Instant;
910

1011
use crate::args::KaniArgs;
1112
use crate::session::KaniSession;
@@ -40,7 +41,9 @@ impl KaniSession {
4041
// extra argument
4142
cmd.arg("--json-ui");
4243

44+
let now = Instant::now();
4345
let _cbmc_result = self.run_redirect(cmd, &output_filename)?;
46+
let elapsed = now.elapsed().as_secs_f32();
4447
let format_result = self.format_cbmc_output(&output_filename);
4548

4649
if format_result.is_err() {
@@ -51,6 +54,7 @@ impl KaniSession {
5154
// the best possible fix is port to rust instead of using python, or getting more
5255
// feedback than just exit status (or using a particular magic exit code?)
5356
}
57+
println!("Verification Time: {}s", elapsed);
5458
}
5559

5660
Ok(VerificationStatus::Success)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Verification Time:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// This test is meant for checking that the "Verification time:" line (which
5+
// reports the time spent in CBMC) is printed in the output
6+
7+
fn is_sorted(s: &[i32]) -> bool {
8+
for i in 0..s.len() - 1 {
9+
if !(s[i] <= s[i + 1]) {
10+
return false;
11+
}
12+
}
13+
true
14+
}
15+
16+
#[kani::proof]
17+
#[kani::unwind(6)]
18+
fn check_sorted() {
19+
let mut arr: [i32; 5] = kani::any();
20+
arr.sort();
21+
assert!(is_sorted(&arr));
22+
}

0 commit comments

Comments
 (0)