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

Support for Primitive Proptests #1435

Closed
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
21014e2
Added proptest test cases.
Jul 1, 2022
6f28fb8
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 5, 2022
e797964
Added prototype translator.
Jul 5, 2022
988892c
Added missing recurisve case. Separated to helper.
Jul 5, 2022
7b4568a
Removed panic put in for debugging.
Jul 6, 2022
a0669f5
Changed name of translator
Jul 6, 2022
005bb7c
Refactored test case for proptest integration.
Jul 6, 2022
6b0c65e
Fixed typo in variable name.
Jul 6, 2022
7d43e49
Added multi-argument and combo tests for proptest.
Jul 6, 2022
690d1fa
purged redundant spaces.
Jul 6, 2022
a0e92f4
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 8, 2022
7f9836d
Rustfmt on library/kani_macros/src/lib.rs
Jul 8, 2022
334ec6e
Initial prototype to hijack proptest.
Jul 8, 2022
5697a90
Added todo not for hard-coded path.
Jul 9, 2022
a26fbcf
Partially working cargo kani hack. Recovery is not running though.
Jul 9, 2022
e3adb09
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 9, 2022
ef368d0
fixed empty var check
Jul 9, 2022
b78bda8
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 11, 2022
7291ac6
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 11, 2022
8c604f0
Added expanded macro printing to kani-compiler. Remove later.
Jul 14, 2022
b34431d
Added flags to mark rules in expanded form.
Jul 14, 2022
471f246
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 14, 2022
75a8621
Make the var names unique to detect rule firing.
Jul 15, 2022
c71f185
Prototyped new BODY2 rule. Need to push the API side for testing.
Jul 15, 2022
52733ec
Moved macros out to proper sugar.rs file.
Jul 18, 2022
e3e4226
Supported Minimum Strategy.
Jul 18, 2022
0386207
Got new proptest to type check. TODO: cleanup
Jul 19, 2022
f4af6eb
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 19, 2022
490f87b
Removed expansion. Somehow fixes the "finding proof" issue.
Jul 19, 2022
efe3cb4
Fixed missing tuple implementation.
Jul 19, 2022
eac76a7
Externalized arbitrary value generation. (Commit before macro try)
Jul 19, 2022
67a6494
Added hack translator for from strategy to kani.
Jul 20, 2022
59e3016
Implemented Invariant for tuples.
Jul 20, 2022
53d4eb9
Just use kani::any by itself for now.
Jul 20, 2022
f5ac0c6
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 22, 2022
9550f85
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 26, 2022
bbef351
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 26, 2022
4855fc5
Reverted proptest macro.
Jul 28, 2022
701725f
Temporary commit: hard-coded kani output path.
Jul 28, 2022
fd6dff4
Implemented custom compile script to get symtabs for proptest.
Jul 29, 2022
b22d996
Added automatic local target detection.
Jul 29, 2022
b94a9b0
Ignored expected error message.
Jul 30, 2022
276d155
implemented search of kani extern path for symtabs.
Jul 30, 2022
45f3689
Added proptest refresh to `kani` and `cargo kani` scripts..
Jul 30, 2022
6a40e85
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Jul 30, 2022
814ace3
Removed redundant part after PR1420 merged.
Jul 30, 2022
6a91150
Added back floating point support.
Aug 2, 2022
cad9f1d
Cleaned up warnings and clippy complaints.
Aug 2, 2022
4f6dd59
Added support for booleans.
Aug 2, 2022
c718138
Removed proptest translator not needed.
Aug 2, 2022
7d7f105
Fixed infinite recursion.
Aug 2, 2022
83bf62b
Fixed recompiling criteria.
Aug 2, 2022
7a1564e
Added prelude module.
Aug 2, 2022
b9e018d
Fixed license for PR.
Aug 2, 2022
2853a58
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Aug 2, 2022
31ad28a
Applied `cargo fmt`.
Aug 2, 2022
77f9e60
Added license to proptest Cargo.toml
Aug 2, 2022
14bedd8
Fixed clippy warning
Aug 2, 2022
0ce21d6
Added license to proptest module.
Aug 2, 2022
f7ecd5f
Merge branch 'main' of github.com:model-checking/kani into proptest-dev
Aug 3, 2022
68c1ce0
Purged non-basic proptest files.
Aug 3, 2022
decdc71
Adjust license tag.
Aug 3, 2022
0309b5e
Purged unused code.
Aug 3, 2022
f7064a0
Added todo message.
Aug 3, 2022
e6d1f46
Reverted invariant.rs.
Aug 3, 2022
5674243
Added basic test case.
Aug 3, 2022
952013e
Added proptest syntax sugar macros.
Aug 3, 2022
8a0335e
Reverted Cargo.toml of proptest testcase. The old one works.
Aug 3, 2022
85b17ee
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Aug 3, 2022
c091336
Rustfmt.
Aug 3, 2022
4a680ac
Supressed warnings caused by kani-specific panic! macro.
Aug 3, 2022
81b7601
Reverted invariant.
Aug 4, 2022
5aac1ed
Temporarily removed refresh script.
Aug 4, 2022
49bd73e
Cleaner path to root workspace.
Aug 4, 2022
a488a18
Made extended linking paths dependent on env being set for proptest.
Aug 4, 2022
5de4c25
Fixed proptest refresh taht was occuring too frequently.
Aug 4, 2022
02a94da
Remove proptest import. They break since only strategies are loaded.
Aug 4, 2022
a1f23c8
Purged tests not needed at this sub-PR.
Aug 4, 2022
9ddd844
Cleaned up paths.
Aug 4, 2022
a66a89c
Purged debug comment on macro expansion.
Aug 4, 2022
f744b7c
Fixed license.
Aug 4, 2022
933751a
Fixed license for new test case.
Aug 4, 2022
3262c1e
More temporary disabling of proptest
YoshikiTakashima Aug 4, 2022
f3e6e55
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
YoshikiTakashima Aug 4, 2022
2258b94
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Aug 5, 2022
0102218
Merge branch 'main' into yoshi-proptest-primitive
Aug 7, 2022
7b1fc35
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Aug 8, 2022
9ebad12
Changed comment to point to kani tracking issue.
Aug 8, 2022
b835517
Moved to using paths rather than string concat.
Aug 8, 2022
dbcbd2a
Made search for symtab more specific.
Aug 8, 2022
3b0f475
Set `-eu` like other scripts.
Aug 9, 2022
bcebad6
Moved to using `tomlq` wrapper around jq. Both installed.
Aug 9, 2022
4e4b0e5
Fixed typo.
Aug 9, 2022
1a549a4
Added docs.
Aug 9, 2022
ab9922d
Fixed dependency install after ci broke.
Aug 9, 2022
7239441
Merge branch 'main' of github.com:model-checking/kani into yoshi-prop…
Aug 9, 2022
fa80a27
Fixed cargo kani misclassifying proptest cases.
Aug 9, 2022
44a4074
Purged unneeded refresh.
Aug 9, 2022
526538c
Fixed clippy warning regarding derived traits.
Aug 9, 2022
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
7 changes: 7 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ dependencies = [
"unicode-ident",
]

[[package]]
name = "proptest"
version = "0.1.0"
dependencies = [
"kani",
]

[[package]]
name = "pulldown-cmark"
version = "0.9.1"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ strip = "debuginfo"
members = [
"library/kani",
"library/std",
"library/proptest",
"tools/bookrunner",
"tools/compiletest",
"tools/make-kani-release",
Expand Down
1 change: 1 addition & 0 deletions kani-compiler/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ pub fn main() {
setup_lib(&out_dir, &lib_out, "kani_macros");
setup_lib(&out_dir, &lib_out, "std");
println!("cargo:rustc-env=KANI_LIB_PATH={}", lib_out);
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
}
12 changes: 12 additions & 0 deletions kani-compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ fn rustc_gotoc_flags(lib_path: &str) -> Vec<String> {
// for more details.
let kani_std_rlib = PathBuf::from(lib_path).join("libstd.rlib");
let kani_std_wrapper = format!("noprelude:std={}", kani_std_rlib.to_str().unwrap());

let build_target = env!("TARGET"); // see build.rs
YoshikiTakashima marked this conversation as resolved.
Show resolved Hide resolved
let kani_extern_lib_path =
PathBuf::from(lib_path).join(format!("../../../../../{}/debug/deps", build_target));
YoshikiTakashima marked this conversation as resolved.
Show resolved Hide resolved

let args = vec![
"-C",
"overflow-checks=on",
Expand All @@ -65,12 +70,19 @@ fn rustc_gotoc_flags(lib_path: &str) -> Vec<String> {
"crate-attr=feature(register_tool)",
"-Z",
"crate-attr=register_tool(kanitool)",
// Prints expanded macro. For proptest devops only, remove after done
YoshikiTakashima marked this conversation as resolved.
Show resolved Hide resolved
// "-Z",
// "unpretty=expanded",
"-L",
lib_path,
"--extern",
"kani",
"--extern",
kani_std_wrapper.as_str(),
"-L",
kani_extern_lib_path.to_str().unwrap(),
"--extern",
"proptest",
];
args.iter().map(|s| s.to_string()).collect()
}
Expand Down
6 changes: 5 additions & 1 deletion kani-driver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ fn main() {
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
// So "repeat" the info from build script (here) to our crate's build environment.
println!("cargo:rustc-env=TARGET={}", var("TARGET").unwrap());

let target = var("TARGET").unwrap();
let out_dir = var("OUT_DIR").unwrap();
println!("cargo:rustc-env=KANI_EXTERN_DIR={}/../../../../{}/debug/deps", out_dir, target);
println!("cargo:rustc-env=TARGET={}", target);
}
14 changes: 11 additions & 3 deletions kani-driver/src/call_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ impl KaniSession {
let target_dir = self.args.target_dir.as_ref().unwrap_or(&find_target_dir()).clone();
let outdir = target_dir.join(build_target).join("debug/deps");

let kani_extern_lib_path = PathBuf::from(std::env!("KANI_EXTERN_DIR"));

let flag_env = {
let rustc_args = self.kani_rustc_flags();
crate::util::join_osstring(&rustc_args, " ")
Expand Down Expand Up @@ -82,9 +84,15 @@ impl KaniSession {

Ok(CargoOutputs {
outdir: outdir.clone(),
symtabs: glob(&outdir.join("*.symtab.json"))?,
metadata: glob(&outdir.join("*.kani-metadata.json"))?,
restrictions: self.args.restrict_vtable().then_some(outdir),
symtabs: glob(&outdir.join("*.symtab.json"))?
.into_iter()
.chain(glob(&kani_extern_lib_path.join("*.symtab.json"))?)
.collect(),
metadata: glob(&outdir.join("*.kani-metadata.json"))?
.into_iter()
.chain(glob(&kani_extern_lib_path.join("*.kani-metadata.json"))?)
.collect(),
restrictions: self.args.restrict_vtable().then(|| outdir),
})
}
}
Expand Down
24 changes: 24 additions & 0 deletions library/kani/src/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ empty_invariant!(f64);

empty_invariant!(());

macro_rules! tuple_invariant {
YoshikiTakashima marked this conversation as resolved.
Show resolved Hide resolved
($($fld:tt : $typ:ident),*) => {
unsafe impl<$($typ : Invariant),*> Invariant for ($($typ,)*) {
#[inline(always)]
fn is_valid(&self) -> bool {
($(self.$fld.is_valid() &&)* true)
}
}
}
}

tuple_invariant!(0: A);
tuple_invariant!(0: A, 1: B);
tuple_invariant!(0: A, 1: B, 2: C);
tuple_invariant!(0: A, 1: B, 2: C, 3: D);
tuple_invariant!(0: A, 1: B, 2: C, 3: D, 4: E);
tuple_invariant!(0: A, 1: B, 2: C, 3: D, 4: E, 5: F);
tuple_invariant!(0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G);
tuple_invariant!(0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H);
tuple_invariant!(0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I);
tuple_invariant!(0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J);
tuple_invariant!(0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K);
tuple_invariant!(0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K, 11: L);

unsafe impl Invariant for bool {
#[inline(always)]
fn is_valid(&self) -> bool {
Expand Down
14 changes: 14 additions & 0 deletions library/proptest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

[package]
YoshikiTakashima marked this conversation as resolved.
Show resolved Hide resolved
name = "proptest"
version = "0.1.0"
edition = "2021"
publish = false
license = "MIT OR Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[target.'cfg(not(kani))'.dependencies]
kani = { path = "../kani" }
59 changes: 59 additions & 0 deletions library/proptest/src/arbitrary/_alloc/alloc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//-
// Copyright 2017, 2018 The proptest developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Modifications Copyright Kani Contributors
// See GitHub history for details

//! Arbitrary implementations for `std::hash`.

use core::cmp;
use core::ops::Range;
use core::usize;

multiplex_alloc!(::alloc::alloc, ::std::alloc);

use crate::arbitrary::*;
use crate::strategy::statics::static_map;
use crate::strategy::*;

arbitrary!(self::alloc::Global; self::alloc::Global);

// Not Debug.
//lazy_just!(System, || System);

arbitrary!(self::alloc::Layout, SFnPtrMap<(Range<u8>, StrategyFor<usize>), Self>;
// 1. align must be a power of two and <= (1 << 31):
// 2. "when rounded up to the nearest multiple of align, must not overflow".
static_map((0u8..32u8, any::<usize>()), |(align_power, size)| {
let align = 1usize << align_power;
let max_size = 0usize.wrapping_sub(align);
// Not quite a uniform distribution due to clamping,
// but probably good enough
self::alloc::Layout::from_size_align(cmp::min(max_size, size), align).unwrap()
})
);

arbitrary!(self::alloc::AllocError, Just<Self>; Just(self::alloc::AllocError));
/* 2018-07-28 CollectionAllocErr is not currently available outside of using
* the `alloc` crate, which would require a different nightly feature. For now,
* disable.
arbitrary!(alloc::collections::CollectionAllocErr, TupleUnion<(WA<Just<Self>>, WA<Just<Self>>)>;
prop_oneof![Just(alloc::collections::CollectionAllocErr::AllocErr),
Just(alloc::collections::CollectionAllocErr::CapacityOverflow)]);
*/

#[cfg(test)]
mod test {
multiplex_alloc!(::alloc::alloc, ::std::alloc);

no_panic_test!(
layout => self::alloc::Layout,
alloc_err => self::alloc::AllocErr
//collection_alloc_err => alloc::collections::CollectionAllocErr
);
}
29 changes: 29 additions & 0 deletions library/proptest/src/arbitrary/_alloc/borrow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//-
// Copyright 2017, 2018 The proptest developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Modifications Copyright Kani Contributors
// See GitHub history for details

//! Arbitrary implementations for std::borrow.

use crate::std_facade::fmt;
use crate::std_facade::{Cow, ToOwned};
use core::borrow::Borrow;

use crate::arbitrary::{any_with, Arbitrary, SMapped};
use crate::strategy::statics::static_map;

arbitrary!(
[A: Arbitrary + Borrow<B>, B: ToOwned<Owned = A> + fmt::Debug + ?Sized]
Cow<'static, B>, SMapped<A, Self>, A::Parameters;
args => static_map(any_with::<A>(args), Cow::Owned)
);

lift1!([Borrow<B> + 'static, B: ToOwned<Owned = A> + fmt::Debug + ?Sized]
Cow<'static, B>; base => static_map(base, Cow::Owned)
);
21 changes: 21 additions & 0 deletions library/proptest/src/arbitrary/_alloc/boxed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//-
// Copyright 2017, 2018 The proptest developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Modifications Copyright Kani Contributors
// See GitHub history for details

//! Arbitrary implementations for `std::boxed`.

use crate::std_facade::Box;

wrap_from!(Box);

#[cfg(test)]
mod test {
no_panic_test!(boxed => Box<u8>);
}
91 changes: 91 additions & 0 deletions library/proptest/src/arbitrary/_alloc/char.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//-
// Copyright 2017, 2018 The proptest developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Modifications Copyright Kani Contributors
// See GitHub history for details

//! Arbitrary implementations for `std::char`.

use crate::std_facade::Vec;
use core::char::*;
use core::iter::once;
use core::ops::Range;

use crate::collection::vec;

multiplex_alloc! {
core::char::DecodeUtf16, std::char::DecodeUtf16,
core::char::DecodeUtf16Error, std::char::DecodeUtf16Error,
core::char::decode_utf16, std::char::decode_utf16
}

const VEC_MAX: usize = ::core::u16::MAX as usize;

use crate::arbitrary::*;
use crate::strategy::statics::static_map;
use crate::strategy::*;

macro_rules! impl_wrap_char {
($type: ty, $mapper: expr) => {
arbitrary!($type, SMapped<char, Self>;
static_map(any::<char>(), $mapper));
};
}

impl_wrap_char!(EscapeDebug, char::escape_debug);
impl_wrap_char!(EscapeDefault, char::escape_default);
impl_wrap_char!(EscapeUnicode, char::escape_unicode);
#[cfg(feature = "unstable")]
impl_wrap_char!(ToLowercase, char::to_lowercase);
#[cfg(feature = "unstable")]
impl_wrap_char!(ToUppercase, char::to_uppercase);

#[cfg(feature = "break-dead-code")]
arbitrary!(DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>,
SMapped<Vec<u16>, Self>;
static_map(vec(any::<u16>(), ..VEC_MAX), decode_utf16)
);

arbitrary!(ParseCharError, IndFlatten<Mapped<bool, Just<Self>>>;
any::<bool>().prop_ind_flat_map(|is_two|
Just((if is_two { "__" } else { "" }).parse::<char>().unwrap_err()))
);

#[cfg(feature = "unstable")]
arbitrary!(CharTryFromError; {
use core::convert::TryFrom;
char::try_from(0xD800 as u32).unwrap_err()
});

arbitrary!(DecodeUtf16Error, SFnPtrMap<Range<u16>, Self>;
static_map(0xD800..0xE000, |x|
decode_utf16(once(x)).next().unwrap().unwrap_err())
);

#[cfg(test)]
mod test {
no_panic_test!(
escape_debug => EscapeDebug,
escape_default => EscapeDefault,
escape_unicode => EscapeUnicode,
parse_char_error => ParseCharError,
decode_utf16_error => DecodeUtf16Error
);

#[cfg(feature = "break-dead-code")]
no_panic_test!(
decode_utf16 => DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>
);

#[cfg(feature = "unstable")]
no_panic_test!(
to_lowercase => ToLowercase,
to_uppercase => ToUppercase,
char_try_from_error => CharTryFromError
);
}
Loading