-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanity_check.py
63 lines (51 loc) · 1.75 KB
/
sanity_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import json
import re
import click
def load_diff_file(f):
diff = dict()
diff_json = json.load(f)
for pair in diff_json:
if "old" not in pair or "new" not in pair:
continue
for old_opcode in pair["old"]:
diff[int(old_opcode, 16)] = set(
(int(new_opcode, 16) for new_opcode in pair["new"])
)
return diff
@click.command()
@click.argument("vtable_diff", type=click.File("r"))
@click.argument("minor_patch_diff", type=click.File("r"))
def sanity_check(vtable_diff, minor_patch_diff):
"""
Compares two JSON diff files to cross-check results from the different
scripts in this repo.
Example:
python sanity_check.py vtable_diff.json minor_patch_diff.json
"""
diff1 = load_diff_file(vtable_diff)
diff2 = load_diff_file(minor_patch_diff)
all_good = True
for old_opcode, new_opcodes in diff2.items():
if old_opcode not in diff1:
if len(new_opcodes) < 50:
print(f"Missing old opcode in vtable diff: {hex(old_opcode)}")
all_good = False
continue
other_new_opcodes = diff1[old_opcode]
vtable_new_opcode = None
if len(other_new_opcodes) > 0:
vtable_new_opcode = list(other_new_opcodes)[0]
elif len(new_opcodes) == 0:
continue
if vtable_new_opcode not in new_opcodes:
new_text = (
hex(vtable_new_opcode) if vtable_new_opcode is not None else "None"
)
print(f"vtable diff mismatch for case {hex(old_opcode)} => {new_text}")
all_good = False
if all_good:
print("Sanity check OK")
else:
print("Errors detected")
if __name__ == "__main__":
sanity_check()