Skip to content

Commit

Permalink
better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsn committed Jul 1, 2022
1 parent c74fdf5 commit 2d3e6c8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/expected/mmio/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Status: SUCCESS\
Description: "offset: attempt to compute number in bytes which would overflow"

Status: SUCCESS\
Description: "attempt to compute offset which would overflow"

Status: FAILURE\
Description: "dereference failure: pointer NULL"

Status: SUCCESS
Description: "dereference failure: pointer invalid"

Status: FAILURE\
Description: "dereference failure: deallocated dynamic object"

Status: FAILURE\
Description: "dereference failure: dead object"

Status: FAILURE\
Description: "dereference failure: pointer outside object bounds"

Status: FAILURE\
Description: "dereference failure: invalid integer address"

Status: FAILURE\
Description: "dereference failure: invalid integer address"
19 changes: 19 additions & 0 deletions tests/expected/mmio/main.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

const BUFFER: *mut u32 = 0x8000 as *mut u32;
const BUFFER2: *mut u32 = 0x1000 as *mut u32;

#[cfg(kani)]
#[kani::proof]
#[kani::mmio_region(0x8000, 8)]
fn test_write() {
let val = 12;
unsafe {
//BUFFER+2 is not in the MMIO region
*(BUFFER.offset(2)) = val;
//BUFFER2 is not in the MMIO region
*BUFFER2 = val;

}
}
12 changes: 12 additions & 0 deletions tests/kani/MMIO/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ fn test_write2() {
core::ptr::write_volatile(BUFFER2, val);

}
}

#[cfg(kani)]
#[kani::proof]
#[kani::mmio_region(0x8000, 8)]
/// Check that larger MMIO regions also work
fn test_write3() {
let val = 12;
unsafe {
*BUFFER = val;
*(BUFFER.offset(1)) = val;
}
}

0 comments on commit 2d3e6c8

Please sign in to comment.