Tips for verifying usages of HashMap
#3909
-
Hi! I'm trying to verify some usages of a #[cfg(kani)]
mod verify {
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
use std::mem::{size_of, size_of_val, transmute};
#[allow(dead_code)]
fn concrete_state() -> RandomState {
let keys: [u64; 2] = [0, 0];
assert_eq!(size_of_val(&keys), size_of::<RandomState>());
unsafe { transmute(keys) }
}
#[kani::proof]
#[kani::stub(RandomState::new, concrete_state)]
#[kani::unwind(3)]
#[kani::solver(minisat)]
fn test() {
let mut map: HashMap<u64, u64> = HashMap::new();
assert_eq!(map.get(&0), None); // Ok
// Fails:
map.insert(0, 0);
assert_eq!(map.get(&0), Some(&0));
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @fpoli. The failure is due to an insufficient unwind value. This indicates that there's a loop somewhere that requires an unwinding value greater than 3. Verification succeeds if I increase the unwind value to 5: SUMMARY:
** 0 of 2198 failed (60 unreachable)
VERIFICATION:- SUCCESSFUL
Verification Time: 255.76009s We have a similar test in our regressions: https://github.com/model-checking/kani/blob/main/tests/perf/hashset/src/lib.rs |
Beta Was this translation helpful? Give feedback.
Hi @fpoli. The failure is due to an insufficient unwind value. This indicates that there's a loop somewhere that requires an unwinding value greater than 3. Verification succeeds if I increase the unwind value to 5:
SUMMARY: ** 0 of 2198 failed (60 unreachable) VERIFICATION:- SUCCESSFUL Verification Time: 255.76009s
We have a similar test in our regressions:
https://github.com/model-checking/kani/blob/main/tests/perf/hashset/src/lib.rs