Skip to content

Commit 399c079

Browse files
authored
Merge pull request #26 from os-checker/test-proofs
Test: add new tests for proofs behaviors
2 parents ec31816 + 112b242 commit 399c079

File tree

6 files changed

+3117
-500
lines changed

6 files changed

+3117
-500
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/target
2+
3+
# ignore kani folder for grep or files findings
4+
# kani

tests/proofs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn test_proofs() -> eyre::Result<()> {
1818
[
1919
"tests/proofs/standard_proofs_with_contracts.rs",
2020
"tests/proofs/standard_proofs.rs",
21+
"tests/proofs/ad_hoc.rs",
2122
]
2223
"#]]
2324
.assert_debug_eq(&proofs);

tests/proofs/ad_hoc.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[cfg(kani)]
2+
mod adhoc {
3+
#[kani::proof]
4+
fn callee_defined_in_proof() {
5+
fn f() -> u8 {
6+
1
7+
}
8+
assert!(f() == 1);
9+
}
10+
11+
#[kani::proof]
12+
fn closure_in_proof() {
13+
let f = || 1;
14+
assert!(f() == 1);
15+
}
16+
17+
fn proof_in_fn_item() {
18+
#[kani::proof]
19+
fn proof() {
20+
assert!(kani::any::<u8>() == 1);
21+
}
22+
}
23+
}

tests/proofs/standard_proofs_with_contracts.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod verify {
44
fn contract_requires(a: u8) {}
55

66
#[kani::proof]
7-
fn standard_proof_with_contract_requires() {
7+
fn single_contract_requires() {
88
contract_requires(0);
99
}
1010

@@ -14,7 +14,25 @@ mod verify {
1414
}
1515

1616
#[kani::proof]
17-
fn standard_proof_with_contract_ensures() {
17+
fn single_with_contract_ensures() {
1818
contract_ensures(0);
1919
}
20+
21+
#[kani::proof]
22+
fn two_contracts_requires_and_ensures() {
23+
let val = contract_ensures(0);
24+
contract_ensures(val);
25+
}
26+
27+
#[kani::requires(a > 0)]
28+
#[kani::ensures(|&ret| ret > 0)]
29+
fn contract(a: u8) -> u8 {
30+
a
31+
}
32+
33+
#[kani::proof]
34+
fn single_contract() {
35+
let val = contract(1);
36+
assert!(val > 0);
37+
}
2038
}

tests/snapshots/ad_hoc.json

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
[
2+
{
3+
"hash": "952175153267326104817555187587143859995",
4+
"def_id": "DefId { id: 0, name: \"adhoc::callee_defined_in_proof\" }",
5+
"file": "tests/proofs/ad_hoc.rs",
6+
"attrs": [
7+
"#[kanitool::proof]"
8+
],
9+
"func": "fn callee_defined_in_proof() {\n fn f() -> u8 {\n 1\n }\n assert!(f() == 1);\n }",
10+
"callees": [
11+
{
12+
"def_id": "DefId { id: 6, name: \"kani::assert\" }",
13+
"file": "kani/library/kani_core/src/lib.rs",
14+
"func": "pub const fn assert(cond: bool, msg: &'static str) {\n let _ = cond;\n let _ = msg;\n }"
15+
},
16+
{
17+
"def_id": "DefId { id: 1, name: \"adhoc::callee_defined_in_proof::f\" }",
18+
"file": "tests/proofs/ad_hoc.rs",
19+
"func": "fn f() -> u8 {\n 1\n }"
20+
}
21+
]
22+
},
23+
{
24+
"hash": "75621983092344117614099719256493026487",
25+
"def_id": "DefId { id: 2, name: \"adhoc::closure_in_proof\" }",
26+
"file": "tests/proofs/ad_hoc.rs",
27+
"attrs": [
28+
"#[kanitool::proof]"
29+
],
30+
"func": "fn closure_in_proof() {\n let f = || 1;\n assert!(f() == 1);\n }",
31+
"callees": [
32+
{
33+
"def_id": "DefId { id: 6, name: \"kani::assert\" }",
34+
"file": "kani/library/kani_core/src/lib.rs",
35+
"func": "pub const fn assert(cond: bool, msg: &'static str) {\n let _ = cond;\n let _ = msg;\n }"
36+
},
37+
{
38+
"def_id": "DefId { id: 3, name: \"adhoc::closure_in_proof::{closure#0}\" }",
39+
"file": "tests/proofs/ad_hoc.rs",
40+
"func": "|| 1"
41+
}
42+
]
43+
},
44+
{
45+
"hash": "767440852073129240514318853477184375838",
46+
"def_id": "DefId { id: 5, name: \"adhoc::proof_in_fn_item::proof\" }",
47+
"file": "tests/proofs/ad_hoc.rs",
48+
"attrs": [
49+
"#[kanitool::proof]"
50+
],
51+
"func": "fn proof() {\n assert!(kani::any::<u8>() == 1);\n }",
52+
"callees": [
53+
{
54+
"def_id": "DefId { id: 10, name: \"<u8 as kani::Arbitrary>::any\" }",
55+
"file": "kani/library/kani_core/src/arbitrary.rs",
56+
"func": "fn any() -> Self {\n // This size_of call does not use generic_const_exprs feature. It's inside a macro, and Self isn't generic.\n unsafe { crate::kani::any_raw_internal::<Self>() }\n }"
57+
},
58+
{
59+
"def_id": "DefId { id: 12, name: \"kani::any_raw\" }",
60+
"file": "kani/library/kani_core/src/lib.rs",
61+
"func": "fn any_raw<T: Copy>() -> T {\n kani_intrinsic()\n }"
62+
},
63+
{
64+
"def_id": "DefId { id: 13, name: \"kani::kani_intrinsic\" }",
65+
"file": "kani/library/kani_core/src/lib.rs",
66+
"func": "fn kani_intrinsic<T>() -> T {\n #[allow(clippy::empty_loop)]\n loop {}\n }"
67+
},
68+
{
69+
"def_id": "DefId { id: 6, name: \"kani::assert\" }",
70+
"file": "kani/library/kani_core/src/lib.rs",
71+
"func": "pub const fn assert(cond: bool, msg: &'static str) {\n let _ = cond;\n let _ = msg;\n }"
72+
},
73+
{
74+
"def_id": "DefId { id: 8, name: \"kani::any\" }",
75+
"file": "kani/library/kani_core/src/lib.rs",
76+
"func": "pub fn any<T: Arbitrary>() -> T {\n T::any()\n }"
77+
},
78+
{
79+
"def_id": "DefId { id: 11, name: \"kani::any_raw_internal\" }",
80+
"file": "kani/library/kani_core/src/lib.rs",
81+
"func": "unsafe fn any_raw_internal<T: Copy>() -> T {\n any_raw::<T>()\n }"
82+
}
83+
]
84+
}
85+
]

0 commit comments

Comments
 (0)