Skip to content
Merged
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 tests/expected/shadow/slices/slice_of_array/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERIFICATION:- SUCCESSFUL
34 changes: 34 additions & 0 deletions tests/expected/shadow/slices/slice_of_array/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zghost-state

// This test demonstrates a possible usage of the shadow memory API to check that
// every element of an arbitrary slice of an array is initialized.
// Since the instrumentation is done manually in the harness only but not inside
// the library functions, the test only verifies that the slices point to memory
// that is within the original array.

const N: usize = 16;

static mut SM: kani::shadow::ShadowMem<bool> = kani::shadow::ShadowMem::new(false);

#[kani::proof]
#[kani::unwind(31)]
fn check_slice_init() {
let arr: [char; N] = kani::any();
// tag every element of the array as initialized
for i in &arr {
unsafe {
SM.set(i as *const char, true);
}
}
// create an arbitrary slice of the array
let end: usize = kani::any_where(|x| *x <= N);
let begin: usize = kani::any_where(|x| *x < end);
let slice = &arr[begin..end];

// verify that all elements of the slice are initialized
for i in slice {
assert!(unsafe { SM.get(i as *const char) });
}
}
1 change: 1 addition & 0 deletions tests/expected/shadow/slices/slice_reverse/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERIFICATION:- SUCCESSFUL
28 changes: 28 additions & 0 deletions tests/expected/shadow/slices/slice_reverse/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zghost-state

// This test demonstrates a possible usage of the shadow memory API to check that
// every element of a reversed array is initialized.
// Since the instrumentation is done manually in the harness only but not inside
// the `reverse` function, the test only verifies that the resulting array
// occupies the same memory as the original one.

const N: usize = 32;

static mut SM: kani::shadow::ShadowMem<bool> = kani::shadow::ShadowMem::new(false);

#[kani::proof]
fn check_reverse() {
let mut a: [u16; N] = kani::any();
for i in &a {
unsafe { SM.set(i as *const u16, true) };
}
a.reverse();

for i in &a {
unsafe {
assert!(SM.get(i as *const u16));
}
}
}
1 change: 1 addition & 0 deletions tests/expected/shadow/slices/slice_split/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERIFICATION:- SUCCESSFUL
35 changes: 35 additions & 0 deletions tests/expected/shadow/slices/slice_split/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zghost-state

// This test demonstrates a possible usage of the shadow memory API to check that
// every element of an array split into two slices is initialized.
// Since the instrumentation is done manually in the harness only but not inside
// the `split_at_checked` function, the test only verifies that the resulting
// slices occupy the same memory as the original array.

const N: usize = 16;

static mut SM: kani::shadow::ShadowMem<bool> = kani::shadow::ShadowMem::new(false);

#[kani::proof]
#[kani::unwind(17)]
fn check_reverse() {
let a: [bool; N] = kani::any();
for i in &a {
unsafe { SM.set(i as *const bool, true) };
}
let index: usize = kani::any_where(|x| *x <= N);
let (s1, s2) = a.split_at_checked(index).unwrap();

for i in s1 {
unsafe {
assert!(SM.get(i as *const bool));
}
}
for i in s2 {
unsafe {
assert!(SM.get(i as *const bool));
}
}
}