Fixture to automate running Amaranth simulations
Project description
pytest-amaranth-sim
Fixture to automate running Amaranth simulations.
This pytest plugin was generated with Cookiecutter along with @hackebrot's cookiecutter-pytest-plugin template.
Features
- Automatically set up an Amaranth pysim
simulator object fixture
sim, ready to run testbenches, viaclksandmodfixtures. - Generate VCDs for simulations. Includes optional workarounds for pytest/GTKWave behavior that I've found useful.
Requirements
- At least Amaranth version
0.5.0or more recent is required. - Pytest, of course, is also required, at least version
6.2.0.
Installation
pytest-amaranth-sim is available on PyPI:
$ pip install pytest-amaranth-sim
If using this plugin as part PDM, you can install using pdm add:
$ pdm add -G dev pytest-amaranth-sim
To follow development, use the git repo:
$ pip install [-e] git+https://github.com/cr1901/pytest-amaranth-sim
$ pdm add -G dev git+https://github.com/cr1901/pytest-amaranth-sim
Usage
import pytest
from amaranth import Elaboratable, Signal, Module
class Adder(Elaboratable):
def __init__(self, width=4):
self.width = width
self.a = Signal(width)
self.b = Signal(width)
self.o = Signal(width + 1)
def elaborate(self, plat): # noqa: D102
m = Module()
m.d.sync += self.o.eq(self.a + self.b)
return m
@pytest.fixture
def testbench(mod, a, b, o):
if (a,b,o,mod.width) == (127, 127, 254, 4):
return pytest.skip(reason="inputs too wide")
async def testbench(sim):
await sim.tick()
sim.set(mod.a, a)
await sim.tick()
assert sim.get(mod.o) == a
sim.set(mod.b, b)
await sim.tick()
assert sim.get(mod.o) == o
return testbench
@pytest.mark.parametrize("a,b,o", [(0, 0, 0), (1, 1, 2), (127, 127, 254)])
@pytest.mark.parametrize("mod", [Adder(4), Adder(8)])
@pytest.mark.parametrize("clks", [1.0 / 12e6])
def test_inject_direct(sim, testbench):
sim.run(testbenches=[testbench], processes=[])
Save inside your test directory to a file that matches the glob test_*.py
(see pytest docs
for more info). Run with:
pytest [--vcds]
Contributing
Contributions are very welcome. Tests can be run with pytest (pdm test),
please ensure the coverage at least stays the same before you submit a pull
request.
License
Distributed under the terms of the [BSD-2] license, "pytest-amaranth-sim" is free and open source software
Issues
If you encounter any problems, please file an issue along with a detailed description.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_amaranth_sim-0.1.1.tar.gz.
File metadata
- Download URL: pytest_amaranth_sim-0.1.1.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddbbfce7f71a494b3c341b151692dbdcc52b16f0671cf227a9a0a0913463a189
|
|
| MD5 |
f615c561f5a01f173ec613cfef05ab37
|
|
| BLAKE2b-256 |
5c98388d6ad9665800cf474ee88428017d7addf34ac3200aca2c7566509efe12
|
Provenance
The following attestation bundles were made for pytest_amaranth_sim-0.1.1.tar.gz:
Publisher:
main.yml on cr1901/pytest-amaranth-sim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_amaranth_sim-0.1.1.tar.gz -
Subject digest:
ddbbfce7f71a494b3c341b151692dbdcc52b16f0671cf227a9a0a0913463a189 - Sigstore transparency entry: 961626983
- Sigstore integration time:
-
Permalink:
cr1901/pytest-amaranth-sim@bee976c0d49ef6ca0c018d4e61f5f0896baf6ec4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/cr1901
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@bee976c0d49ef6ca0c018d4e61f5f0896baf6ec4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_amaranth_sim-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pytest_amaranth_sim-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0884326a57c5a7dd4cb326f3f11dd192bbda9ef121f860aee94d73a02aecd243
|
|
| MD5 |
228a4d88ae19da20e07154b7559249a7
|
|
| BLAKE2b-256 |
5bbeea76798b04ad3a8be74c782cc5dbf80d465f5564750c33b0034187ab9fb9
|
Provenance
The following attestation bundles were made for pytest_amaranth_sim-0.1.1-py3-none-any.whl:
Publisher:
main.yml on cr1901/pytest-amaranth-sim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_amaranth_sim-0.1.1-py3-none-any.whl -
Subject digest:
0884326a57c5a7dd4cb326f3f11dd192bbda9ef121f860aee94d73a02aecd243 - Sigstore transparency entry: 961627015
- Sigstore integration time:
-
Permalink:
cr1901/pytest-amaranth-sim@bee976c0d49ef6ca0c018d4e61f5f0896baf6ec4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/cr1901
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@bee976c0d49ef6ca0c018d4e61f5f0896baf6ec4 -
Trigger Event:
push
-
Statement type: