-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix concrete playback for array and add test
- Loading branch information
Showing
7 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
//! Check that Kani correctly adds tests to when the harness is a proof for contract. | ||
extern crate kani; | ||
|
||
#[kani::requires(idx < slice.len())] | ||
#[kani::modifies(slice)] | ||
#[kani::ensures(| _ | slice[idx] == new_val)] | ||
fn modify_slice(slice: &mut [u32], idx: usize, new_val: u32) { | ||
// Inject bug by incrementing index first. | ||
let new_idx = idx + 1; | ||
*slice.get_mut(new_idx).expect("Expected valid index, but contract is wrong") = new_val; | ||
} | ||
|
||
#[kani::proof_for_contract(modify_slice)] | ||
fn check_modify_slice() { | ||
let mut data: [u32; 4] = kani::any(); | ||
modify_slice(&mut data, kani::any(), kani::any()) | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/script-based-pre/playback_contracts/playback_with_contracts.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[TEST] Generate test... | ||
Checking harness check_modify_slice... | ||
|
||
Failed Checks: | _ | slice[idx] == new_val | ||
Failed Checks:\ | ||
in std::option::expect_failed | ||
|
||
VERIFICATION:- FAILED | ||
|
||
[TEST] Run test... | ||
|
||
running 2 tests | ||
|
||
Expected valid index, but contract is wrong | ||
test result: FAILED. 1 passed; 1 failed; |
20 changes: 20 additions & 0 deletions
20
tests/script-based-pre/playback_contracts/playback_with_contracts.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
# Test that concrete playback -Z concrete-playback executes as expected | ||
set -o nounset | ||
|
||
RS_FILE="modified.rs" | ||
cp original.rs ${RS_FILE} | ||
|
||
echo "[TEST] Generate test..." | ||
kani ${RS_FILE} -Z concrete-playback --concrete-playback=inplace -Z function-contracts --output-format terse | ||
|
||
# Note that today one of the tests will succeed since the contract pre-conditions are not inserted by Kani. | ||
# Hopefully this will change with https://github.com/model-checking/kani/issues/3326 | ||
echo "[TEST] Run test..." | ||
kani playback -Z concrete-playback ${RS_FILE} -- kani_concrete_playback | ||
|
||
# Cleanup | ||
rm ${RS_FILE} | ||
rm kani_concrete_playback |