Refactors testbench build and execution logic
Updates `build_testbench` to use a shared tool execution utility, improving maintainability and consistency. Refactors `run_testbench` to accept project configurations, enabling better customization and handling of tool options. Enhances modularity and reduces redundancy in the simulation workflow.
This commit is contained in:
@@ -44,7 +44,7 @@ def test(args):
|
|||||||
"""Starts the test process."""
|
"""Starts the test process."""
|
||||||
console_utils.print("Starting test process...")
|
console_utils.print("Starting test process...")
|
||||||
build_testbench(project, args.target)
|
build_testbench(project, args.target)
|
||||||
run_testbench(args.target)
|
run_testbench(project, args.target)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@@ -4,6 +4,7 @@ from typing import List
|
|||||||
from hdlbuild.models.project import ProjectConfig
|
from hdlbuild.models.project import ProjectConfig
|
||||||
from hdlbuild.models.config import DIRECTORIES
|
from hdlbuild.models.config import DIRECTORIES
|
||||||
from hdlbuild.dependencies.resolver import DependencyResolver
|
from hdlbuild.dependencies.resolver import DependencyResolver
|
||||||
|
from hdlbuild.tools.xilinx_ise.common import run_tool
|
||||||
from hdlbuild.utils.console_utils import ConsoleTask
|
from hdlbuild.utils.console_utils import ConsoleTask
|
||||||
from hdlbuild.utils.source_resolver import expand_all_sources, expand_testbenches
|
from hdlbuild.utils.source_resolver import expand_all_sources, expand_testbenches
|
||||||
|
|
||||||
@@ -86,28 +87,24 @@ def build_testbench(project: ProjectConfig, testbench_name: str):
|
|||||||
testbench_name=testbench_name
|
testbench_name=testbench_name
|
||||||
)
|
)
|
||||||
|
|
||||||
# 2. Befehl bauen
|
# 2. FUSE-Befehl ausführen mit `run_tool`
|
||||||
xilinx_path = project.xilinx_path
|
mandatory_arguments = [
|
||||||
xilinx_bin_dir = os.path.join(xilinx_path, "bin", "lin64") # oder nt64 bei Windows
|
|
||||||
fuse_executable = os.path.join(xilinx_bin_dir, "fuse")
|
|
||||||
|
|
||||||
cmd = [
|
|
||||||
fuse_executable,
|
|
||||||
"-intstyle", "xflow",
|
|
||||||
"-prj", f"{project.name}_sim.prj",
|
"-prj", f"{project.name}_sim.prj",
|
||||||
"-o", isim_exe_name,
|
"-o", isim_exe_name,
|
||||||
f"work.{testbench_name.replace('.vhd', '').replace('.v', '')}",
|
f"work.{testbench_name.replace('.vhd', '').replace('.v', '')}",
|
||||||
"work.glbl"
|
"work.glbl"
|
||||||
]
|
]
|
||||||
|
|
||||||
# 3. Ausführen mit Konsole
|
run_tool(
|
||||||
task = ConsoleTask(prefix="hdlbuild", title=f"FUSE {testbench_name}")
|
project=project,
|
||||||
result = task.run_command(cmd, cwd=DIRECTORIES.build)
|
tool_executable_name="fuse",
|
||||||
|
tool_option_attr="fuse",
|
||||||
|
mandatory_arguments=mandatory_arguments,
|
||||||
|
working_dir=DIRECTORIES.build,
|
||||||
|
silent=False
|
||||||
|
)
|
||||||
|
|
||||||
if result != 0:
|
def run_testbench(project: ProjectConfig, testbench_name: str):
|
||||||
raise RuntimeError(f"FUSE fehlgeschlagen für Testbench {testbench_name}")
|
|
||||||
|
|
||||||
def run_testbench(testbench_name: str):
|
|
||||||
"""
|
"""
|
||||||
Führt eine gebaute Testbench-Executable aus (ISim Simulation).
|
Führt eine gebaute Testbench-Executable aus (ISim Simulation).
|
||||||
|
|
||||||
@@ -116,7 +113,6 @@ def run_testbench(testbench_name: str):
|
|||||||
"""
|
"""
|
||||||
# Pfade
|
# Pfade
|
||||||
isim_exe_name = f"isim_{testbench_name.replace('.vhd', '').replace('.v', '')}"
|
isim_exe_name = f"isim_{testbench_name.replace('.vhd', '').replace('.v', '')}"
|
||||||
isim_exe_path = os.path.join(DIRECTORIES.build, isim_exe_name)
|
|
||||||
|
|
||||||
isim_cmd_file = os.path.join(DIRECTORIES.build, f"{isim_exe_name}.cmd")
|
isim_cmd_file = os.path.join(DIRECTORIES.build, f"{isim_exe_name}.cmd")
|
||||||
|
|
||||||
@@ -124,13 +120,17 @@ def run_testbench(testbench_name: str):
|
|||||||
with open(isim_cmd_file, "w") as f:
|
with open(isim_cmd_file, "w") as f:
|
||||||
f.write("")
|
f.write("")
|
||||||
|
|
||||||
|
cmd = [f"./{isim_exe_name}"]
|
||||||
|
|
||||||
|
tool_opts = getattr(project.tool_options, "isim", [])
|
||||||
|
if tool_opts:
|
||||||
|
cmd.extend(tool_opts)
|
||||||
|
|
||||||
# 2. Kommando bauen
|
# 2. Kommando bauen
|
||||||
cmd = [
|
cmd.extend([
|
||||||
f"./{isim_exe_name}",
|
|
||||||
"-gui",
|
|
||||||
"-tclbatch",
|
"-tclbatch",
|
||||||
f"{isim_exe_name}.cmd"
|
f"{isim_exe_name}.cmd"
|
||||||
]
|
])
|
||||||
|
|
||||||
# 3. Ausführen
|
# 3. Ausführen
|
||||||
task = ConsoleTask(prefix="hdlbuild", title=f"RUN {testbench_name}")
|
task = ConsoleTask(prefix="hdlbuild", title=f"RUN {testbench_name}")
|
||||||
|
Reference in New Issue
Block a user