Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Concrete Playback Unit tests to run with --cfg kani #2353

Merged
merged 22 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a160eed
Generate unit test, line by line
jaisnan Feb 16, 2023
0168917
clippy changes
jaisnan Feb 16, 2023
964c22e
add tempfile dependency
jaisnan Feb 16, 2023
7d749bf
Merge branch 'main' of https://github.com/model-checking/kani into main
jaisnan Feb 16, 2023
aa83942
Merge branch 'main' of https://github.com/model-checking/kani into main
jaisnan Feb 22, 2023
16c2400
Merge branch 'main' of https://github.com/model-checking/kani into main
jaisnan Mar 31, 2023
de833b3
Merge branch 'main' of https://github.com/model-checking/kani into main
jaisnan Apr 2, 2023
d51294e
Add concrete_playback feature to kani_macros
jaisnan Apr 6, 2023
47e48f2
Merge branch 'main' of https://github.com/model-checking/kani into Fi…
jaisnan Apr 6, 2023
6c59f18
Add regression test
jaisnan Apr 6, 2023
d61f6ab
Merge branch 'main' of https://github.com/model-checking/kani into Fi…
jaisnan Apr 6, 2023
bc3671a
Delete accidental changes
jaisnan Apr 6, 2023
4ae20a3
Add copyright strings
jaisnan Apr 6, 2023
3429b9e
Fix cargo.toml
jaisnan Apr 6, 2023
c728dc3
Remove logging in CI test
jaisnan Apr 6, 2023
d1ddd11
Add nightly from toolchain file
jaisnan Apr 6, 2023
f43e284
Fix diff error in CI
jaisnan Apr 6, 2023
c111570
Remove time from expected
jaisnan Apr 6, 2023
223b9a8
Address comments
jaisnan Apr 6, 2023
8899012
Merge branch 'main' into Fix-concrete-playback-cfg-kani
jaisnan Apr 6, 2023
1c5c5b7
Update tests/script-based-pre/playback_with_cfg_kani/sample_crate/src…
jaisnan Apr 6, 2023
3d3f1fb
Merge branch 'main' into Fix-concrete-playback-cfg-kani
jaisnan Apr 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/kani/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ publish = false
kani_macros = { path = "../kani_macros" }

[features]
concrete_playback = []
concrete_playback = ["kani_macros/concrete_playback"]
3 changes: 3 additions & 0 deletions library/kani_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ proc-macro2 = "1.0"
proc-macro-error = "1.0.4"
quote = "1.0.20"
syn = { version = "1.0.98", features = ["full"] }

[features]
concrete_playback = []
20 changes: 10 additions & 10 deletions library/kani_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use {
syn::{parse_macro_input, ItemFn},
};

#[cfg(not(kani))]
#[cfg(any(not(kani), feature = "concrete_playback"))]
jaisnan marked this conversation as resolved.
Show resolved Hide resolved
#[proc_macro_attribute]
pub fn proof(_attr: TokenStream, item: TokenStream) -> TokenStream {
// Leave the code intact, so it can be easily be edited in an IDE,
Expand All @@ -38,7 +38,7 @@ pub fn proof(_attr: TokenStream, item: TokenStream) -> TokenStream {
/// Marks a Kani proof harness
///
/// For async harnesses, this will call [`kani::block_on`] (see its documentation for more information).
#[cfg(kani)]
#[cfg(all(kani, not(feature = "concrete_playback")))]
#[proc_macro_attribute]
pub fn proof(attr: TokenStream, item: TokenStream) -> TokenStream {
let fn_item = parse_macro_input!(item as ItemFn);
Expand Down Expand Up @@ -98,14 +98,14 @@ pub fn proof(attr: TokenStream, item: TokenStream) -> TokenStream {
}
}

#[cfg(not(kani))]
#[cfg(any(not(kani), feature = "concrete_playback"))]
#[proc_macro_attribute]
pub fn should_panic(_attr: TokenStream, item: TokenStream) -> TokenStream {
// No-op in non-kani mode
item
}

#[cfg(kani)]
#[cfg(all(kani, not(feature = "concrete_playback")))]
#[proc_macro_attribute]
pub fn should_panic(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.is_empty(), "`#[kani::should_panic]` does not take any arguments currently");
Expand All @@ -117,7 +117,7 @@ pub fn should_panic(attr: TokenStream, item: TokenStream) -> TokenStream {
result
}

#[cfg(not(kani))]
#[cfg(any(not(kani), feature = "concrete_playback"))]
#[proc_macro_attribute]
pub fn unwind(_attr: TokenStream, item: TokenStream) -> TokenStream {
// When the config is not kani, we should leave the function alone
Expand All @@ -127,7 +127,7 @@ pub fn unwind(_attr: TokenStream, item: TokenStream) -> TokenStream {
/// Set Loop unwind limit for proof harnesses
/// The attribute '#[kani::unwind(arg)]' can only be called alongside '#[kani::proof]'.
/// arg - Takes in a integer value (u32) that represents the unwind value for the harness.
#[cfg(kani)]
#[cfg(all(kani, not(feature = "concrete_playback")))]
#[proc_macro_attribute]
pub fn unwind(attr: TokenStream, item: TokenStream) -> TokenStream {
let mut result = TokenStream::new();
Expand All @@ -140,7 +140,7 @@ pub fn unwind(attr: TokenStream, item: TokenStream) -> TokenStream {
result
}

#[cfg(not(kani))]
#[cfg(any(not(kani), feature = "concrete_playback"))]
#[proc_macro_attribute]
pub fn stub(_attr: TokenStream, item: TokenStream) -> TokenStream {
// When the config is not kani, we should leave the function alone
Expand All @@ -154,7 +154,7 @@ pub fn stub(_attr: TokenStream, item: TokenStream) -> TokenStream {
/// # Arguments
/// * `original` - The function or method to replace, specified as a path.
/// * `replacement` - The function or method to use as a replacement, specified as a path.
#[cfg(kani)]
#[cfg(all(kani, not(feature = "concrete_playback")))]
#[proc_macro_attribute]
pub fn stub(attr: TokenStream, item: TokenStream) -> TokenStream {
let mut result = TokenStream::new();
Expand All @@ -167,7 +167,7 @@ pub fn stub(attr: TokenStream, item: TokenStream) -> TokenStream {
result
}

#[cfg(not(kani))]
#[cfg(any(not(kani), feature = "concrete_playback"))]
#[proc_macro_attribute]
pub fn solver(_attr: TokenStream, item: TokenStream) -> TokenStream {
// No-op in non-kani mode
Expand All @@ -178,7 +178,7 @@ pub fn solver(_attr: TokenStream, item: TokenStream) -> TokenStream {
/// The attribute `#[kani::solver(arg)]` can only be used alongside `#[kani::proof]``
///
/// arg - name of solver, e.g. kissat
#[cfg(kani)]
#[cfg(all(kani, not(feature = "concrete_playback")))]
#[proc_macro_attribute]
pub fn solver(attr: TokenStream, item: TokenStream) -> TokenStream {
let mut result = TokenStream::new();
Expand Down
13 changes: 13 additions & 0 deletions tests/script-based-pre/concrete_playback_test/bin/Cargo.toml
jaisnan marked this conversation as resolved.
Show resolved Hide resolved
jaisnan marked this conversation as resolved.
Show resolved Hide resolved
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 = "bin"
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"] }
29 changes: 29 additions & 0 deletions tests/script-based-pre/concrete_playback_test/bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

jaisnan marked this conversation as resolved.
Show resolved Hide resolved
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)));
}

jaisnan marked this conversation as resolved.
Show resolved Hide resolved
#[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);
}
}
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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

set +e

OUT_DIR=bin/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

# Check if the directory containing cargo is in the PATH environment variable
if ! echo "$PATH" | grep -q "$(dirname "$(command -v cargo)")"; then
echo "Directory containing cargo is not in PATH. Adding directory to PATH..."
echo "export PATH=$PATH:$(dirname "$(command -v cargo)")" >> ~/.bashrc
jaisnan marked this conversation as resolved.
Show resolved Hide resolved
source ~/.bashrc
fi

echo "Running cargo test on the unit test ..."
karkhaz marked this conversation as resolved.
Show resolved Hide resolved
echo

cd bin/

output=$(grep 'channel = ' ../../../../rust-toolchain.toml | cut -d '"' -f 2)
echo "$output"

# Run cargo test on the unit test
cargo_output=$(RUSTFLAGS="--cfg=kani" cargo +${output} test 2>/dev/null)
jaisnan marked this conversation as resolved.
Show resolved Hide resolved
echo "$cargo_output"

cd ..

# Try to leave a clean output folder at the end
rm -rf ${OUT_DIR}
karkhaz marked this conversation as resolved.
Show resolved Hide resolved

set -e
jaisnan marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions tests/script-based-pre/concrete_playback_test/config.yml
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: concrete_playback_test.sh
expected: concrete_playback_test.expected