Skip to content

Commit

Permalink
Add fixme tests that reproduce issues model-checking#555, model-check…
Browse files Browse the repository at this point in the history
…ing#556, and model-checking#560 (model-checking#952)

Add tests for a few open issues.
  • Loading branch information
celinval authored and tedinski committed Apr 22, 2022
1 parent 1cae082 commit f44d4ae
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/kani/Cast/cast_abstract_args_to_concrete_fixme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test is a modified version of cast_abstract_args_to_concrete_fixme.rs.
//! The original test requires --no-undefined-function-checks to pass. This is an issue that
//! require investigation. See https://github.com/model-checking/kani/issues/555.
//!
//! Once this issue is fixed. Please remove this test and remove the kani flag from the original
//! test: --no-undefined-function-check

fn main() {
let _x32 = 1.0f32.powi(2);
let _x64 = 1.0f64.powi(2);

unsafe {
let size: libc::size_t = mem::size_of::<i32>();
let my_num: *mut libc::c_void = libc::malloc(size);
if my_num.is_null() {
panic!("failed to allocate memory");
}
let my_num2 = libc::memset(my_num, 1, size);
libc::free(my_num);
}
}
14 changes: 14 additions & 0 deletions tests/kani/Iterator/into_iter_fixme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

// compile-flags: --edition 2018
// kani-flags: --unwind 4
//
// This reproduces the issue seen in "Failures when iterating over results".
// See https://github.com/model-checking/kani/issues/556 for more information.
#[kani::proof]
pub fn main() {
let numbers = vec![1, 10, -1];
let positives: Vec<_> = numbers.into_iter().filter(|&n| n > 0).collect();
assert_eq!(positives.len(), 2);
}
45 changes: 45 additions & 0 deletions tests/kani/PhantomData/phantom_fixme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

// compile-flags: --edition 2018
// kani-flags: --unwind 4
//
// Testcase based on https://doc.rust-lang.org/rust-by-example/generics/phantom/testcase_units.html
// which reproduces issue https://github.com/model-checking/kani/issues/560

use std::marker::PhantomData;
use std::ops::Add;

#[derive(Debug, Clone, Copy)]
enum Mm {}

/// `Length` is a type with phantom type parameter `Unit`,
/// and is not generic over the length type (that is `u32`).
///
/// `u32` already implements the `Clone` and `Copy` traits.
#[derive(Debug, Clone, Copy)]
struct Length<Unit>(u32, PhantomData<Unit>);

/// The `Add` trait defines the behavior of the `+` operator.
impl<Unit> Add for Length<Unit> {
type Output = Length<Unit>;

// add() returns a new `Length` struct containing the sum.
fn add(self, rhs: Length<Unit>) -> Length<Unit> {
// `+` calls the `Add` implementation for `u32`.
Length(self.0 + rhs.0, PhantomData)
}
}

fn main() {
// `one_meter` has phantom type parameter `Mm`.
let one_meter: Length<Mm> = Length(1000, PhantomData);

// `+` calls the `add()` method we implemented for `Length<Unit>`.
//
// Since `Length` implements `Copy`, `add()` does not consume
// `one_foot` and `one_meter` but copies them into `self` and `rhs`.
let two_meters = one_meter + one_meter;

assert!(two_meters.0 == 2000);
}

0 comments on commit f44d4ae

Please sign in to comment.