Skip to content

Commit 2cfe4dc

Browse files
author
Carolyn Zech
authored
Fix autoharness termination test & print metadata in alphabetical order (#3971)
#3968 [failed in the merge queue](https://github.com/model-checking/kani/actions/runs/14180398658/job/39724995535) because the `cargo_autoharness_termination` test assumed that the recursion test wouldn't time out, but it did. This doesn't happen often, since this test has worked up until now, but in the interest of having robust tests, this PR splits the termination test into two: - `autoharness_timeout`, which tests that the default timeout of 60s kicks in - `autoharness_unwind`, which tests that the default unwind bound of 20 kicks in The unwind test specifies a timeout of 5m to ensure that the unwind bound takes effect before the timeout. While I was fixing this, I also fixed some inconsistencies with the printed metadata: - We use "Chosen Function" in one table and "Selected Function" in another--changed it to "Selected Function" in both to be consistent - The functions aren't printed alphabetically in 2/3 tables--fixed so that they're always sorted By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 6e9cb87 commit 2cfe4dc

File tree

22 files changed

+253
-210
lines changed

22 files changed

+253
-210
lines changed

kani-compiler/src/kani_middle/codegen_units.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ impl CodegenUnits {
9292
args,
9393
*kani_fns.get(&KaniModel::Any.into()).unwrap(),
9494
);
95-
let chosen_fn_names = chosen.iter().map(|func| func.name()).collect::<Vec<_>>();
9695
AUTOHARNESS_MD
97-
.set(AutoHarnessMetadata { chosen: chosen_fn_names, skipped })
96+
.set(AutoHarnessMetadata {
97+
chosen: chosen.iter().map(|func| func.name()).collect::<BTreeSet<_>>(),
98+
skipped,
99+
})
98100
.expect("Initializing the autoharness metdata failed");
99101

100102
let automatic_harnesses = get_all_automatic_harnesses(

kani-driver/src/autoharness/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn postprocess_project(
8383
/// Print automatic harness metadata to the terminal.
8484
fn print_autoharness_metadata(metadata: Vec<KaniMetadata>) {
8585
let mut chosen_table = PrettyTable::new();
86-
chosen_table.set_header(vec!["Chosen Function"]);
86+
chosen_table.set_header(vec!["Selected Function"]);
8787

8888
let mut skipped_table = PrettyTable::new();
8989
skipped_table.set_header(vec!["Skipped Function", "Reason for Skipping"]);
@@ -122,7 +122,7 @@ fn print_autoharness_metadata(metadata: Vec<KaniMetadata>) {
122122
fn print_chosen_table(table: &mut PrettyTable) {
123123
if table.is_empty() {
124124
println!(
125-
"\nChosen Functions: None. Kani did not generate automatic harnesses for any functions in the available crate(s)."
125+
"\nSelected Functions: None. Kani did not generate automatic harnesses for any functions in the available crate(s)."
126126
);
127127
return;
128128
}
@@ -178,7 +178,8 @@ impl KaniSession {
178178
}
179179

180180
/// Prints the results from running the `autoharness` subcommand.
181-
pub fn print_autoharness_summary(&self, automatic: Vec<&HarnessResult<'_>>) -> Result<()> {
181+
pub fn print_autoharness_summary(&self, mut automatic: Vec<&HarnessResult<'_>>) -> Result<()> {
182+
automatic.sort_by(|a, b| a.harness.pretty_name.cmp(&b.harness.pretty_name));
182183
let (successes, failures): (Vec<_>, Vec<_>) =
183184
automatic.into_iter().partition(|r| r.result.status == VerificationStatus::Success);
184185

kani_metadata/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate clap;
55

66
use serde::{Deserialize, Serialize};
77
use std::{
8-
collections::{BTreeMap, HashSet},
8+
collections::{BTreeMap, BTreeSet, HashSet},
99
path::PathBuf,
1010
};
1111
use strum_macros::{Display, EnumString};
@@ -43,12 +43,12 @@ pub struct KaniMetadata {
4343

4444
/// For the autoharness subcommand, all of the user-defined functions we found,
4545
/// which are "chosen" if we generated an automatic harness for them, and "skipped" otherwise.
46+
/// We use ordered data structures so that the metadata is in alphabetical order.
4647
#[derive(Debug, Clone, Serialize, Deserialize)]
4748
pub struct AutoHarnessMetadata {
4849
/// Functions we generated automatic harnesses for.
49-
pub chosen: Vec<String>,
50+
pub chosen: BTreeSet<String>,
5051
/// Map function names to the reason why we did not generate an automatic harness for that function.
51-
/// We use an ordered map so that when we print the data, it is ordered alphabetically by function name.
5252
pub skipped: BTreeMap<String, AutoHarnessSkipReason>,
5353
}
5454

tests/script-based-pre/cargo_autoharness_contracts/contracts.expected

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
Kani generated automatic harnesses for 5 function(s):
22
+--------------------------------+
3-
| Chosen Function |
3+
| Selected Function |
44
+================================+
5-
| should_pass::div |
5+
| should_fail::max |
66
|--------------------------------|
7-
| should_pass::has_recursion_gcd |
7+
| should_pass::div |
88
|--------------------------------|
99
| should_pass::has_loop_contract |
1010
|--------------------------------|
11-
| should_pass::unchecked_mul |
11+
| should_pass::has_recursion_gcd |
1212
|--------------------------------|
13-
| should_fail::max |
13+
| should_pass::unchecked_mul |
1414
+--------------------------------+
1515

1616
Skipped Functions: None. Kani generated automatic harnesses for all functions in the available crate(s).
@@ -44,13 +44,13 @@ Autoharness Summary:
4444
+--------------------------------+-----------------------------+---------------------+
4545
| Selected Function | Kind of Automatic Harness | Verification Result |
4646
+====================================================================================+
47-
| should_pass::unchecked_mul | #[kani::proof_for_contract] | Success |
47+
| should_pass::div | #[kani::proof_for_contract] | Success |
4848
|--------------------------------+-----------------------------+---------------------|
4949
| should_pass::has_loop_contract | #[kani::proof] | Success |
5050
|--------------------------------+-----------------------------+---------------------|
5151
| should_pass::has_recursion_gcd | #[kani::proof_for_contract] | Success |
5252
|--------------------------------+-----------------------------+---------------------|
53-
| should_pass::div | #[kani::proof_for_contract] | Success |
53+
| should_pass::unchecked_mul | #[kani::proof_for_contract] | Success |
5454
|--------------------------------+-----------------------------+---------------------|
5555
| should_fail::max | #[kani::proof_for_contract] | Failure |
5656
+--------------------------------+-----------------------------+---------------------+

tests/script-based-pre/cargo_autoharness_dependencies/dependencies.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Kani generated automatic harnesses for 1 function(s):
2-
+-----------------+
3-
| Chosen Function |
4-
+=================+
5-
| yes_harness |
6-
+-----------------+
2+
+-------------------+
3+
| Selected Function |
4+
+===================+
5+
| yes_harness |
6+
+-------------------+
77

88
Skipped Functions: None. Kani generated automatic harnesses for all functions in the available crate(s).
99

tests/script-based-pre/cargo_autoharness_exclude/exclude.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Kani generated automatic harnesses for 1 function(s):
2-
+-----------------+
3-
| Chosen Function |
4-
+=================+
5-
| include::simple |
6-
+-----------------+
2+
+-------------------+
3+
| Selected Function |
4+
+===================+
5+
| include::simple |
6+
+-------------------+
77

88
Kani did not generate automatic harnesses for 2 function(s).
99
If you believe that the provided reason is incorrect and Kani should have generated an automatic harness, please comment on this issue: https://github.com/model-checking/kani/issues/3832

0 commit comments

Comments
 (0)