-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.py
More file actions
96 lines (79 loc) · 5.05 KB
/
run.py
File metadata and controls
96 lines (79 loc) · 5.05 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
import subprocess
import os
print("🚀 Gamma Runner v1.0.0")
failure = False
# Run ghdl -a --std=08 for all .vhdl files in the current directory
anal_process = subprocess.Popen("ghdl -a --std=08 *.vhdl", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
anal_output, _ = anal_process.communicate()
anal_result = anal_process.returncode
if anal_result == 0:
print("|-✅ Analysis successful!")
# Iterate over each folder in test and find Testbench.vhdl files
for root, dirs, files in os.walk("test"):
for file in files:
if file == "Testbench.vhdl":
testbench_path = os.path.join(root, file)
folder_name = os.path.basename(root)
testbench_name = f"{folder_name}testbench"
print(f"|-🧪 Running {folder_name} tests...")
# analyze the testbench
analyze_process = subprocess.Popen(f"ghdl -a --std=08 {testbench_path}", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
analyze_output, _ = analyze_process.communicate()
analyze_result = analyze_process.returncode
if analyze_result == 0:
print("|--✅ Analysis successful!")
# Compile the testbench
elaborate_process = subprocess.Popen(f"ghdl -e --std=08 {testbench_name}", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
elaborate_output, _ = elaborate_process.communicate()
elaborate_result = elaborate_process.returncode
if elaborate_result == 0:
print("|--✅ Elaboration successful!")
# Run the testbench and output to a VCD file
run_process = subprocess.Popen(f"ghdl -r --std=08 {testbench_name} --vcd=test/{folder_name}/changes.vcd", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
run_output, _ = run_process.communicate()
run_result = run_process.returncode
with open(f"test/{folder_name}/simulation_output.txt", "w") as output_file:
output_file.write(run_output.decode("utf-8"))
if run_result == 0:
# see if the simulation_output contains "__FAILOUT"
with open(f"test/{folder_name}/simulation_output.txt", "r") as output_file:
output = output_file.read()
if "___FAILOUT" in output:
failure = True
print("|--❌ Simulation ran, but tests failed!")
# find what the test failed on
# note: there may be multiple failouts in the file
# test\<whatever>\Testbench.vhdl:<int>:<int>:@<int>ns:(report <something): ___FAILOUT <message>
# find the line numbers where the failouts are
failout_lines = [line for line in output.split("\n") if "___FAILOUT" in line]
failout_lines = [line.split(":")[1] for line in failout_lines]
failout_lines = [int(line) for line in failout_lines]
# find the messages of the failouts
failout_messages = [line for line in output.split("\n") if "___FAILOUT" in line]
failout_messages = [line.split("___FAILOUT")[1].strip() for line in failout_messages]
for i in range(len(failout_lines)):
print(f"|---🧨 Test failed at line {failout_lines[i]}: {failout_messages[i]}")
else:
print("|--✅ Simulation successful!")
else:
failure = True
print("|--❌ Simulation failed to run!")
else:
with open(f"test/{folder_name}/elaborate_error.txt", "w") as output_file:
output_file.write(elaborate_output.decode("utf-8"))
failure = True
print("|--❌ Elaboration failed!")
else:
with open(f"test/{folder_name}/analyze_error.txt", "w") as output_file:
output_file.write(analyze_output.decode("utf-8"))
failure = True
print("|--❌ Analysis failed!")
else:
with open("analysis_error.txt", "w") as output_file:
output_file.write(anal_output.decode("utf-8"))
failure = True
print("|-❌ Analysis failed!")
if failure:
exit(1)
else:
exit(0)