-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[documentation] Cookbook : a project of library written with amaranth hdl #719
Comments
Erratum : build the test bench, generate the rtlil, and invoke sby With the described procedure, I could not have failing assertion (most likely, they was never reached because of the evaluation on ⇒ The clock domain's ⇒ As we don't need to do something fancy during the invocation of See the fix commit Below are fixed parts :
Instanciate a simple test bench
class Test:
@staticmethod
def _buildTestBench(dut: Elaboratable, test, cd: ClockDomain) -> Module:
"""
dut : 'Device Under Test'
test : a function that will add assertions to the test bench
"""
m = Module()
m.domains.sync = cd
m.submodules.dut = dut
test(m, cd)
return m Generate the RTLIL fileGiven a base name, I will instruct ilName = f"tmp.{baseName}.il"
sync = ClockDomain("sync")
rst = Signal()
sync.rst = rst
m = Test._buildTestBench(dut, test, sync)
fragment = Fragment.get(m, platform)
output = rtlil.convert(
fragment,
ports=dut.ports() + [sync.rst, sync.clk],
)
print(f"Generating {ilName}...")
with open(ilName, "wt") as f:
f.write(output) Invoke sby
In a subprocess, we launch a simple invocation like invoke_args = [require_tool("sby"), "-f", sbyName]
print(f"Running sby -f {' '.join(invoke_args)}...")
subprocess.run(invoke_args).check_returncode() That's all (until next time) |
Erratum : Generate the SBY configuration file For the CI to work, do not use boolector, only smtbmc. I also simplified the file to looks like more the one used by the Here is the fixed part : Generate the SBY configuration fileEach test will require a SBY configuration file in order to target the generated RTLIL. For my project, I wrote a little helper that generate the file from the target RTLIL file and the required depth ; then I use this helper class Test:
@staticmethod
def _generateSbyConfig(sbyName: str, ilName: str, depth: int):
print(f"Generating {sbyName}...")
with open(sbyName, "wt") as f:
f.write(
"\n".join(
[
"[options]",
"mode bmc",
f"depth {depth}",
"",
"[engines]",
"smtbmc",
"",
"[script]",
f"read_ilang {ilName}",
"prep -top top",
"",
"[files]",
f"{ilName}",
]
)
) |
Abstract
You have written some hardware design using amaranth-hdl, that you wish to promote into a library in order to reuse it in another project ?
You also have written some tests that use SymbiYosys(sby) to validate this library in part or in full ?
This cookbook will describe the minimal settings to run those test in a github action in order to validate a commit. Before that, as a reminder or quick start, it will also describe what to install locally and a way to write tests. It is based on this commit from a project of mine to gather some reusable stuff for my own projects.
Target audience
This cookbook will be easier to understand provided :
However, the reference project is small enough to be studied at a leisurely pace and be used as an informative template
Overview
This cookbook will describe the following item, in that order
setuptools
and follows PEP 621Local Setup
The key point is to install SymbiYosys from source, meaning following the installation manual.
I installed the required parts ("Yosys, Yosys-SMTBMC and ABC", and "sby") and the recommanded part ("boolector").
Python package definition
See the reference file in full.
The key point is the list of dependencies. In order to use up to dates versions of amaranth, I instruct the setup tools to use a recent commit on the main branch. The targeted commit hashes will have to be updated with time.
Implementing tests that call sby
See the reference file in full
First thing first, I instructed git to ignore any file named
tmp
or liketmp.*
. Then, my tests generate RTLIL files and their companion SBY files with names starting withtmp.
This is to make sure that those artefacts will not end up in the repository.This part will show :
sby
Instanciate a simple test bench
Generate the RTLIL file
Given a base name, I will instruct
amaranth.back.rtill
to generate the specified RTLIL file with :Generate the SBY configuration file
Each test will require a SBY configuration file in order to target the generated RTLIL. For my project, I wrote a little helper that generate the file from the target RTLIL file and the required depth ; then I use this helper
Invoke sby
In a subprocess, we launch a simple invocation like
sby -f <the-sby-configuration-file>
, and we check the return code for detecting failure.Testing locally
I wrote a little script to automate this part, because I includes reformating the sources, packaging and re-installing locally the project, and then launching the tests and compute coverages
Github actions
See the reference file in full
The key points when setting up the github actions are :
amaranth-yosys
sby
from amaranth_yosys. That is where using the aforementionedamaranth._toolchain.require_tool
is coming in handy.Installation of dependencies
Running the tests
The text was updated successfully, but these errors were encountered: