Skip to content

cargo kani --tests fails on crates with integration tests #1448

Closed

Description

@zhassan-aws

Steps to reproduce:

  1. cargo new foo
  2. cd foo
  3. Append the following to src/main.rs:
#[cfg(test)]
mod tests {
    #[test]
    #[kani::proof]
    fn check() {
        assert!(1 + 1 == 2);
    }
}
  1. Run cargo kani --tests. Verification is successful:

SUMMARY: 
 ** 0 of 1 failed

VERIFICATION:- SUCCESSFUL
  1. Under the package root directory, create a tests directory, and place a my_test.rs file inside with the following:
#[test]
fn main() {
    assert!(2 + 2 == 4);
}
  1. Run cargo clean
  2. Run cargo kani --tests again

This fails with the following:

$ cargo kani --tests
   Compiling foo v0.1.0 (/home/ubuntu/examples/integ_tests/foo)
    Finished test [unoptimized + debuginfo] target(s) in 0.26s
  Executable unittests src/main.rs (target/x86_64-unknown-linux-gnu/debug/deps/foo-61c8a3392540768f)
  Executable tests/my_test.rs (target/x86_64-unknown-linux-gnu/debug/deps/my_test-3ee8fa6d631c7ebc)
/home/ubuntu/git/kani/library/std/src/lib.rs: In function 'main':
/home/ubuntu/git/kani/library/std/src/lib.rs:41:9: error: 
reason for conflict at #this: number of members is different (2/0)

struct _15120766920117065333 {
  struct _15678888388531287603 ** data;
  unsigned long int len;
}
struct Unit {
}
error: conflicting types for variable 'main::1::var_1'
old definition in module '' file /home/ubuntu/examples/integ_tests/foo/src/main.rs line 1 column 1 function main
struct _15120766920117065333 {
  struct _15678888388531287603 ** data;
  unsigned long int len;
}
new definition in module '' file /home/ubuntu/git/kani/library/std/src/lib.rs line 41 column 9 function main
struct Unit {
}
         kani::assert($cond, concat!("assertion failed: ", stringify!($cond)));
/home/ubuntu/examples/integ_tests/foo/tests/my_test.rs: In function 'main':
/home/ubuntu/examples/integ_tests/foo/tests/my_test.rs:3:13: error: error: conflicting types for variable 'main::1::var_2'
old definition in module '' file /home/ubuntu/examples/integ_tests/foo/src/main.rs line 1 column 1 function main
struct [_13271361662039110976; 0] {
  struct _15678888388531287603 *[0] 0;
} *
new definition in module '' file /home/ubuntu/examples/integ_tests/foo/tests/my_test.rs line 3 column 13 function main
_Bool
     assert!(2 + 2 == 4);
typechecking main failed
Error: goto-cc exited with status exit status: 1

with Kani version: 43cb18c

Activity

  1. added
    [C] Bug
    on Aug 3, 2022
  2. changed the title [-]cargo kani fails on binary crates with integration tests[/-] [+]cargo kani --tests fails on crates with integration tests[/+] on Aug 4, 2022
  3. zhassan-aws commented on Aug 4, 2022

    @zhassan-aws
    ContributorAuthor

    Same issue is reproducible with lib crates.

  4. zhassan-aws commented on Aug 4, 2022

    @zhassan-aws
    ContributorAuthor

    We can use cargo test's --lib option to avoid running integration tests, e.g.:

    $ git diff
    diff --git a/kani-driver/src/call_cargo.rs b/kani-driver/src/call_cargo.rs
    index f8624297f97..d7010adf323 100644
    --- a/kani-driver/src/call_cargo.rs
    +++ b/kani-driver/src/call_cargo.rs
    @@ -48,6 +48,7 @@ pub fn cargo_build(&self) -> Result<CargoOutputs> {
             if self.args.tests {
                 args.push("test".into());
                 args.push("--no-run".into());
    +            args.push("--lib".into());
             } else {
                 args.push("build".into());
             }
    

    However, this results in an error for binary crates:

    error: no library targets found in package `foo`
    
  5. tedinski commented on Aug 8, 2022

    @tedinski
    Contributor

    Is this just about main in integration tests? Isn't that a strange thing to do? Did we actually run into code somewhere that does that?

  6. tedinski commented on Aug 26, 2022

    @tedinski
    Contributor

    Writing down thoughts so they don't get lost.

    Two potential issues here

    1. RMC should use fully qualified name for harness selection and it should not rely on no_mangle attribute #661
      This could be causing issues because main might otherwise be given a fully-qualified name that doesn't clash.
    2. kani-driver: Get json messages from cargo invocations #1598
      This could be causing issues because perhaps there really is a main regardless, and now we're colliding multiple binaries symbols together into one binary.
  7. self-assigned this
    on Nov 26, 2022
  8. added this to Kani 0.16and Kani 0.17 and removed this from Kani 0.16on Nov 26, 2022
  9. zhassan-aws commented on Dec 7, 2022

    @zhassan-aws
    ContributorAuthor

    This was fixed by the MIR linker. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[C] Bug

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions