-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
172 lines (141 loc) · 4.19 KB
/
run.py
File metadata and controls
172 lines (141 loc) · 4.19 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python3
import os
import subprocess
import sys
from datetime import datetime
# ==================================================
# USER CONFIGURATION
# ==================================================
TOP = "uart_top_tb"
WORK_DIR = "work"
LOG_DIR = "logs"
COV_DIR = "coverage"
TESTS = [
"random_tx_test",
"directed_tx_test"
]
RTL_FILES = [
"../rtl/uart_baud_rate_gen_tx.v",
"../rtl/uart_baud_rate_gen_rx.v",
"../rtl/uart_tx.v",
"../rtl/uart_rx.v",
"../rtl/uart_top.v"
]
TB_FILES = [
"../tb/uart_if.sv",
"../tb/uart_uvm_pkg.sv",
"../tb/uart_top_tb.sv"
]
# ==================================================
# DIRECTORY SETUP
# ==================================================
os.makedirs(LOG_DIR, exist_ok=True)
os.makedirs(COV_DIR, exist_ok=True)
# ==================================================
# HELPER FUNCTION
# ==================================================
def run_cmd(cmd, logfile=None):
print(f"\n[CMD] {' '.join(cmd)}")
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True
)
output = ""
for line in process.stdout:
print(line, end="")
output += line
process.wait()
if logfile:
with open(logfile, "w") as f:
f.write(output)
return process.returncode, output
# ==================================================
# CREATE WORK LIBRARY
# ==================================================
if not os.path.exists(WORK_DIR):
rc, _ = run_cmd(["vlib", WORK_DIR])
if rc != 0:
sys.exit("ERROR: vlib failed")
# ==================================================
# COMPILE WITH COVERAGE
# ==================================================
compile_cmd = [
"vlog",
"-sv",
"-work", WORK_DIR,
"+cover=bcesft" # Branch, Condition, Expression, State, FSM, Toggle
]
compile_cmd += RTL_FILES
compile_cmd += TB_FILES
rc, _ = run_cmd(compile_cmd)
if rc != 0:
sys.exit("ERROR: Compilation failed")
print("\n=== COMPILATION PASSED ===")
# ==================================================
# RUN TESTS
# ==================================================
results = {}
ucdb_files = []
for test in TESTS:
print(f"\n=== RUNNING TEST: {test} ===")
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
logfile = f"{LOG_DIR}/{test}_{timestamp}.log"
ucdb_file = f"{COV_DIR}/{test}.ucdb"
sim_cmd = [
"vsim",
"-c",
"-coverage",
"-work", WORK_DIR,
TOP,
f"+UVM_TESTNAME={test}",
"-do",
f"coverage save -onexit {ucdb_file}; run -all; quit"
]
rc, output = run_cmd(sim_cmd, logfile)
if "TEST FAILED" in output:
results[test] = "FAIL"
else:
results[test] = "PASS"
ucdb_files.append(ucdb_file)
# ==================================================
# COVERAGE MERGE
# ==================================================
print("\n=== MERGING COVERAGE DATABASES ===")
merged_ucdb = f"{COV_DIR}/uart_merged.ucdb"
merge_cmd = ["vcover", "merge", merged_ucdb] + ucdb_files
rc, _ = run_cmd(merge_cmd)
if rc != 0:
sys.exit("ERROR: Coverage merge failed")
# ==================================================
# COVERAGE REPORT GENERATION
# ==================================================
print("\n=== GENERATING COVERAGE REPORT ===")
html_cmd = [
"vcover", "report",
"-html", f"{COV_DIR}/cov_html",
merged_ucdb
]
run_cmd(html_cmd)
text_cmd = [
"vcover", "report",
"-details",
merged_ucdb
]
run_cmd(text_cmd)
# ==================================================
# SUMMARY
# ==================================================
print("\n==============================")
print(" REGRESSION SUMMARY ")
print("==============================")
for test, result in results.items():
print(f"{test:25} : {result}")
if "FAIL" in results.values():
print("\nOVERALL RESULT: FAIL ❌")
sys.exit(1)
else:
print("\nOVERALL RESULT: PASS ✅")
print(f"Coverage HTML: {COV_DIR}/cov_html/index.html")
sys.exit(0)