-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_vvp_output.py
70 lines (56 loc) · 2.05 KB
/
parse_vvp_output.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
64
65
66
67
68
69
70
import re
import sys
def parse_vvp_output(file_path):
# Regex pattern to match each line of the output
pattern = re.compile(
r"\| Time: (\d+) ns \| Code: (\d{12}) \| Exp Data: (\d{8}) \| Exp. Syndrome: (\d{4}) \| Dec Data: (\d{8}) \| Syndrome: (\d{4}) \|"
)
results = []
with open(file_path, "r") as file:
for line in file:
match = pattern.match(line)
if match:
time, code, exp_data, exp_synd, dec_data, synd = match.groups()
results.append(
{
"time": int(time),
"code": code,
"exp_data": exp_data,
"exp_synd": exp_synd,
"dec_data": dec_data,
"synd": synd,
}
)
return results
def calculate_score(results):
total_tests = len(results)
correct_tests = 0
for result in results:
if (
result["exp_data"] == result["dec_data"]
and result["exp_synd"] == result["synd"]
):
correct_tests += 1
score = (correct_tests / total_tests) * 100
return score
if len(sys.argv) != 2:
print("Usage: python3 parse_vvp_output.py <vvp_output_file>")
sys.exit(1)
file_path = sys.argv[1]
results = parse_vvp_output(file_path)
score = calculate_score(results)
print(f"Total Tests: {len(results)}")
print(
f'Correct Tests: {sum(1 for r in results if r["exp_data"] == r["dec_data"] and r["exp_synd"] == r["synd"])}'
)
print(f"Score: {score:.2f}%")
# Create a file to store failed outputs
with open("failed_outputs.txt", "w") as file:
for result in results:
if (
result["exp_data"] != result["dec_data"]
or result["exp_synd"] != result["synd"]
):
file.write(
f"| Time: {result['time']} ns | Code: {result['code']} | Exp Data: {result['exp_data']} | Exp. Syndrome: {result['exp_synd']} | Dec Data: {result['dec_data']} | Syndrome: {result['synd']} |\n"
)