Skip to content

Commit 84496da

Browse files
adpaco-awsdanielsn
authored andcommitted
Add a couple of missing tests (nondet. vectors, offset) (rust-lang#79)
* Add a couple of missing tests (nondet. vectors, offset) * Add `test_offset_str` to BinOp_Offset test * Add assertions in `NondetVectors` test Co-authored-by: Daniel Schwartz-Narbonne <[email protected]>
1 parent 452b7ad commit 84496da

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

rust-tests/cbmc-reg/BinOp_Offset/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3-
pub fn test_offset() {
3+
pub fn test_offset_array() {
44
let s = ['a', 'b', 'c'];
55
let ptr = s.as_ptr();
66

@@ -11,6 +11,18 @@ pub fn test_offset() {
1111
}
1212
}
1313

14+
pub fn test_offset_str() {
15+
let s: &str = "123";
16+
let ptr: *const u8 = s.as_ptr();
17+
18+
unsafe {
19+
assert!(*ptr.offset(0) == b'1');
20+
assert!(*ptr.offset(1) == b'2');
21+
assert!(*ptr.offset(2) == b'3');
22+
}
23+
}
24+
1425
pub fn main() {
15-
test_offset();
26+
test_offset_array();
27+
test_offset_str()
1628
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
const FIFO_SIZE: usize = 2;
4+
fn __nondet<T>() -> T {
5+
unimplemented!()
6+
}
7+
8+
fn main() {
9+
let len: usize = __nondet();
10+
if !(len <= FIFO_SIZE) {
11+
return;
12+
}
13+
let _buf1: Vec<u8> = vec![0u8; len]; //< this works
14+
let elt: u8 = __nondet();
15+
let _buf2: Vec<u8> = vec![elt; len]; //< this fails: "memset destination region writeable"
16+
let idx: usize = __nondet();
17+
if idx < len {
18+
assert!(_buf1[idx] == 0u8);
19+
assert!(_buf2[idx] == elt);
20+
}
21+
}

0 commit comments

Comments
 (0)