Improve template path handling. Add synthesis tests

This commit is contained in:
Alex Mykyta
2022-02-23 22:53:54 -08:00
parent e7e941d27b
commit 5324b594bf
32 changed files with 274 additions and 162 deletions

View File

@@ -4,6 +4,9 @@ from peakrdl.regblock.cpuif.apb3 import APB3_Cpuif, APB3_Cpuif_flattened
class APB3(CpuifTestMode):
cpuif_cls = APB3_Cpuif
rtl_files = [
"apb3_intf.sv",
]
tb_files = [
"apb3_intf.sv",
"apb3_intf_driver.sv",
@@ -12,3 +15,4 @@ class APB3(CpuifTestMode):
class FlatAPB3(APB3):
cpuif_cls = APB3_Cpuif_flattened
rtl_files = []

View File

@@ -4,6 +4,9 @@ from peakrdl.regblock.cpuif.axi4lite import AXI4Lite_Cpuif, AXI4Lite_Cpuif_flatt
class AXI4Lite(CpuifTestMode):
cpuif_cls = AXI4Lite_Cpuif
rtl_files = [
"axi4lite_intf.sv",
]
tb_files = [
"axi4lite_intf.sv",
"axi4lite_intf_driver.sv",
@@ -12,3 +15,4 @@ class AXI4Lite(CpuifTestMode):
class FlatAXI4Lite(AXI4Lite):
cpuif_cls = AXI4Lite_Cpuif_flattened
rtl_files = []

View File

@@ -10,35 +10,42 @@ from ..sv_line_anchor import SVLineAnchor
if TYPE_CHECKING:
from peakrdl.regblock import RegblockExporter
from ..regblock_testcase import RegblockTestCase
from ..sim_testcase import SimTestCase
class CpuifTestMode:
cpuif_cls = None # type: CpuifBase
# Files required by the DUT
rtl_files = [] # type: List[str]
# Files required by the sim testbench
tb_files = [] # type: List[str]
tb_template = ""
def get_tb_files(self) -> List[str]:
def _translate_paths(self, files: List[str]) -> List[str]:
class_dir = os.path.dirname(inspect.getfile(self.__class__))
cwd = os.getcwd()
tb_files = []
for file in self.tb_files:
new_files = []
for file in files:
relpath = os.path.relpath(
os.path.join(class_dir, file),
cwd
)
tb_files.append(relpath)
return tb_files
if relpath not in new_files:
new_files.append(relpath)
return new_files
def get_sim_files(self) -> List[str]:
return self._translate_paths(self.rtl_files + self.tb_files)
def get_tb_inst(self, tb_cls: 'RegblockTestCase', exporter: 'RegblockExporter') -> str:
def get_synth_files(self) -> List[str]:
return self._translate_paths(self.rtl_files)
# For consistency, make the template root path relative to the test dir
template_root_path = os.path.join(os.path.dirname(__file__), "../..")
loader = jj.FileSystemLoader(
template_root_path
)
def get_tb_inst(self, tb_cls: 'SimTestCase', exporter: 'RegblockExporter') -> str:
class_dir = os.path.dirname(inspect.getfile(self.__class__))
loader = jj.FileSystemLoader(class_dir)
jj_env = jj.Environment(
loader=loader,
undefined=jj.StrictUndefined,
@@ -52,11 +59,6 @@ class CpuifTestMode:
"type": type,
}
# template paths are relative to their class.
# transform to be relative to the root path
class_dir = os.path.dirname(inspect.getfile(self.__class__))
template_local_path = os.path.join(class_dir, self.tb_template)
template_path = os.path.relpath(template_local_path, template_root_path)
template = jj_env.get_template(template_path)
template = jj_env.get_template(self.tb_template)
return template.render(context)

View File

@@ -4,6 +4,7 @@ from peakrdl.regblock.cpuif.passthrough import PassthroughCpuif
class Passthrough(CpuifTestMode):
cpuif_cls = PassthroughCpuif
rtl_files = []
tb_files = [
"passthrough_driver.sv",
]