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

Concrete playback needs tweak for harnesses under cfg(test) #1577

Open
zhassan-aws opened this issue Aug 23, 2022 · 3 comments
Open

Concrete playback needs tweak for harnesses under cfg(test) #1577

zhassan-aws opened this issue Aug 23, 2022 · 3 comments
Labels
[C] Bug This is a bug. Something isn't working.

Comments

@zhassan-aws
Copy link
Contributor

The current instructions for the concrete playback feature include adding kani in the dev-dependencies section. If the harness of interest is under #[cfg(test)], then cargo kani needs to be run with the --tests option. However, including --tests results in trying to compile the Kani crate with Kani! This fails with the following error:

error: duplicate diagnostic item found: `KaniAssume`.
  --> /home/ubuntu/.cargo/git/checkouts/kani-0ce0dacf5e98886d/499e35f/library/kani/src/lib.rs:44:1
   |
44 | pub fn assume(_cond: bool) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: the diagnostic item is first defined in crate `kani`.

error: duplicate diagnostic item found: `KaniExpectFail`.
   --> /home/ubuntu/.cargo/git/checkouts/kani-0ce0dacf5e98886d/499e35f/library/kani/src/lib.rs:122:1
    |
122 | pub fn expect_fail(_cond: bool, _message: &'static str) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the diagnostic item is first defined in crate `kani`.

error: duplicate diagnostic item found: `KaniAssert`.
  --> /home/ubuntu/.cargo/git/checkouts/kani-0ce0dacf5e98886d/499e35f/library/kani/src/lib.rs:61:1
   |
61 | pub fn assert(_cond: bool, _msg: &'static str) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: the diagnostic item is first defined in crate `kani`.

error: duplicate diagnostic item found: `KaniAnyRaw`.
   --> /home/ubuntu/.cargo/git/checkouts/kani-0ce0dacf5e98886d/499e35f/library/kani/src/lib.rs:115:1
    |
115 | fn any_raw_inner<T>() -> T {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the diagnostic item is first defined in crate `kani`.

error: duplicate diagnostic item found: `KaniPanic`.
   --> /home/ubuntu/.cargo/git/checkouts/kani-0ce0dacf5e98886d/499e35f/library/kani/src/lib.rs:137:1
    |
137 | pub fn panic(message: &'static str) -> ! {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the diagnostic item is first defined in crate `kani`.

Error: "Failed to compile crate."
error: could not compile `kani` due to 5 previous errors
Error: cargo exited with status exit status: 101

The workaround I've used is to remove kani from the dev-dependencies, before running cargo kani, then add it back before running debugging the generated harness.

Steps to reproduce:

  1. cargo new --lib conc_playback
  2. cd conc_playback
  3. Add kani to dev-dependencies in Cargo.toml:
[dev-dependencies]
kani = { git = "https://github.com/model-checking/kani", features = ["concrete_playback"] }
  1. Run cargo kani --tests
@zhassan-aws zhassan-aws added the [C] Bug This is a bug. Something isn't working. label Aug 23, 2022
@zhassan-aws
Copy link
Contributor Author

One easy fix is to update the instructions to suggest conditionally adding kani as a dev dependency:

[target.'cfg(not(kani))'.dev-dependencies]
kani = { git = "https://github.com/model-checking/kani", features = ["concrete_playback"] }

@celinval
Copy link
Contributor

That's an interesting one... There's definitely a conflict between --tests and --concrete-playback.

It feels a bit counter intuitive to add kani under cfg(not(kani)). Another issue is that the --concrete-playback feature adds the test case in the same module as the proof harness. So this fix wouldn't work if the harness is inside a module guarded with #[cfg(kani)]:

#[cfg(kani)]
mod harnesses {
  #[kani:proof]
  fn my_harness() {}

  // Test will be here.
}

@jaisnan
Copy link
Contributor

jaisnan commented Jan 31, 2023

Ran into this issue while adding the concrete playback button for the extension, this causes all cfg(test) or #[test] cases to crash and it gives the same underlying error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Bug This is a bug. Something isn't working.
Projects
None yet
Development

No branches or pull requests

3 participants