Skip to content

Commit

Permalink
More expected tests (readable/writable)
Browse files Browse the repository at this point in the history
  • Loading branch information
adpaco-aws committed May 13, 2022
1 parent 9584340 commit 2369fe3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/expected/intrinsics/copy/copy-unreadable-src/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FAILURE\
memmove source region readable
16 changes: 16 additions & 0 deletions tests/expected/intrinsics/copy/copy-unreadable-src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Checks that `copy` fails when `src` is not valid for reads.
#[kani::proof]
fn test_copy_invalid() {
let arr: [i32; 3] = [0, 1, 0];
let src: *const i32 = arr.as_ptr();

unsafe {
// Get an invalid pointer with a negative offset
let src_invalid = unsafe { src.sub(1) as *const i32 };
let dst = src.add(1) as *mut i32;
core::intrinsics::copy(src_invalid, dst, 1);
}
}
2 changes: 2 additions & 0 deletions tests/expected/intrinsics/copy/copy-unwritable-dst/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FAILURE\
memmove destination region writeable
15 changes: 15 additions & 0 deletions tests/expected/intrinsics/copy/copy-unwritable-dst/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Checks that `copy` fails when `dst` is not valid for writes.
#[kani::proof]
fn test_copy_invalid() {
let arr: [i32; 3] = [0, 1, 0];
let src: *const i32 = arr.as_ptr();

unsafe {
// Get an invalid pointer with an out-of-bounds offset
let dst_invalid = src.add(3) as *mut i32;
core::intrinsics::copy(src, dst_invalid, 1);
}
}

0 comments on commit 2369fe3

Please sign in to comment.