Skip to content

Commit f4900ab

Browse files
committed
test: mertge kani list and distributed verification list for proofs
1 parent 949f4a5 commit f4900ab

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

tests/kani_list.rs

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
use distributed_verification::KaniList;
2-
use std::process::Command;
2+
use std::{collections::HashMap, process::Command};
33

44
mod utils;
5-
use utils::*;
5+
use utils::{assert_eq, *};
66

77
#[test]
88
fn validate_kani_list_json() -> Result<()> {
99
let proofs = get_proofs("tests/proofs")?;
1010

1111
for path in &proofs {
12-
let kani_list = get_kani_list(path.to_str().unwrap());
1312
let file_stem = file_stem(path);
1413
let list_path = format!("kani_list/{file_stem}.txt");
1514
dbg!(&list_path);
15+
16+
let path = path.to_str().unwrap();
17+
// run `kani list`
18+
let kani_list = get_kani_list(path);
1619
expect_file![list_path].assert_debug_eq(&kani_list);
20+
21+
// run `distributed_verification`
22+
let text = cmd(&[path]);
23+
let v_ser_function: Vec<SerFunction> = serde_json::from_str(&text).unwrap();
24+
merge(&kani_list, &v_ser_function);
1725
}
1826

1927
Ok(())
@@ -33,3 +41,53 @@ fn get_kani_list(file: &str) -> KaniList {
3341
let file_json = std::fs::File::open("kani-list.json").unwrap();
3442
serde_json::from_reader(file_json).unwrap()
3543
}
44+
45+
fn merge(list: &KaniList, v_ser_fun: &[SerFunction]) {
46+
// sanity check
47+
let totals = &list.totals;
48+
assert_eq!(v_ser_fun.len(), totals.standard_harnesses + totals.contract_harnesses);
49+
assert_eq!(
50+
list.standard_harnesses.values().map(|s| s.len()).sum::<usize>(),
51+
totals.standard_harnesses
52+
);
53+
assert_eq!(
54+
list.contract_harnesses.values().map(|s| s.len()).sum::<usize>(),
55+
totals.contract_harnesses
56+
);
57+
58+
let map: HashMap<_, _> = v_ser_fun
59+
.iter()
60+
.enumerate()
61+
.map(|(idx, f)| ((&*f.func.file, &*f.func.name), idx))
62+
.collect();
63+
64+
// check all standard proofs are in distributed-verification json
65+
for (path, proofs) in &list.standard_harnesses {
66+
for proof in proofs {
67+
let key = (path.as_str(), proof.as_str());
68+
let idx = map.get(&key).unwrap();
69+
dbg!(idx);
70+
}
71+
}
72+
73+
// check all contract proofs are in distributed-verification json
74+
for (path, proofs) in &list.contract_harnesses {
75+
for proof in proofs {
76+
let key = (path.as_str(), proof.as_str());
77+
let idx = map.get(&key).unwrap();
78+
dbg!(idx);
79+
}
80+
}
81+
82+
// douoble check
83+
for &(path, proof) in map.keys() {
84+
// FIXME: split standard and contract proofs if kind supported
85+
match list.standard_harnesses.get(path) {
86+
Some(set) => _ = set.get(proof).unwrap(),
87+
None => match list.contract_harnesses.get(path) {
88+
Some(set) => _ = set.get(proof).unwrap(),
89+
None => panic!("{path} {proof} does not exist"),
90+
},
91+
};
92+
}
93+
}

tests/proofs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn test_proofs() -> Result<()> {
7070
let mut v_macro = vec![];
7171
for (idx, path) in proofs.iter().enumerate() {
7272
let file_stem = file_stem(path);
73+
// FIXME: no need to construct path
7374
let text = cmd(&[&format!("tests/proofs/{file_stem}.rs")]);
7475
expect_file![format!("./snapshots/{file_stem}.json")].assert_eq(&text);
7576
v_json.push(serde_json::from_str(&text).unwrap());
@@ -110,6 +111,7 @@ fn test_compare_unique_hash() -> Result<()> {
110111
let mut v_json = Vec::<Vec<SerFunction>>::with_capacity(proofs.len());
111112
for path in &proofs {
112113
let file_stem = path.file_stem().and_then(|f| f.to_str()).unwrap();
114+
// FIXME: no need to construct path
113115
let text = cmd(&[&format!("tests/compare/{file_stem}.rs")]);
114116
// NOTE: don't write text to json file, since compare.rs write it in a different way
115117
v_json.push(serde_json::from_str(&text).unwrap());

0 commit comments

Comments
 (0)