Skip to content

Commit 2d3e6c8

Browse files
committed
better tests
1 parent c74fdf5 commit 2d3e6c8

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

tests/expected/mmio/expected

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Status: SUCCESS\
2+
Description: "offset: attempt to compute number in bytes which would overflow"
3+
4+
Status: SUCCESS\
5+
Description: "attempt to compute offset which would overflow"
6+
7+
Status: FAILURE\
8+
Description: "dereference failure: pointer NULL"
9+
10+
Status: SUCCESS
11+
Description: "dereference failure: pointer invalid"
12+
13+
Status: FAILURE\
14+
Description: "dereference failure: deallocated dynamic object"
15+
16+
Status: FAILURE\
17+
Description: "dereference failure: dead object"
18+
19+
Status: FAILURE\
20+
Description: "dereference failure: pointer outside object bounds"
21+
22+
Status: FAILURE\
23+
Description: "dereference failure: invalid integer address"
24+
25+
Status: FAILURE\
26+
Description: "dereference failure: invalid integer address"

tests/expected/mmio/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
const BUFFER: *mut u32 = 0x8000 as *mut u32;
5+
const BUFFER2: *mut u32 = 0x1000 as *mut u32;
6+
7+
#[cfg(kani)]
8+
#[kani::proof]
9+
#[kani::mmio_region(0x8000, 8)]
10+
fn test_write() {
11+
let val = 12;
12+
unsafe {
13+
//BUFFER+2 is not in the MMIO region
14+
*(BUFFER.offset(2)) = val;
15+
//BUFFER2 is not in the MMIO region
16+
*BUFFER2 = val;
17+
18+
}
19+
}

tests/kani/MMIO/test.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,16 @@ fn test_write2() {
2525
core::ptr::write_volatile(BUFFER2, val);
2626

2727
}
28+
}
29+
30+
#[cfg(kani)]
31+
#[kani::proof]
32+
#[kani::mmio_region(0x8000, 8)]
33+
/// Check that larger MMIO regions also work
34+
fn test_write3() {
35+
let val = 12;
36+
unsafe {
37+
*BUFFER = val;
38+
*(BUFFER.offset(1)) = val;
39+
}
2840
}

0 commit comments

Comments
 (0)