-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix playback with build scripts (#2477)
I'm not 100% sure on why we need to set target, but without it, cargo is not properly running the build scripts as part of `playback` subcommand. I added that + made sure we propagate RUSTFLAGS to playback as well.
- Loading branch information
Showing
10 changed files
with
101 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
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_build.sh | ||
expected: playback_with_build.expected |
10 changes: 10 additions & 0 deletions
10
tests/script-based-pre/cargo_playback_build/playback_with_build.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,10 @@ | ||
[TEST] Generate test... | ||
Checking harness harnesses::harness... | ||
VERIFICATION:- SUCCESSFUL | ||
|
||
[TEST] Run test... | ||
running 2 tests | ||
test harnesses::kani_concrete_playback_harness | ||
test test::print_os_name | ||
|
||
test result: ok. 2 passed; 0 failed; |
22 changes: 22 additions & 0 deletions
22
tests/script-based-pre/cargo_playback_build/playback_with_build.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,22 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
set +e | ||
|
||
TMP_DIR="tmp_dir" | ||
|
||
rm -rf ${TMP_DIR} | ||
cp -r sample_crate ${TMP_DIR} | ||
pushd ${TMP_DIR} > /dev/null | ||
|
||
|
||
echo "[TEST] Generate test..." | ||
cargo kani --concrete-playback=inplace -Z concrete-playback | ||
|
||
echo "[TEST] Run test..." | ||
cargo kani playback -Z concrete-playback | ||
|
||
# Cleanup | ||
popd > /dev/null | ||
rm -r ${TMP_DIR} |
6 changes: 6 additions & 0 deletions
6
tests/script-based-pre/cargo_playback_build/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,6 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
[package] | ||
name = "sample_crate" | ||
version = "0.1.0" | ||
edition = "2021" |
10 changes: 10 additions & 0 deletions
10
tests/script-based-pre/cargo_playback_build/sample_crate/build.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,10 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
//! Export some variables to the harness | ||
use std::env::var; | ||
|
||
fn main() { | ||
let target = if var("TARGET").unwrap().contains("linux") { "linux" } else { "other" }; | ||
println!(r#"cargo:rustc-cfg=TARGET_OS="{}""#, target); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/script-based-pre/cargo_playback_build/sample_crate/src/lib.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,31 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! This test is used to test playback with a build configuration. | ||
#[cfg(TARGET_OS = "linux")] | ||
pub const OS_NAME: &'static str = "linux"; | ||
|
||
#[cfg(not(TARGET_OS = "linux"))] | ||
pub const OS_NAME: &'static str = "other"; | ||
|
||
#[cfg(kani)] | ||
mod harnesses { | ||
use super::*; | ||
|
||
#[kani::proof] | ||
fn harness() { | ||
kani::cover!(true, "Cover {OS_NAME}"); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn print_os_name() { | ||
println!("OS: {OS_NAME}"); | ||
assert!(["linux", "other"].contains(&OS_NAME)); | ||
} | ||
} |
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