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

Add coverage test suite #2608

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions scripts/kani-regression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cargo test -p kani_metadata
# Declare testing suite information (suite and mode)
TESTS=(
"script-based-pre exec"
"coverage coverage-based"
"kani kani"
"expected expected"
"ui expected"
Expand Down
2 changes: 2 additions & 0 deletions tests/coverage/reachable/assert-false/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
22, SATISFIED
27, SATISFIED
36 changes: 36 additions & 0 deletions tests/coverage/reachable/assert-false/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//
// Check the location of the assert statement when using assert!(false);
// This currently requires the old format since the new format doesn't include
// line numbers https://github.com/model-checking/kani/issues/918
// Also disable reachability checks because they add annotations to each
// assert's description which would be visible with the old output format

fn any_bool() -> bool {
kani::any()
}

#[kani::proof]
fn main() {
if any_bool() {
assert!(false);
}

if any_bool() {
let s = "Fail with custom runtime message";
kani::cover!();
assert!(false, "{}", s);
}

if any_bool() {
kani::cover!();
assert!(false, "Fail with custom static message");
}
}

#[inline(always)]
#[track_caller]
fn check_caller(b: bool) {
assert!(b);
}
Empty file.
1 change: 1 addition & 0 deletions tests/coverage/reachable/assert/reachable_fail/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8, SATISFIED
11 changes: 11 additions & 0 deletions tests/coverage/reachable/assert/reachable_fail/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

#[kani::proof]
fn main() {
let x = 5;
if kani::any() {
kani::cover!();
assert!(x != 5);
}
}
1 change: 1 addition & 0 deletions tests/coverage/reachable/assert/reachable_pass/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8, SATISFIED
11 changes: 11 additions & 0 deletions tests/coverage/reachable/assert/reachable_pass/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

#[kani::proof]
fn main() {
let x = 5;
if x > 3 {
kani::cover!();
assert!(x > 4);
}
}
Empty file.
1 change: 1 addition & 0 deletions tests/coverage/reachable/bounds/reachable_fail/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
17 changes: 17 additions & 0 deletions tests/coverage/reachable/bounds/reachable_fail/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for
// index-out-of-bounds checks and that it reports ones that are unreachable.
// The check in this test is reachable and doesn't hold, so should be reported
// as FAILURE

fn get(s: &[i16], index: usize) -> i16 {
kani::cover!();
s[index]
}

#[kani::proof]
fn main() {
get(&[7, -83, 19], 15);
}
1 change: 1 addition & 0 deletions tests/coverage/reachable/bounds/reachable_pass/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
20 changes: 20 additions & 0 deletions tests/coverage/reachable/bounds/reachable_pass/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for
// index-out-of-bounds checks and that it reports ones that are unreachable.
// The check in this test is reachable, so should be reported as SUCCESS

fn get(s: &[i16], index: usize) -> i16 {
if index < s.len() {
kani::cover!();
s[index]
} else {
-1
}
}

#[kani::proof]
fn main() {
get(&[7, -83, 19], 2);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11, SATISFIED
19 changes: 19 additions & 0 deletions tests/coverage/reachable/debug-assert-eq/reachable_fail/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for debug_assert_eq
// macro and that it reports ones that are unreachable.
// The check in this test is reachable and does not hold, so should be reported
// as FAILURE

fn check(x: i32) {
if x > 5 {
kani::cover!();
debug_assert_eq!(x, 10);
}
}

#[kani::proof]
fn main() {
check(7);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
18 changes: 18 additions & 0 deletions tests/coverage/reachable/debug-assert-eq/reachable_pass/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for debug_assert_eq
// macro and that it reports ones that are unreachable.
// The check in this test is reachable, so should be reported as SUCCESS

fn check(x: i32) {
if x > 5 {
kani::cover!();
debug_assert_eq!(x, 10);
}
}

#[kani::proof]
fn main() {
check(10);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11, SATISFIED
19 changes: 19 additions & 0 deletions tests/coverage/reachable/debug-assert-ne/reachable_fail/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for debug_assert_ne
// macro and that it reports ones that are unreachable.
// The check in this test is reachable and does not hold, so should be reported
// as FAILURE

fn check(x: i32) {
if x > 5 {
kani::cover!();
debug_assert_ne!(x, 17);
}
}

#[kani::proof]
fn main() {
check(17);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
18 changes: 18 additions & 0 deletions tests/coverage/reachable/debug-assert-ne/reachable_pass/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for debug_assert_ne
// macro and that it reports ones that are unreachable.
// The check in this test is reachable, so should be reported as SUCCESS

fn check(x: i32) {
if x > 5 {
kani::cover!();
debug_assert_ne!(x, 17);
}
}

#[kani::proof]
fn main() {
check(10);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
17 changes: 17 additions & 0 deletions tests/coverage/reachable/div-zero/reachable_fail/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for
// divide-by-zero checks and that it reports ones that are unreachable.
// The check in this test is reachable and doesn't hold, so should be reported
// as FAILURE

fn div(x: u16, y: u16) -> u16 {
kani::cover!();
x / y
}

#[kani::proof]
fn main() {
div(678, 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
20 changes: 20 additions & 0 deletions tests/coverage/reachable/div-zero/reachable_pass/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for
// divide-by-zero checks and that it reports ones that are unreachable.
// The check in this test is reachable, so should be reported as SUCCESS

fn div(x: u16, y: u16) -> u16 {
if y != 0 {
kani::cover!();
x / y
} else {
0
}
}

#[kani::proof]
fn main() {
div(11, 3);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
17 changes: 17 additions & 0 deletions tests/coverage/reachable/overflow-neg/reachable_fail/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for negation
// overflow checks and that it reports ones that are unreachable
// The negation overflow check in this test is reachable and doesn't hold, so
// should be reported as FAILURE

fn negate(x: i32) -> i32 {
kani::cover!();
-x
}

#[kani::proof]
fn main() {
negate(std::i32::MIN);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11, SATISFIED
21 changes: 21 additions & 0 deletions tests/coverage/reachable/overflow-neg/reachable_pass/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for negation
// overflow checks and that it reports ones that are unreachable
// The negation overflow check in this test is reachable, so should be
// reported as SUCCESS

fn negate(x: i32) -> i32 {
if x != std::i32::MIN {
kani::cover!();
-x
} else {
std::i32::MAX
}
}

#[kani::proof]
fn main() {
negate(7532);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11, SATISFIED
22 changes: 22 additions & 0 deletions tests/coverage/reachable/overflow/reachable_fail/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for arithmetic
// overflow checks and that it reports ones that are unreachable.
// The arithmetic overflow check in this test is reachable but does not hold, so
// should be reported as FAILURE

fn cond_reduce(thresh: u32, x: u32) -> u32 {
if x > thresh {
kani::cover!();
x - 50
} else {
x
}
}

#[kani::proof]
fn main() {
cond_reduce(60, 70);
cond_reduce(40, 42);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11, SATISFIED
24 changes: 24 additions & 0 deletions tests/coverage/reachable/overflow/reachable_pass/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for arithmetic
// overflow checks and that it reports ones that are unreachable.
// The arithmetic overflow check in this test is reachable, so should be
// reported as SUCCESS

fn reduce(x: u32) -> u32 {
if x > 1000 {
kani::cover!();
x - 1000
} else {
x
}
}

#[kani::proof]
fn main() {
reduce(7);
reduce(33);
reduce(728);
reduce(1079);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
17 changes: 17 additions & 0 deletions tests/coverage/reachable/rem-zero/reachable_fail/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for
// remainder-by-zero checks and that it reports ones that are unreachable.
// The check in this test is reachable and doesn't hold, so should be reported
// as FAILURE

fn rem(x: u16, y: u16) -> u16 {
kani::cover!();
x % y
}

#[kani::proof]
fn main() {
rem(678, 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10, SATISFIED
20 changes: 20 additions & 0 deletions tests/coverage/reachable/rem-zero/reachable_pass/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// This test checks that kani injects a reachability check for
// remainder-by-zero checks and that it reports ones that are unreachable.
// The check in this test is reachable, so should be reported as SUCCESS

fn rem(x: u16, y: u16) -> u16 {
if y != 0 {
kani::cover!();
x % y
} else {
0
}
}

#[kani::proof]
fn main() {
rem(11, 3);
}
3 changes: 3 additions & 0 deletions tests/coverage/unreachable/abort/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
22, UNREACHABLE
12, SATISFIED
17, UNREACHABLE
Loading