-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Concrete Playback Unit tests to run with
--cfg kani
(#2353)
Co-authored-by: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com>
- Loading branch information
1 parent
94a26d1
commit f266f0f
Showing
8 changed files
with
102 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
script: playback_with_cfg_kani.sh | ||
expected: playback_with_cfg_kani.expected |
4 changes: 4 additions & 0 deletions
4
tests/script-based-pre/playback_with_cfg_kani/playback_with_cfg_kani.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,4 @@ | ||
failures: | ||
harnesses::kani_concrete_playback_harness_15598097466099501582 | ||
|
||
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; |
34 changes: 34 additions & 0 deletions
34
tests/script-based-pre/playback_with_cfg_kani/playback_with_cfg_kani.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,34 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
set +e | ||
|
||
OUT_DIR=sample_crate/target | ||
|
||
echo | ||
echo "Starting output file check..." | ||
echo | ||
|
||
|
||
# Check if cargo is installed | ||
if ! command -v cargo &> /dev/null; then | ||
echo "cargo command not found. Please install Rust and Cargo." | ||
exit 1 | ||
fi | ||
|
||
echo "Running cargo test on the unit test ..." | ||
echo | ||
|
||
cd sample_crate/ | ||
|
||
output=$(grep 'channel = ' ../../../../rust-toolchain.toml | cut -d '"' -f 2) | ||
echo "$output" | ||
|
||
# Run cargo test on the unit test | ||
RUSTFLAGS="--cfg=kani" cargo +${output} test 2>/dev/null | ||
|
||
cd .. | ||
|
||
# Try to leave a clean output folder at the end | ||
rm -rf ${OUT_DIR} |
13 changes: 13 additions & 0 deletions
13
tests/script-based-pre/playback_with_cfg_kani/sample_crate/Cargo.toml
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,13 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
[package] | ||
name = "sample_crate" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[dev-dependencies] | ||
kani = { path = "../../../../library/kani", features = ["concrete_playback"] } |
33 changes: 33 additions & 0 deletions
33
tests/script-based-pre/playback_with_cfg_kani/sample_crate/src/main.rs
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,33 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// This test checks that running the unit test generated using the concrete playback feature | ||
// with `RUSTFLAGS="--cfg=kani" cargo +nightly test doesn't cause a compilation error. | ||
// There is an existing UI test to generate the unit test itself (in kani/tests/ui/concrete-playback/result). | ||
|
||
fn main() {} | ||
|
||
#[cfg(kani)] | ||
mod harnesses { | ||
#[kani::proof] | ||
fn harness() { | ||
let result_1: Result<u8, u8> = kani::any(); | ||
let result_2: Result<u8, u8> = kani::any(); | ||
assert!(!(result_1 == Ok(101) && result_2 == Err(102))); | ||
} | ||
|
||
#[test] | ||
fn kani_concrete_playback_harness_15598097466099501582() { | ||
let concrete_vals: Vec<Vec<u8>> = vec![ | ||
// 1 | ||
vec![1], | ||
// 101 | ||
vec![101], | ||
// 0 | ||
vec![0], | ||
// 102 | ||
vec![102], | ||
]; | ||
kani::concrete_playback_run(concrete_vals, harness); | ||
} | ||
} |