Skip to content

Commit 7209765

Browse files
author
Carolyn Zech
authored
Autoharness: exit code 1 upon harness failure (#4043)
Exit Kani with a failure code if any automatic harnesses fail. This replicates the behavior of just running manual harnesses. 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 60aa1dd commit 7209765

File tree

11 files changed

+18
-24
lines changed

11 files changed

+18
-24
lines changed

kani-driver/src/autoharness/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ impl KaniSession {
200200
}
201201

202202
/// Prints the results from running the `autoharness` subcommand.
203-
pub fn print_autoharness_summary(&self, mut automatic: Vec<&HarnessResult<'_>>) -> Result<()> {
203+
pub fn print_autoharness_summary(
204+
&self,
205+
mut automatic: Vec<&HarnessResult<'_>>,
206+
) -> Result<usize> {
204207
automatic.sort_by(|a, b| a.harness.pretty_name.cmp(&b.harness.pretty_name));
205208
let (successes, failures): (Vec<_>, Vec<_>) =
206209
automatic.into_iter().partition(|r| r.result.status == VerificationStatus::Success);
@@ -258,6 +261,6 @@ impl KaniSession {
258261
println!("No functions were eligible for automatic verification.");
259262
}
260263

261-
Ok(())
264+
Ok(failing)
262265
}
263266
}

kani-driver/src/harness_runner.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,13 @@ impl KaniSession {
298298
self.show_coverage_summary()?;
299299
}
300300

301-
if self.autoharness_compiler_flags.is_some() {
302-
self.print_autoharness_summary(automatic)?;
303-
}
301+
let autoharness_failing = if self.autoharness_compiler_flags.is_some() {
302+
self.print_autoharness_summary(automatic)?
303+
} else {
304+
0
305+
};
304306

305-
if failing > 0 && self.autoharness_compiler_flags.is_none() {
307+
if failing + autoharness_failing > 0 {
306308
// Failure exit code without additional error message
307309
drop(self);
308310
std::process::exit(1);

tests/script-based-pre/cargo_autoharness_contracts/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33
script: contracts.sh
44
expected: contracts.expected
5+
exit_code: 1

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@
33
# SPDX-License-Identifier: Apache-2.0 OR MIT
44

55
cargo kani autoharness -Z autoharness
6-
# We expect verification to fail, so the above command will produce an exit status of 1
7-
# However, we don't want the test to fail because of that exit status; we only want it to fail if the expected file doesn't match
8-
# So, exit with a status code of 0 explicitly.
9-
exit 0;

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22
# Copyright Kani Contributors
33
# SPDX-License-Identifier: Apache-2.0 OR MIT
44

5-
cargo kani autoharness -Z autoharness
6-
# We expect verification to fail, so the above command will produce an exit status of 1
7-
# However, we don't want the test to fail because of that exit status; we only want it to fail if the expected file doesn't match
8-
# So, exit with a status code of 0 explicitly.
9-
exit 0;
5+
cargo kani autoharness -Z autoharness

tests/script-based-pre/cargo_autoharness_harnesses_fail/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33
script: harnesses_fail.sh
44
expected: harnesses_fail.expected
5+
exit_code: 1

tests/script-based-pre/cargo_autoharness_harnesses_fail/harnesses_fail.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22
# Copyright Kani Contributors
33
# SPDX-License-Identifier: Apache-2.0 OR MIT
44

5-
cargo kani autoharness -Z autoharness
6-
# We expect verification to fail, so the above command will produce an exit status of 1
7-
# However, we don't want the test to fail because of that exit status; we only want it to fail if the expected file doesn't match
8-
# So, exit with a status code of 0 explicitly.
9-
exit 0;
5+
cargo kani autoharness -Z autoharness

tests/script-based-pre/cargo_autoharness_termination_timeout/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33
script: termination_timeout.sh
44
expected: termination_timeout.expected
5+
exit_code: 1

tests/script-based-pre/cargo_autoharness_termination_unwind/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33
script: termination_unwind.sh
44
expected: termination_unwind.expected
5+
exit_code: 1

tests/script-based-pre/cargo_autoharness_type_invariant/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33
script: type-invariant.sh
44
expected: type-invariant.expected
5+
exit_code: 1

0 commit comments

Comments
 (0)